Skip to main content

xmlrpc returns unexpected status

No replies
b1gbear
Offline
Joined: 2010-06-14
Points: 0

Hi all, I'm sorry if I'm in bad forum, but I don't know where my question should be...
Well, I'm trying to use xmlrpc server, because of downloading data from web url to desktop (swing) application. I found http://ws.apache.org/xmlrpc/ and it seems to be great for my purpose. But when I'm trying to connect to xmlrpc, server returns following:

org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server returned unexpected status: Not Found<br />
        at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:94)<br />
        at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:152)<br />
        at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)<br />
        at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)<br />
        at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)

I followed manual for The XML-RPC Servlet and I wrote these lines into my web.xml

<br />
      EOTService<br />
      services.EOTService </p>
<p>            enabledForExtensions<br />
            true<br />
            Sets, whether the servlet supports vendor extensions for XML-RPC. </p>
<p>      EOTService<br />
      /service<br />

my servlet looks like this:

package services;</p>
<p>import org.apache.xmlrpc.*;<br />
import org.apache.xmlrpc.common.*;<br />
import org.apache.xmlrpc.server.*;<br />
import org.apache.xmlrpc.webserver.*;</p>
<p>public class EOTService extends XmlRpcServlet {<br />
	private boolean isAuthenticated(String pUserName, String pPassword) {<br />
		return pUserName.equals("username") && pPassword.equals("password");<br />
	}</p>
<p>	protected XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException {<br />
		PropertyHandlerMapping mapping = (PropertyHandlerMapping) super.newXmlRpcHandlerMapping();</p>
<p>		AbstractReflectiveHandlerMapping.AuthenticationHandler handler =<br />
			new AbstractReflectiveHandlerMapping.AuthenticationHandler() {<br />
				public boolean isAuthorized(XmlRpcRequest pRequest) {<br />
					XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) pRequest.getConfig();</p>
<p>					return isAuthenticated(config.getBasicUserName(), config.getBasicPassword());<br />
				}<br />
			};</p>
<p>		mapping.setAuthenticationHandler(handler);</p>
<p>		try {<br />
			mapping.addHandler("Calculator", Class.forName("services.Calculator"));<br />
		} catch (ClassNotFoundException e) {<br />
			e.printStackTrace();<br />
		}<br />
		return mapping;<br />
	}<br />
}

(instead of XmlRpcServlet.properties I added handler - I read that this method is fine - but I tried to create XmlRpcServlet.properties too and it's not working)...
and in the same package I have the class Calculator

package services;</p>
<p>public class Calculator {<br />
	public int add(int a, int b) {<br />
		return a + b;<br />
	}</p>
<p>	public int sub(int a, int b) {<br />
		return a - b;<br />
	}<br />
}

My client is simple, but in accordance with manual

try {<br />
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();<br />
    config.setServerURL(new URL("http://127.0.0.1:8080/service"));<br />
    config.setBasicUserName("username");<br />
    config.setBasicPassword("password");<br />
    config.setBasicEncoding("UTF-8");<br />
    XmlRpcClient client = new XmlRpcClient();<br />
    client.setConfig(config);<br />
    Object[] params = new Object[]{new Integer(33), new Integer(9)};<br />
    Integer result = (Integer)client.execute("Calculator.add", params); </p>
<p>    System.out.println("33 + 9 = " + result);<br />
} catch (java.net.MalformedURLException e) {<br />
    System.out.println("MalformedURLException: " + e.getMessage());<br />
} catch (org.apache.xmlrpc.XmlRpcException e) {<br />
    e.printStackTrace(System.out);<br />
}

When I put http://localhost:8080/eot/service in my browser, it returns exception:

HTTP method GET is not supported by this URL
but it should return this exception, so I think that it works ok.
Does somebody know, where the problem is? Thank you.