Java and xmlrpc?

Discussion in 'Java' started by ted holden, Dec 2, 2004.

  1. ted holden

    ted holden Guest

    Has anybody set up xmlrpc for Java recently, say within the last six months,
    and gotten it to work?

    I'm trying to figure out how to use the Apache xmlrpc jar files with Eclipse
    and I'm not getting anywhere terribly quickly...
     
    ted holden, Dec 2, 2004
    #1
    1. Advertising

  2. ted holden

    ted holden Guest

    ted holden wrote:

    >
    >
    > Has anybody set up xmlrpc for Java recently, say within the last six
    > months, and gotten it to work?
    >
    > I'm trying to figure out how to use the Apache xmlrpc jar files with
    > Eclipse and I'm not getting anywhere terribly quickly...



    Problem fixed. This was basically an eclipse glitch, you have to include
    the external jars apriori as you create a project. Adding them later
    should have worked but didn't.
     
    ted holden, Dec 2, 2004
    #2
    1. Advertising

  3. ted holden

    shakah Guest

    I'm using xmlrpc-1.2-b1.jar without difficuly, both client- and
    server-side. Not using it with Eclipse, though.
     
    shakah, Dec 2, 2004
    #3
  4. > I'm using xmlrpc-1.2-b1.jar without difficuly, both client- and
    > server-side. Not using it with Eclipse, though.

    Can you submit an example of how you use it?
    Is it with a large servlet container (e.g. Tomcat) or have you used it
    "standalone"?

    Regards,
    Martin Egholm
     
    Martin Egholm Nielsen, Dec 3, 2004
    #4
  5. ted holden

    shakah Guest

    Sorry, didn't see your post. If you're still interested...

    client-side (stand-alone Java app):
    org.apache.xmlrpc.XmlRpcClientLite xrc_ = new
    org.apache.xmlrpc.XmlRpcClientLite("http://www.acme.com/xmlrpcurl") ;

    java.util.Vector vParams = new java.util.Vector() ;
    java.util.Hashtable ht = new java.util.Hashtable() ;
    ht.put("environment", sEnvironment) ;
    ht.put("authData", sAuthData) ;
    vParams.addElement(ht) ;

    String sToken = (String) xrc_.execute("myserver.attach", vParams) ;

    server-side (Tomcat, actually in a JSP):
    // ...XML/RPC handler class
    public static class MyHandler {
    public String attach(java.util.Hashtable h)
    throws java.security.NoSuchAlgorithmException
    ,org.apache.xmlrpc.XmlRpcException {
    try {
    // ...the required args
    String sEnvironment = (String) h.get("environment") ;
    String sAuthData = (String) h.get("authData") ;

    // ...etc

    return "return value" ;
    }
    catch(NullPointerException x) {
    throw new org.apache.xmlrpc.XmlRpcException(-2, "missing
    \"environment\" or \"authData\" parameters?") ;
    }
    catch(ClassCastException x) {
    throw new org.apache.xmlrpc.XmlRpcException(-2, "unexpected
    \"environment\" or \"authData\" parameter types?") ;
    }
    }
    }

    // ...one-time init
    private static org.apache.xmlrpc.XmlRpcServer xrs = null ;
    if(null==xrs) {
    xrs = new org.apache.xmlrpc.XmlRpcServer() ;
    xrs.addHandler("myserver", new MyHandler()) ;
    }
     
    shakah, Dec 7, 2004
    #5
  6. ted holden

    shakah Guest

    To clarify the "one-time init" code snippet -- the JSP more-or-less
    does:

    if(null!=request.getContentType() &&
    request.getContentType().equals("text/xml")) {
    if(null==xrs) {
    xrs = new org.apache.xmlrpc.XmlRpcServer() ;
    xrs.addHandler("myserver", new MyHandler()) ;
    }

    byte [] abResult = xrs.execute(request.getInputStream()) ;

    response.setContentType("text/xml") ;
    response.setContentLength(abResult.length) ;
    out.clear() ;
    out.write(new String(abResult)) ;
    out.flush() ;
    }
     
    shakah, Dec 7, 2004
    #6
  7. ted holden

    shakah Guest

    To clarify the "one-time init" code snippet -- the JSP more-or-less
    does:

    if(null!=request.getContentType() &&
    request.getContentType().equals("text/xml")) {
    if(null==xrs) {
    xrs = new org.apache.xmlrpc.XmlRpcServer() ;
    xrs.addHandler("myserver", new MyHandler()) ;
    }

    byte [] abResult = xrs.execute(request.getInputStream()) ;

    response.setContentType("text/xml") ;
    response.setContentLength(abResult.length) ;
    out.clear() ;
    out.write(new String(abResult)) ;
    out.flush() ;
    }
     
    shakah, Dec 7, 2004
    #7
  8. Hi Shakah (and others),

    > Sorry, didn't see your post. If you're still interested...

    Sure I am - thanks alot! Haven't tried it yet, though. But it makes a
    lot of sense...
    How many external libs are required? Hopefully not the huge and almighty
    xalan.jar etc.?

    I'm hoping for a solution that I can fit in an embedded system...

    Is there a way to have the rpc-server share the connection/stream with
    an ordinary webserver? That is, I have this simple webserver for
    displaying some regular html, and I would like to overlay the rpc part
    somehow...

    Regards,
    Martin Egholm

    > client-side (stand-alone Java app):
    > org.apache.xmlrpc.XmlRpcClientLite xrc_ = new
    > org.apache.xmlrpc.XmlRpcClientLite("http://www.acme.com/xmlrpcurl") ;
    >
    > java.util.Vector vParams = new java.util.Vector() ;
    > java.util.Hashtable ht = new java.util.Hashtable() ;
    > ht.put("environment", sEnvironment) ;
    > ht.put("authData", sAuthData) ;
    > vParams.addElement(ht) ;
    >
    > String sToken = (String) xrc_.execute("myserver.attach", vParams) ;
    >
    > server-side (Tomcat, actually in a JSP):
    > // ...XML/RPC handler class
    > public static class MyHandler {
    > public String attach(java.util.Hashtable h)
    > throws java.security.NoSuchAlgorithmException
    > ,org.apache.xmlrpc.XmlRpcException {
    > try {
    > // ...the required args
    > String sEnvironment = (String) h.get("environment") ;
    > String sAuthData = (String) h.get("authData") ;
    >
    > // ...etc
    >
    > return "return value" ;
    > }
    > catch(NullPointerException x) {
    > throw new org.apache.xmlrpc.XmlRpcException(-2, "missing
    > \"environment\" or \"authData\" parameters?") ;
    > }
    > catch(ClassCastException x) {
    > throw new org.apache.xmlrpc.XmlRpcException(-2, "unexpected
    > \"environment\" or \"authData\" parameter types?") ;
    > }
    > }
    > }
    >
    > // ...one-time init
    > private static org.apache.xmlrpc.XmlRpcServer xrs = null ;
    > if(null==xrs) {
    > xrs = new org.apache.xmlrpc.XmlRpcServer() ;
    > xrs.addHandler("myserver", new MyHandler()) ;
    > }
    >



    > To clarify the "one-time init" code snippet -- the JSP more-or-less
    > does:
    >
    > if(null!=request.getContentType() &&
    > request.getContentType().equals("text/xml")) {
    > if(null==xrs) {
    > xrs = new org.apache.xmlrpc.XmlRpcServer() ;
    > xrs.addHandler("myserver", new MyHandler()) ;
    > }
    >
    > byte [] abResult = xrs.execute(request.getInputStream()) ;
    >
    > response.setContentType("text/xml") ;
    > response.setContentLength(abResult.length) ;
    > out.clear() ;
    > out.write(new String(abResult)) ;
    > out.flush() ;
    > }
    >
     
    Martin Egholm Nielsen, Dec 8, 2004
    #8
  9. ted holden wrote:

    > Problem fixed. This was basically an eclipse glitch, you have to include
    > the external jars apriori as you create a project. Adding them later
    > should have worked but didn't.


    That's odd. Adding Jars to a project later generally does work for me.
    YMMV.


    John Bollinger
     
    John C. Bollinger, Dec 8, 2004
    #9
  10. ted holden

    shakah Guest

    I think the only required jar is xmlrpc-1.2-b1.jar (at least for the
    version I'm using).

    As for the webserver, you can "share the connection/stream with an
    ordinary webserver". For example, you could run the XML/RPC service
    under:

    http://[hostname]/services/myxmlrpcserver.jsp
    without affecting the rest of the web server.
     
    shakah, Dec 8, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Aschwanden
    Replies:
    2
    Views:
    809
    Shalabh Chaturvedi
    Dec 29, 2003
  2. Etienne Posthumus
    Replies:
    1
    Views:
    1,110
    Roger Binns
    Apr 1, 2004
  3. writeson
    Replies:
    5
    Views:
    374
    writeson
    Mar 23, 2005
  4. Joxean Koret

    XMLRPC and non-ascii characters

    Joxean Koret, Jun 29, 2005, in forum: Python
    Replies:
    1
    Views:
    342
    Richard Brodie
    Jun 29, 2005
  5. fortepianissimo
    Replies:
    1
    Views:
    374
    fortepianissimo
    Oct 23, 2006
Loading...

Share This Page