Hi Jochen,
Here is my XML RPC Client code:
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import org.apache.xmlrpc.client.*;
import org.apache.xmlrpc.*;
public class testRpc{
public static void main (String[] args) throws Throwable
{
try
{
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new
URL("http://10.0.56.76:8032/xmlrpc"));
config.setEncoding("iso-8859-1");
XmlRpcClient xmlRpcClient = new XmlRpcClient();
xmlRpcClient.setTransportFactory(new
XmlRpcCommonsTransportFactory(xmlRpcClient));
xmlRpcClient.setConfig(config);
HashMap data = new HashMap();
data.put("1",new Integer(3));
data.put("2",new Integer(5));
Object[] params1 = new Object[]{data};
// Call the server, and get our result.
HashMap result = (HashMap)
xmlRpcClient.execute("Calculator.sumAndDifference",params1);
int sum = ((Integer) result.get("sum")).intValue();
int difference = ((Integer)
result.get("difference")).intValue();
// Print out our result.
System.out.println("Sum: " + Integer.toString(sum) +
", Difference: " +
Integer.toString(difference));
System.out.println(result);
}
catch ( IOException ex ) {
System.out.println( "Network error: The server may not
exist." );
return;
}
catch ( XmlRpcException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
***********************************************************
Here is my Server code:
import java.util.Hashtable;
import org.apache.xmlrpc.server.*;
import org.apache.xmlrpc.webserver.*;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.*;
public class RpcServer {
private int port;
public RpcServer( int port ) {
this.port = port;
}
public static void main( String args[] ) throws Exception {
WebServer webServer = new WebServer(8032);
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.AdderImp
l
*/
phm.load(Thread.currentThread().getContextClassLoader(),"MyHandlers.prop
erties");
xmlRpcServer.setHandlerMapping(phm);
XmlRpcServerConfigImpl serverConfig =
(XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthOptional(false);
webServer.start();
System.out.println("XML-RPC Server started OK");
}
}
****************************************************************
Here is Calculator Class:
import java.util.HashMap;
public class Calculator {
public HashMap sumAndDifference (HashMap data) {
System.out.println("sumAndDifference called");
int x = ((Integer)data.get("1")).intValue();
int y = ((Integer)data.get("2")).intValue();
System.out.println("1:"+ x + "***2:"+y);
HashMap result = new HashMap();
result.put("sum", new Integer(x + y));
result.put("difference", new Integer(x - y));
return result;
}
}
Can you tell me what is wrong in this code?
I try with Wireshark and I don't see ant HTTP packet capture. But it is
all working fine, I just want to investigate what the XML RPC
request/response looks like. Because in real system my Server is not
Java based but C based so I want to see what XML RPC request packet my
Java Client will send to it.
Any help is appreciated.
Thanks,
Preeti
Preeti Vishwakarma
Software Engineer
T: +1 408.962.6137
[EMAIL PROTECTED]
www.sonicwall.com
-----Original Message-----
From: Jochen Wiedmann [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 07, 2007 11:58 AM
To: [email protected]
Subject: Re: Examining XML RPC request packets
On 11/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:
> I have tried Ethreal and Wireshark , they don't help.
Then you did something wrong. They do help. An alternative tool is
tcpmon, btw.
--
Look, that's why there's rules, understand? So that you think before
you break 'em.
-- (Terry Pratchett, Thief of Time)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]