Skip to main content

xmlrpc returns unexpected status

No replies
Joined: 2010-06-14

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 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(<br />
        at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(<br />
        at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(<br />
        at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(<br />
        at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(<br />
        at org.apache.xmlrpc.client.XmlRpcClient.execute(

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>	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>		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 I added handler - I read that this method is fine - but I tried to create 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>	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(""));<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 ( 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.