Menu

how can i use XmlRpcProxy.createProxy

Help
2008-03-06
2013-04-25
  • wim verreycken

    wim verreycken - 2008-03-06

    Hello everyone,

    I'm a newbie in xml-rpc, or any kind of rpc for that matter.
    I can't get XmlRpcProxy.createProxy to work with my service.
    This code works fine :
            Object result = null;
        XmlRpcClient client = new XmlRpcClient( "http://127.0.0.1:8080/xml-rpc/RPC2", false );
        if(client != null) {
            result = client.invoke("Hello.sayHello", new Object[] {"wim", "mysecret"} );
            System.out.println("result is : " + result);
        }
        else System.out.println("error : client is null.");

    I want to use an XmlRpcProxy instead of the XmlRpcClient, but I cant seem to get the syntax right.
    Can anyone privide me the working code for xmlrpc-1.1 to obtain the result from my Hello service
    using an XmlRpcProxy ubstead?

    Thanks a lot!

     
    • Greger Ohlson

      Greger Ohlson - 2008-03-07

      Hi,

      What errors do you get? Compilation errors or runtime errors? It should look something like this:

      import redstone.xmlrpc.XmlRpcProxy;
      import redstone.xmlrpc.XmlRpcFault;

      // This interface is most likely placed in a file of its own.
      static interface Hello
      {
          public String sayHello( String username, String password ) throws XmlRpcFault;
      }

      public static void main( String[] args ) throws Exception
      {
          Hello helloService = ( Hello ) XmlRpcProxy.createProxy( "http://127.0.0.1:8080/xml-rpc/RPC2", new Class[] { Hello.class } );
          System.out.println( helloService.sayHello( "wim", "mysecret" ) );
      }

      Cheers!
      Greger

       
    • wim verreycken

      wim verreycken - 2008-03-07

      Hi,

      The first thing i notice in your code is this :
      static interface Hello

      My interface is not static. I'm using jdk 1.6 and if I try to declare an interface "static" I get this compile error :
      Illegal modifier for the interface MyHelloService. only abstract & public are allowed.
      It is the same when i try it on a new interface in a new project.
      Is this a problem?

      (BTW Why would anyone declare an interface to be static?)

      tnx,
      Wim

       
      • Greger Ohlson

        Greger Ohlson - 2008-03-07

        Hi,

        Sorry, the example wasn't quite clear. The Hello interface requires a static modifier
        if the interface is defined within another class like below. But normally you define
        interfaces in their own files in which case 'static' is not used. The static below
        means that the interface has no association with Application other than the fact that
        it is declared within the Application class and its full name is Application.Hello when
        used outside of the class.

        Anyway... just put Hello in Hello.java instead and forget about the static thingy :-)

        Let me know how it works out for you.

        Regards,
        Greger.

        public class Application
        {
            static interface Hello
            {
               ...
            }

            public static void main( String[] args ) throws XmlRpcException, IOException, XmlRpcFault
            {
               ...
            }
        }

         
    • wim verreycken

      wim verreycken - 2008-03-07

      Hi greger,

      I found my mistake. The name of the InvocationHandler I used in my example service was not the same as
      the name of the interface. This is obviously required :-) I forgot to update it somewhere along.
      The interface does not need to be static.

      Also, it seems the createProxy method has had somewhat of an update. I found the line needed to create the proxy is :

      Hello helloService = ( Hello ) XmlRpcProxy.createProxy (new URL ("http://127.0.0.1:8080/xml-rpc/RPC2"), new Class[]{MyHelloService.class}, false);

      It now takes URL, Class[], boolean as arguments, so you will also need to import import java.net.URL;

      Thanks a lot for your help.
      Cheers,

      wim

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.