Java and xmlrpc?

T

ted holden

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...
 
T

ted holden

ted said:
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.
 
S

shakah

I'm using xmlrpc-1.2-b1.jar without difficuly, both client- and
server-side. Not using it with Eclipse, though.
 
M

Martin Egholm Nielsen

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
 
S

shakah

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()) ;
}
 
S

shakah

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() ;
}
 
S

shakah

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() ;
}
 
M

Martin Egholm Nielsen

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() ;
}
 
J

John C. Bollinger

ted said:
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
(e-mail address removed)
 
S

shakah

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top