<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>libjack.com &#187; XML-RPC</title>
	<atom:link href="http://libjack.com/tag/xml-rpc/feed/" rel="self" type="application/rss+xml" />
	<link>http://libjack.com</link>
	<description>What is a libjack? ... Dunno? .... stick around and find out!</description>
	<lastBuildDate>Tue, 07 Apr 2009 00:10:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Magento api with Java Client &#8212; problem with XML-RPC interface</title>
		<link>http://libjack.com/2009/03/26/java-magento-xmlrpc-api-nil-issue/</link>
		<comments>http://libjack.com/2009/03/26/java-magento-xmlrpc-api-nil-issue/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 23:56:41 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[technobabble]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[XML-RPC]]></category>
		<category><![CDATA[xmlrpc]]></category>

		<guid isPermaLink="false">http://libjack.com/?p=34</guid>
		<description><![CDATA[One of the features touted by Magento is the api exposed via both XML-RPC and SOAP. I quickly (and successfully) tested the SOAP interface using the amazingly complete (and free) soapUI. I wanted to use XML-RPC, and decided to build a test client in Java. While trying to build a client, using the apache ws-xmlrpc [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>One of the features touted by Magento is the api exposed via both XML-RPC and SOAP. I quickly (and successfully) tested the SOAP interface using the amazingly complete (and free) <a href="http://www.soapui.org/">soapUI</a>. I wanted to use XML-RPC, and decided to build a test client in Java. While trying to build a client, using the apache <a href="http://ws.apache.org/xmlrpc/">ws-xmlrpc</a> library, I ran into a roadblock.  The initial login and some other calls would work just fine, but some calls such as product.info would always cause an exception, similar to:</p>
<pre>Exception in thread "main" org.apache.xmlrpc.client.XmlRpcClientException:
Failed to parse servers response: Unknown type: nil</pre>
<p>I posted on the magento forum to no success (except to find a few others with the same problem). So I was on my own..</p>
<p>After some research, I determined that the problem (IMHO) is that the Magento api is incorrectly using the <strong>nil</strong> type in responses. According to the XML-RPC spec, <strong>nil</strong> is an extended type, and can only be used with a namespace (e.g. <strong>ex:nil</strong>) &#8212; see the <a href="http://ws.apache.org/xmlrpc/types.html">data types</a> section on the apache site. But, luckily, the ws-xmlrpc library can be easily extended to provide a work around, and the following solution worked for me.</p>
<p><span id="more-34"></span><br />
All you need to do is extend the builtin TypeFactoryImpl class and the assign the client TypeFactory to your custom class. Most of the work by this custom TypeFactory can be done using the super class, so just check for the <em>incorrect</em> <strong>nil</strong> usage when getting a parser. e.g the TypeFactory I used :</p>
<pre>public class MyTypeFactory extends TypeFactoryImpl {

    public MyTypeFactory(XmlRpcController pController) {
        super(pController);
    }

    @Override
    public TypeParser getParser(XmlRpcStreamConfig pConfig,
      NamespaceContextImpl pContext, String pURI, String pLocalName) {

        if ("".equals(pURI) &amp;&amp; NullSerializer.NIL_TAG.equals(pLocalName)) {
            return new NullParser();
        } else {
            return super.getParser(pConfig, pContext, pURI, pLocalName);
        }
    }
}</pre>
<p>and then created my XmlRpcClient as follows:</p>
<pre>XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://mymagentoserver.com/api/xmlrpc/"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
client.setTypeFactory(new MyTypeFactory(client));</pre>
<p>Notes:</p>
<ul>
<li>There is a <em>enabledForExtensions</em> property used by the client (and server) classes, which can be set by XmlRpcConfig:: setEnabledForExtensions(), but that has no effect here since the Magento server is doing it wrong.</li>
<li>You would use a very similar method if you needed to implement a custom type (if your XML-RPC server defined one), but would need to provide a custom TypeSerializer as well, by overriding the <em>getSerializer()</em> method in MyTypeFactory. There is an example of this on the ws-xmlrpc site in the advanced techniques section.</li>
</ul>
<p>As usual, your milage may vary.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://libjack.com/2009/03/26/java-magento-xmlrpc-api-nil-issue/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

