You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by "Blanchard, Raphael" <Ra...@nrc-cnrc.gc.ca> on 2003/08/06 16:52:13 UTC
SOAPStruct and Apache
Hi,
I have been trying to make a Apache Soap Client for my SOAP::Lite
web service. However I run into problems with SOAPStructs returned by the
service. It seems java cannot deserialize them. I get the following error
message java.lang.IllegalArgumentException: No mapping found for
'http://xml.apache.org/xml-soap:SOAPStruct' using encoding style
'http://schemas.xmlsoap.org/soap/encoding/'. I've tried writting
serializers for java but without any success. Can someone please help me
with this, I'm going nuts...
Raphael
PERL WEB SERVICE USING SOAP LITE
----------------------------------------------------------------------------
----------------------------------------------------------
#!/usr/bin/perl
use SOAP::Transport::HTTP;
use MySearch;
$server = SOAP::Transport::HTTP::CGI
->dispatch_to('WS');
->handle;
exit;
package WS;
sub search {
my $mysearch = new MySearch;
my $hashref_params = {};
$hashref_params->{"max_results"} = 1;
my $sql_statement = $mysearch->get_search_params($hashref_params);
my $sth = $edurss->query($sql_statement);
my (@result_array, $result_row);
while ($result_row = $sth->fetchrow_hashref()) {
foreach my $key (keys %$result_row) {
if (!$result_row->{$key}) {
%$result_row = 'null';
}
}
SOAP::Data->type(DomainInfo => $result_row)->name('item');
push (@result_array, $result_row);
$test = \@result_array;
}
return $#result_array + 1,\@result_array;
}
JAVA CLIENT CODE
----------------------------------------------------------------------------
---------------------------
try {
URL url = new URL("http://myurl/bla.cgi");
String urn = "urn:WS";
Call call = new Call();
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI(urn);
call.setMethodName("search");
SOAPHTTPConnection st = new SOAPHTTPConnection();
SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
SOAPContext reqCtx = call.getSOAPContext();
DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
Envelope callEnv = call.buildEnvelope();
StringWriter payloadSW = new StringWriter();
callEnv.marshall(payloadSW, smr, reqCtx);
reqCtx.setRootPart(payloadSW.toString(),
Constants.HEADERVAL_CONTENT_TYPE);
st.send(url, "", null, null, smr, reqCtx);
SOAPContext respCtx = st.getResponseSOAPContext();
String payloadStr = Call.getEnvelopeString(st);
System.out.println(payloadStr);
Document respDoc = xdb.parse(new InputSource(new
StringReader(payloadStr)));
Element payload = null;
if (respDoc != null) {
payload = respDoc.getDocumentElement();
}
else {
throw new SOAPException(Constants.FAULT_CODE_CLIENT,
"Parsing error, response was:\n" +
payloadStr);
}
Envelope respEnv = Envelope.unmarshall(payload, respCtx);
Response resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
Response response = resp;
if (response.generatedFault()) {
Fault f = response.getFault();
JOptionPane.showMessageDialog(this,"Fault = " + f.getFaultCode() +
"," + f.getFaultString());
}
else {
Parameter ret = response.getReturnValue();
Object value = ret.getValue();
String output = null;
if ( value != null )
{
String[] tlist = (String[])value;
for ( int i = 0; i < tlist.length; i++ )
output.concat(tlist[i]);
}
JOptionPane.showMessageDialog(this,"return: " + output);
}
}
catch (Exception ee) {
JOptionPane.showMessageDialog(this, ee);
System.out.println(ee);
tSearchString.setText(ee.toString());
}
}
SOAP RESULT
----------------------------------------------------------------------------
----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:namesp2="http://xml.apache.org/xml-soap"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<namesp1:searchResponse
xmlns:namesp1="urn:WS">
<s-gensym3 xsi:type="xsd:int">1</s-gensym3>
<SOAP-ENC:Array xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="namesp2:SOAPStruct[1]">
<item xsi:type="namesp2:SOAPStruct">
<link xsi:type="xsd:string">NULL</link>
<feedid xsi:type="xsd:int">103</feedid>
<dc_title
xsi:type="xsd:string">NULL</dc_title>
<feed_title xsi:type="xsd:string">FOS
News</feed_title
<title xsi:type="xsd:string">New Articles on
Open Access The July issue of In ...</title>
<id xsi:type="xsd:int">17226</id>
</item>
</SOAP-ENC:Array>
</namesp1:searchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Re: SOAPStruct and Apache
Posted by Scott Nichol <sn...@scottnichol.com>.
If you can generate WSDL from SOAP::Lite, then Apache Axis will work better for you, because it can use the WSDL to know how to de-serialize.
If you must use Apache SOAP, then you will probably have to write a serializer. I don't know how SOAP::Lite uses 'http://xml.apache.org/xml-soap:SOAPStruct'. That the namespace of the type is 'http://xml.apache.org/xml-soap is disconcerting, as that should only be used for Vector, Map, DataHandler and other types defined by Apache SOAP. SOAPStruct is not defined by Apache SOAP. There is a SOAPStruct from the round2 interop in the namespace
http://soapinterop.org/. That struct looks like Integer myInt;
String myString;
Float myFloat;
What is the structure of the struct you are getting from SOAP::Lite? Can you post the XML payload being sent?
Scott Nichol
Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message -----
From: "Blanchard, Raphael" <Ra...@nrc-cnrc.gc.ca>
To: <so...@ws.apache.org>
Sent: Wednesday, August 06, 2003 10:52 AM
Subject: SOAPStruct and Apache
> Hi,
> I have been trying to make a Apache Soap Client for my SOAP::Lite
> web service. However I run into problems with SOAPStructs returned by the
> service. It seems java cannot deserialize them. I get the following error
> message java.lang.IllegalArgumentException: No mapping found for
> 'http://xml.apache.org/xml-soap:SOAPStruct' using encoding style
> 'http://schemas.xmlsoap.org/soap/encoding/'. I've tried writting
> serializers for java but without any success. Can someone please help me
> with this, I'm going nuts...
>
> Raphael
>
>
>
> PERL WEB SERVICE USING SOAP LITE
> ----------------------------------------------------------------------------
> ----------------------------------------------------------
> #!/usr/bin/perl
>
> use SOAP::Transport::HTTP;
> use MySearch;
>
>
> $server = SOAP::Transport::HTTP::CGI
> ->dispatch_to('WS');
> ->handle;
>
>
> exit;
>
> package WS;
>
> sub search {
> my $mysearch = new MySearch;
> my $hashref_params = {};
> $hashref_params->{"max_results"} = 1;
> my $sql_statement = $mysearch->get_search_params($hashref_params);
> my $sth = $edurss->query($sql_statement);
> my (@result_array, $result_row);
> while ($result_row = $sth->fetchrow_hashref()) {
> foreach my $key (keys %$result_row) {
> if (!$result_row->{$key}) {
> %$result_row = 'null';
> }
> }
>
> SOAP::Data->type(DomainInfo => $result_row)->name('item');
> push (@result_array, $result_row);
> $test = \@result_array;
> }
>
> return $#result_array + 1,\@result_array;
>
> }
>
>
> JAVA CLIENT CODE
> ----------------------------------------------------------------------------
> ---------------------------
> try {
>
> URL url = new URL("http://myurl/bla.cgi");
> String urn = "urn:WS";
> Call call = new Call();
> call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
> call.setTargetObjectURI(urn);
> call.setMethodName("search");
>
>
> SOAPHTTPConnection st = new SOAPHTTPConnection();
>
>
> SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
> BeanSerializer beanSer = new BeanSerializer();
> SOAPContext reqCtx = call.getSOAPContext();
> DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
> Envelope callEnv = call.buildEnvelope();
> StringWriter payloadSW = new StringWriter();
> callEnv.marshall(payloadSW, smr, reqCtx);
> reqCtx.setRootPart(payloadSW.toString(),
> Constants.HEADERVAL_CONTENT_TYPE);
> st.send(url, "", null, null, smr, reqCtx);
> SOAPContext respCtx = st.getResponseSOAPContext();
> String payloadStr = Call.getEnvelopeString(st);
> System.out.println(payloadStr);
> Document respDoc = xdb.parse(new InputSource(new
> StringReader(payloadStr)));
> Element payload = null;
> if (respDoc != null) {
> payload = respDoc.getDocumentElement();
> }
> else {
> throw new SOAPException(Constants.FAULT_CODE_CLIENT,
> "Parsing error, response was:\n" +
> payloadStr);
> }
> Envelope respEnv = Envelope.unmarshall(payload, respCtx);
> Response resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
> Response response = resp;
>
>
> if (response.generatedFault()) {
> Fault f = response.getFault();
> JOptionPane.showMessageDialog(this,"Fault = " + f.getFaultCode() +
> "," + f.getFaultString());
>
> }
> else {
>
> Parameter ret = response.getReturnValue();
> Object value = ret.getValue();
> String output = null;
> if ( value != null )
> {
> String[] tlist = (String[])value;
> for ( int i = 0; i < tlist.length; i++ )
> output.concat(tlist[i]);
> }
> JOptionPane.showMessageDialog(this,"return: " + output);
> }
>
>
> }
> catch (Exception ee) {
> JOptionPane.showMessageDialog(this, ee);
> System.out.println(ee);
> tSearchString.setText(ee.toString());
> }
>
>
>
>
> }
>
>
> SOAP RESULT
> ----------------------------------------------------------------------------
> ----------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
>
> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
>
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/1999/XMLSchema"
> xmlns:namesp2="http://xml.apache.org/xml-soap"
>
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
> <SOAP-ENV:Body>
> <namesp1:searchResponse
> xmlns:namesp1="urn:WS">
> <s-gensym3 xsi:type="xsd:int">1</s-gensym3>
> <SOAP-ENC:Array xsi:type="SOAP-ENC:Array"
> SOAP-ENC:arrayType="namesp2:SOAPStruct[1]">
> <item xsi:type="namesp2:SOAPStruct">
> <link xsi:type="xsd:string">NULL</link>
> <feedid xsi:type="xsd:int">103</feedid>
> <dc_title
> xsi:type="xsd:string">NULL</dc_title>
> <feed_title xsi:type="xsd:string">FOS
> News</feed_title
> <title xsi:type="xsd:string">New Articles on
> Open Access The July issue of In ...</title>
> <id xsi:type="xsd:int">17226</id>
> </item>
> </SOAP-ENC:Array>
> </namesp1:searchResponse>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>