[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlrpc-user
Subject: How can I get it running under Tomcat?
From: Richard Gomes <rgomes1997 () yahoo ! co ! uk>
Date: 2008-10-13 1:59:40
Message-ID: 200810130259.41139.rgomes1997 () yahoo ! co ! uk
[Download RAW message or body]
Hi,
I've managed to get my tiny proof of concept running.
When I run my standalone server it responds properly to the client.
This is the client:
public class Client {
public static void main(String[] args) throws Exception {
// create configuration
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new \
URL("http://localhost:8080/jquantlib-xmlrpc/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) };
Double result = (Double) client.execute("DayCounter.evaluate", params);
System.out.println("Response is " + result);
}
}
This is the server:
public class Server {
private static final int port = 8080;
public static void main(String[] args) throws Exception {
WebServer webServer = new WebServer(port);
XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
/*
* Load handler definitions from a property file.
* The property file might look like:
* Calculator=org.apache.xmlrpc.demo.Calculator
* org.apache.xmlrpc.demo.proxy.Adder=org.apache.xmlrpc.demo.proxy.AdderImpl
*/
phm.load(Thread.currentThread().getContextClassLoader(), \
"org/apache/xmlrpc/webserver/XmlRpcServlet.properties");
/*
* You may also provide the handler classes directly, like this:
* phm.addHandler("Calculator", org.apache.xmlrpc.demo.Calculator.class);
* phm.addHandler(org.apache.xmlrpc.demo.proxy.Adder.class.getName(), \
org.apache.xmlrpc.demo.proxy.AdderImpl.class);
*/
xmlRpcServer.setHandlerMapping(phm);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) \
xmlRpcServer.getConfig(); serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthOptional(false);
webServer.start();
}
}
I also followed the steps on ...
http://ws.apache.org/xmlrpc/xmlrpc2/server.html
...but the example is not complete and the code seems to be outdated.
In particular, the following snippets of code seem to be relative to a previous \
version:
XmlRpcServer xmlrpc = new XmlRpcServer ();
xmlrpc.addHandler ("examples", new ExampleHandler ());
...
byte[] result = xmlrpc.execute (request.getInputStream ());
response.setContentType ("text/xml");
response.setContentLength (result.length());
OutputStream out = response.getOutputStream();
out.write (result);
out.flush ();
When I deploy into Tomcat6, it fails like this:
Exception in thread "main" org.apache.xmlrpc.client.XmlRpcClientException: Failed to \
parse servers response: Expected methodResponse element, got html at \
org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:177)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:145)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:94)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:53)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:166)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:136)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:125)
at org.jquantlib.xmlrpc.client.Client.main(Client.java:28)
Caused by: org.xml.sax.SAXParseException: Expected methodResponse element, got html
For more information, my test can be obtained via
svn co http://jquant.svn.sourceforge.net/svnroot/jquant/trunk/jquantlib-xmlrpc
Any idea?
Thanks a lot
Richard Gomes
http://www.jquantlib.org/index.php/User:RichardGomes
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic