I am
trying to write a Java client that uses Apache SOAP to connect to a service
running gSOAP. I have tried to model it after the addressbook example in the
Apache SOAP toolkit. Unfortunately, when I get back the response, instead of
mapping the data into an AdapterInfo object, the QueryError is mapped as the
response value and the other fields in the struct are stuck in an vector. Can
someone please tell me what is going wrong?
Thanks
---------------------------------------------
Code:
public class AdapterInfo
{
private int QueryError;
private int AdapterID;
private int MemBase;
private int IoBase;
{
private int QueryError;
private int AdapterID;
private int MemBase;
private int IoBase;
public AdapterInfo()
{
}
public AdapterInfo( int
QueryError,
int AdapterID,
int MemBase,
int IoBase)
{
this.QueryError = QueryError ;
this.AdapterID = AdapterID ;
this.MemBase = MemBase ;
this.IoBase = IoBase ;
}
int AdapterID,
int MemBase,
int IoBase)
{
this.QueryError = QueryError ;
this.AdapterID = AdapterID ;
this.MemBase = MemBase ;
this.IoBase = IoBase ;
}
public void setQueryError(int QueryError)
{
this.QueryError = QueryError;
}
public int getQueryError()
{
return QueryError;
}
{
return QueryError;
}
public void setAdapterID(int AdapterID)
{
this.AdapterID = AdapterID;
}
public int getAdapterID()
{
return AdapterID;
}
{
return AdapterID;
}
public void setMemBase(int MemBase)
{
this.MemBase = MemBase;
}
public int getMemBase()
{
return MemBase;
}
{
return MemBase;
}
public void setIoBase(int IoBase)
{
this.IoBase = IoBase;
}
public int getIoBase()
{
return IoBase;
}
{
return IoBase;
}
public String toString()
{
return "Adapter ID = " + AdapterID + "\n" +
"Query error = " + QueryError + "\n" +
"Memory base = " + MemBase + "\n" +
"IO base = " + IoBase + "\n";
}
}
public String GetAdapterInfo(int AdapterID)
// Response???
{
String output = "";
{
String output = "";
try
{
Call call = new Call();
SOAPMappingRegistry smr = new SOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
Vector params = new Vector();
Response resp;
{
Call call = new Call();
SOAPMappingRegistry smr = new SOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
Vector params = new Vector();
Response resp;
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName("urn:remote-adap", "GetAdapInfoResponse"),
AdapterInfo.class,
beanSer,
beanSer);
new QName("urn:remote-adap", "GetAdapInfoResponse"),
AdapterInfo.class,
beanSer,
beanSer);
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:remote-adap");
call.setMethodName("GetAdapterInfo");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI("urn:remote-adap");
call.setMethodName("GetAdapterInfo");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
params.addElement(new org.apache.soap.rpc.Parameter("Adapter", int.class, new
Integer(AdapterID), null));
call.setParams(params);
resp =
call.invoke(ServerUrl, "");
System.out.println("invoke response=" + resp.generatedFault());
// Check the
response.
if (!resp.generatedFault())
{
Vector retParams = resp.getParams();
Parameter ret = resp.getReturnValue();
Object info = ret.getValue();
int i;
if (!resp.generatedFault())
{
Vector retParams = resp.getParams();
Parameter ret = resp.getReturnValue();
Object info = ret.getValue();
int i;
System.out.println("response body part=" +
resp.getBodyPart(0).toString());
System.out.println("response part count=" + resp.getPartCount());
System.out.println("vector part count=" + retParams.size());
System.out.println("response part count=" + resp.getPartCount());
System.out.println("vector part count=" + retParams.size());
for (i=0; i < retParams.size();
i++)
{
Parameter param = (Parameter)retParams.elementAt(i);
{
Parameter param = (Parameter)retParams.elementAt(i);
System.out.println("vector part "+i+" type=" +
param.getValue().getClass());
}
}
System.out.println("output type=" + info.getClass());
output = info.toString();
System.out.println("output=" + output);
}
else
{
Fault fault = resp.getFault();
}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: " +
fault);
}
}
catch (SOAPException se)
{
System.err.println("Caught SOAPException (" +
se.getFaultCode() + "): " +
se.getMessage());
return output;
}
catch (MessagingException me)
{
System.err.println("Caught MessagingException:" +
me.getMessage());
return output;
}
}
}
catch (SOAPException se)
{
System.err.println("Caught SOAPException (" +
se.getFaultCode() + "): " +
se.getMessage());
return output;
}
catch (MessagingException me)
{
System.err.println("Caught MessagingException:" +
me.getMessage());
return output;
}
return output;
}
}
------------------------------------------------------------
Request:
<?xml version='1.0'
encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:GetAdapterInfo
xmlns:ns1="urn:remote-adap"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Adapter
xsi:type="xsd:int">1</Adapter>
</ns1:GetAdapterInfo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------------------------------------------------------------
Response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:remote-adap">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<ns:GetAdapInfoResponse>
<QueryError xsi:type="xsd:int">0</QueryError>
<AdapterID xsi:type="xsd:int">1</AdapterID>
<MemBase xsi:type="xsd:int">-100663296</MemBase>
<IoBase xsi:type="xsd:int">-68173824</IoBase>
</ns:GetAdapInfoResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>