Results 1 to 3 of 3
  1. #1
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Default xmlrpc returns unexpected status

    Hi all I'm trying to use xmlrpc server, because of downloading data from web url to desktop (swing) application. I found XML-RPC and it seems to be great for my purpose. But when I'm trying to connect to xmlrpc, server returns following:
    Java Code:
    org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server returned unexpected status: Not Found
            at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:94)
            at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:152)
            at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
            at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
            at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
            at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
            at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
            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
    Java Code:
    <web-app version="2.4"
    		 xmlns="http://java.sun.com/xml/ns/j2ee"
    		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    		 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    	<servlet>
    		<servlet-name>EOTService</servlet-name>
    		<servlet-class>services.EOTService</servlet-class>
    		<init-param>
    			<param-name>enabledForExtensions</param-name>
    			<param-value>true</param-value>
    			<description>Sets, whether the servlet supports vendor extensions for XML-RPC.</description>
    		</init-param>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>EOTService</servlet-name>
    		<url-pattern>/service</url-pattern>
    	</servlet-mapping>
    </web-app>
    my servlet looks like this:
    Java Code:
    package services;
    
    import org.apache.xmlrpc.*;
    import org.apache.xmlrpc.common.*;
    import org.apache.xmlrpc.server.*;
    import org.apache.xmlrpc.webserver.*;
    
    public class EOTService extends XmlRpcServlet {
    	private boolean isAuthenticated(String pUserName, String pPassword) {
    		return pUserName.equals("username") && pPassword.equals("password");
    	}
    
    	protected XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException {
    		PropertyHandlerMapping mapping = (PropertyHandlerMapping) super.newXmlRpcHandlerMapping();
    
    		AbstractReflectiveHandlerMapping.AuthenticationHandler handler =
    			new AbstractReflectiveHandlerMapping.AuthenticationHandler() {
    				public boolean isAuthorized(XmlRpcRequest pRequest) {
    					XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) pRequest.getConfig();
    
    					return isAuthenticated(config.getBasicUserName(), config.getBasicPassword());
    				}
    			};
    
    		mapping.setAuthenticationHandler(handler);
    
    		try {
    			mapping.addHandler("Calculator", Class.forName("services.Calculator"));
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		}
    		return mapping;
    	}
    }
    (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
    Java Code:
    package services;
    
    public class Calculator {
    	public int add(int a, int b) {
    		return a + b;
    	}
    
    	public int sub(int a, int b) {
    		return a - b;
    	}
    }
    My client is simple, but in accordance with manual
    Java Code:
    try {
                XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
                config.setServerURL(new URL("http://127.0.0.1:8080/service"));
                config.setBasicUserName("username");
                config.setBasicPassword("password");
                config.setBasicEncoding("UTF-8");
                XmlRpcClient client = new XmlRpcClient();
                client.setConfig(config);
                Object[] params = new Object[]{new Integer(33), new Integer(9)};
                Integer result = (Integer)client.execute("Calculator.add", params);
    
                System.out.println("33 + 9 = " + result);
            } catch (java.net.MalformedURLException e) {
                System.out.println("MalformedURLException: " + e.getMessage());
            } catch (org.apache.xmlrpc.XmlRpcException e) {
                e.printStackTrace(System.out);
            }
    When I put http://localhost:8080/eot/service in my browser, it returns exception:
    Java Code:
    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.

  2. #2
    mangstadt is offline Member
    Join Date
    Jul 2010
    Location
    USA
    Posts
    19
    Rep Power
    0

    Default

    Look at the servlet URL in your client code...

    Quote Originally Posted by BigBear View Post
    Java Code:
    config.setServerURL(new URL("http://127.0.0.1:8080/service"));

  3. #3
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

Similar Threads

  1. Error: unexpected type
    By silvia in forum New To Java
    Replies: 3
    Last Post: 02-05-2010, 10:54 PM
  2. Unexpected characters using PrintWriter
    By mjwoodford in forum New To Java
    Replies: 1
    Last Post: 09-18-2009, 07:09 PM
  3. unexpected type
    By one in forum New To Java
    Replies: 13
    Last Post: 01-20-2009, 10:32 AM
  4. Unexpected Error
    By Mir in forum New To Java
    Replies: 10
    Last Post: 07-07-2008, 08:57 PM
  5. An unexpected jumper bug on my IO code?
    By cruxblack in forum New To Java
    Replies: 7
    Last Post: 07-29-2007, 09:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •