You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by Yusuf Goolamabbas <yu...@outblaze.com> on 2000/08/18 03:34:03 UTC
How to get SOAP client to pass structures to SOAP/Perl server
Hi, I have the sample Geometry.pm from Keith Brown running under a mod-perl
enabled server. This class takes 2 parameters [origin/corner] which are
structures. I got a client working in perl. I then attempted to write a
client in Java using the IBM SOAP implementation. I seem to have a
problem getting the elements of the structure serialized. I am enclosing
my client code. Would appreciate where I am goofing up
I am also enclosing the Geometry.pm class which sits behind the
SOAP/Perl endpoint
Regards, Yusuf
--
Yusuf Goolamabbas
yusufg@outblaze.com
import java.io.*;
import java.net.*;
import java.util.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
class origin
{
private int x ;
private int y ;
public origin()
{
}
public origin(int x, int y)
{
this.x = x;
this.y = y;
}
public void setx(int x)
{
this.x = x ;
}
public void sety(int x)
{
this.y = y ;
}
public int getx(int x)
{
return this.x ;
}
public int gety(int x)
{
return this.y ;
}
public String toString()
{
return x + " " + y ;
}
}
class corner
{
private int x ;
private int y ;
public corner()
{
}
public corner(int x, int y)
{
this.x = x;
this.y = y;
}
public void setx(int x)
{
this.x = x ;
}
public void sety(int x)
{
this.y = y ;
}
public int getx(int x)
{
return this.x ;
}
public int gety(int x)
{
return this.y ;
}
public String toString()
{
return x + " " + y;
}
}
public class Geo {
public static void main (String[] args) throws Exception {
final boolean debug = false;
System.out.println("args[0] = " + args[0]);
String methodName = "calculateArea";
SOAPMappingRegistry smr = new SOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("urn:com-develop-geometry", "corner"),
corner.class, beanSer, beanSer);
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("urn:com-develop-geometry", "origin"),
origin.class, beanSer, beanSer);
// Build the call.
Call call = new Call ();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI ("urn:com-develop-geometry");
call.setMethodName (methodName);
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector ();
corner corn = new corner(100,200);
origin orig = new origin(10,20);
params.addElement(new Parameter("origin", origin.class,
orig, null));
params.addElement(new Parameter("corner", corner.class,
corn, null));
call.setParams (params);
if (debug) {
Writer sink = new StringWriter();
Envelope env = call.buildEnvelope();
env.marshall(sink, new SOAPMappingRegistry());
System.out.println("Request envelope:");
System.out.println(sink);
}
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
URL url = new URL(args[0]);
if (debug) {
System.out.println("\n\nSending request...\n\n");
}
String actionURI = "urn:com-develop-geometry#" + methodName ;
Response resp = call.invoke (/* router URL */ url, /* actionURI */ actionURI );
if (debug) {
System.out.println("\n\nGot response.\n\n");
}
// Check the response.
if (resp.generatedFault ()) {
Fault fault = resp.getFault ();
System.out.println ("Ouch, the call failed: ");
System.out.println (" Fault Code = " + fault.getFaultCode ());
System.out.println (" Fault String = " + fault.getFaultString ());
} else {
Parameter result = resp.getReturnValue ();
System.out.println (methodName + " = " + result.getValue());
}
}
}