ws-soap-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barry White <ba...@thisbloke.com>
Subject Re: SOAPStruct and Apache
Date Wed, 06 Aug 2003 15:22:21 GMT
Hi Raphael,

I've recently had the same problem as you. I was getting responses with 
different data structures but all identified by something like:

<item xsi:type="namesp2:SOAPStruct">

You have to tell Apache SOAP about this type in the mapping registry, eg:

mappingRegistry.mapTypes(Constants.NS_URI_SOAP_ENC,
new QName(Constants.NS_URI_XML_SOAP, "SOAPStruct"),
MyClass.class, null, new BeanSerializer());

This statement would tell apache soap to use a BeanSerializer to 
deserialize SOAPStruct's into a class of type MyClass.

I found that I had to manipulate the mapping registry for each call to make 
sure it was set up correctly which was a bit of a pain! I created a call 
factory which did this manipulation for me based on the call that I asked 
for and it works quite well.

This link is good for information about creating custome 
serializers/deserializers:
http://www-106.ibm.com/developerworks/webservices/library/ws-soapmap1/

Barry


At 15:52 06/08/2003, you wrote:

>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'>http://xml.apache.org/xml-soap:SOAPStruct'

> using encoding style 
> '<http://schemas.xmlsoap.org/soap/encoding/'>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>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>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>http://www.w3.org/1999/XMLSchema-instance"

>
> 
>xmlns:SOAP-ENC="<http://schemas.xmlsoap.org/soap/encoding/>http://schemas.xmlsoap.org/soap/encoding/"

>
> 
>xmlns:SOAP-ENV="<http://schemas.xmlsoap.org/soap/envelope/>http://schemas.xmlsoap.org/soap/envelope/"

>
> 
>xmlns:xsd="<http://www.w3.org/1999/XMLSchema>http://www.w3.org/1999/XMLSchema"
> 
>xmlns:namesp2="<http://xml.apache.org/xml-soap>http://xml.apache.org/xml-soap"
> 
>SOAP-ENV:encodingStyle="<http://schemas.xmlsoap.org/soap/encoding/>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>



Mime
View raw message