You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@ws.apache.org by Jimisola Laursen <li...@jimisola.com> on 2006/07/18 23:54:51 UTC

Re: An example using HandlerMapping

"Read the source Luke"...

Jochen, great work! Truly. Once I read the code and figured it out it worked
on the first run :)

One question though, reading the source there doesn't seem to be a default
handler as there is with the 2.0.x versions. Is this correct or have I
missed out on something?

I've attached some code that I think would be very useful to other as
"Getting started" examples.

Regards,
Jimisola

(the code below uses Calculator, Adder and AdderImpl which are available on
the site for Apache XML-RPC)

Server.java:

package org.apache.xmlrpc.demo.webserver;

import java.net.InetAddress;

import org.apache.xmlrpc.common.TypeConverterFactoryImpl;
import org.apache.xmlrpc.demo.Calculator;
import org.apache.xmlrpc.demo.proxy.Adder;
import org.apache.xmlrpc.demo.webserver.proxy.impls.AdderImpl;
import org.apache.xmlrpc.server.DynamicHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

public class Server
{
    public static void main(String[] args) throws Exception
    {
        WebServer webServer = new WebServer(8080,
InetAddress.getByName("127.0.0.1"));
        
        XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
        
        // use reflection for (dynamic) mapping
        DynamicHandlerMapping dhm = new DynamicHandlerMapping(new
TypeConverterFactoryImpl(), true);
    
        // add "Calculator" handler - used by regular agent
        dhm.addHandler("Calculator", Calculator.class);
        // add Adder handler - using full name for use by dynamic proxy
        dhm.addHandler(Adder.class.getName(), AdderImpl.class);
        xmlRpcServer.setHandlerMapping(dhm);
        
        XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl)
xmlRpcServer.getConfig();
        serverConfig.setEnabledForExtensions(true);
        serverConfig.setContentLengthOptional(false);

        webServer.start();
    }
}


Client.java:

package org.apache.xmlrpc.demo.client;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.client.util.ClientFactory;
import org.apache.xmlrpc.demo.proxy.Adder;

public class Client
{
    public static void main(String[] args) throws XmlRpcException,
MalformedURLException
    {
        // create configuration
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
        config.setEnabledForExtensions(true);  
        config.setConnectionTimeout(60 * 1000);
        config.setReplyTimeout(60 * 1000);

        XmlRpcClient client = new XmlRpcClient();
        
        // use Commons HttpClient as transport
        client.setTransportFactory(new
XmlRpcCommonsTransportFactory(client));
        // set configuration
        client.setConfig(config);

        // make the a regular call
        Object[] params = new Object[]
        { new Integer(2), new Integer(3) };
        Integer result = (Integer) client.execute("Calculator.add", params);
        System.out.println("2 + 3 = " + result);
        
        // make a call using dynamic proxy
        ClientFactory factory = new ClientFactory(client);
        Adder adder = (Adder) factory.newInstance(Adder.class);
        int sum = adder.add(2, 4);
        System.out.println("2 + 4 = " + sum);
    }
}
-- 
View this message in context: http://www.nabble.com/An-example-using-tf1963053.html#a5387175
Sent from the Apache Xml-RPC - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org


RE: An example using HandlerMapping

Posted by Jimisola Laursen <li...@jimisola.com>.
Hi!

I would suggest that you start by checking what values relevant parameters
have in the Server.
This just to make sure whether the root of the problem is caused by the
client or the server.
(btw, have you been able to turn on logging? I tried to get JDK 1.4 logging
working, but no luck so far.)

Regards,
Jimisola
-- 
View this message in context: http://www.nabble.com/An-example-using-tf1963053.html#a5403453
Sent from the Apache Xml-RPC - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org


Re: An example using HandlerMapping

Posted by Jochen Wiedmann <jo...@gmail.com>.
On 7/18/06, Jimisola Laursen <li...@jimisola.com> wrote:

> One question though, reading the source there doesn't seem to be a default
> handler as there is with the 2.0.x versions. Is this correct or have I
> missed out on something?

No, currently there isn't. I understand the use case, so if anyone
provides a patch, I'll be happy to accept it.


> I've attached some code that I think would be very useful to other as
> "Getting started" examples.

Thanks, I'll see that I can put it in somewhere.


Jochen

-- 
Whenever you find yourself on the side of the
majority, it is time to pause and reflect.
(Mark Twain)

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlrpc-user-unsubscribe@ws.apache.org
For additional commands, e-mail: xmlrpc-user-help@ws.apache.org