[prev in list] [next in list] [prev in thread] [next in thread] 

List:       soap-user
Subject:    Re: How to deseralize a hashtable?
From:       "Scott Nichol" <snicholnews () scottnichol ! com>
Date:       2004-08-15 21:52:59
Message-ID: 01b001c48312$3bde9770$6401a8c0 () northgate
[Download RAW message or body]

I do not know how Axis handles this.  If the service produces WSDL, that would be the obvious approach for Axis, but without WSDL, I do not know: try axis-user@ws.apache.org.

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: "Chen, Donald" <dchen@nrgn.com>
To: <soap-user@ws.apache.org>
Sent: Friday, August 13, 2004 3:24 PM
Subject: RE: How to deseralize a hashtable?


Scott:

Do you happen to know if there is some serializer equavlent to the
PropertyBabSerialier in Apache-Axis which can be
Helpful on solving the simmilar problem if I use the Apache-Axis to
write the client?

Thanks a lot,

Donald

PS. Axis seems applying an entirely different method to do the ser/des
business.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com] 
Sent: Friday, August 06, 2004 8:18 PM
To: soap-user@ws.apache.org
Subject: Re: How to deseralize a hashtable?


Subsequent to the 2.3.1 release, I wrote a PropertyBagSerializer
(http://cvs.apache.org/viewcvs.cgi/*checkout*/ws-soap/java/src/org/apach
e/soap/encoding/soapenc/PropertyBagSerializer.java?rev=1.3) that can be
used for this.  You would need to either get the last nightly build and
use it instead of 2.3.1, or just grab the code from the CVS link above,
compile it, and put the byte code in your classpath.  Your client code
would look like

        SOAPMappingRegistry smrr = new SOAPMappingRegistry ();
        PropertyBagSerializer pbs = new PropertyBagSerializer ();
        smrr.mapTypes(Constants.NS_URI_SOAP_ENC, new
QName("http://xml.apache.org/xml-soap", "SOAPStruct"), Hashtable.class,
null, pbs);

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: "Chen, Donald" <dchen@nrgn.com>
To: <soap-user@ws.apache.org>
Sent: Friday, August 06, 2004 5:08 PM
Subject: How to deseralize a hashtable?


Hi, All.

I have a WS in Perl via SOAP::Lite.  Via this WS, a client can call a
method getAllInfo() which returns a Hashtable.  I wrote a WS client in
perl with success, but writing a WS client in Java via the
Apache-Soap-2.3.1 is never successful.

Specifically, the error I got is like this:

Exception in thread "main" java.lang.IllegalArgumentException: No
Deserializer found to deserialize a
'http://xml.apache.org/xml-soap:SOAPStruct' using encoding style
'http://schemas.xmlsoap.org/soap/encoding/'.
        at
org.apache.soap.util.xml.XMLJavaMappingRegistry.queryDeserializer(XMLJav
aMappingRegistry.java:206)
        at
org.apache.soap.util.xml.XMLJavaMappingRegistry.unmarshall(XMLJavaMappin
gRegistry.java:302)
        at
org.apache.soap.encoding.soapenc.ParameterSerializer.unmarshall(Paramete
rSerializer.java:206)
        at
org.apache.soap.util.xml.XMLJavaMappingRegistry.unmarshall(XMLJavaMappin
gRegistry.java:314)
        at
org.apache.soap.rpc.RPCMessage.unmarshall(RPCMessage.java:417)
        at
org.apache.soap.rpc.RPCMessage.extractFromEnvelope(RPCMessage.java:197)
        at
org.apache.soap.rpc.Response.extractFromEnvelope(Response.java:142)
        at GetChemDef.main(GetChemDef.java:167)


Here is the payload I got from the server:

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
xmlns:namesp2="http://xml.apache.org/xml-soap"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/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/2001/XMLSchema"><SOAP-ENV:Body><namesp17:ge
tAllInfoResponse
xmlns:namesp17="http://johnny5:8002/ChemDefServices"><s-gensym68
xsi:type="namesp2:SOAPStruct"><delimilator
xsi:type="xsd:string">|</delimilator><chemistry
xsi:type="xsd:string">caffeine</chemistry><a
xsi:type="xsd:string">aPiece</a><smiles
xsi:type="xsd:string">c1ccccc1</smiles><b
xsi:type="xsd:string">bPiece</b><syntaxOk
xsi:type="xsd:int">1</syntaxOk></s-gensym68></namesp17:getAllInfoRespons
e></SOAP-ENV:Body></SOAP-ENV:Envelope>


This payload refects a hashtable:

%h = ( chemistry => 'caffeine',
           a             => 'aPiece',
           b             => 'bPiece',
           smiles     => 'c1ccccc1'
         );

Here are the major code lines (as you can see, I was trying to use the
HashtableSerializer ):

        // build the call.
        Call call = new Call();
        call.setSOAPTransport(st);
 
call.setTargetObjectURI("http://localhost:8002/ChemDefServices");
        call.setMethodName("getAllInfo");

        SOAPMappingRegistry smrr = new SOAPMappingRegistry ();
        HashtableSerializer hsd = new HashtableSerializer ();
        smrr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("",
"ChemDefServices"), Hashtable.class, null, hsd);

        // create the transport and set parameters
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
        call.setSOAPMappingRegistry(smrr);
        Vector params = new Vector();
        params.addElement(new Parameter("definition", String.class,
"definition", null));
        params.addElement(new Parameter("chemDefString", String.class,
chemDefString, null));
        call.setParams(params);

        // invoke it
        System.err.println("Invoking chemDef service at: ");
        System.err.println("\t" + serviceURL);
        Response resp;
        try {
            SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
            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);

            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);
            }
            System.out.println("payloadStr = \n" + payloadStr);
           Envelope respEnv = Envelope.unmarshall(payload, respCtx);
            System.out.println("respEnv = \n" + respEnv.toString());
            System.out.println("respCtx = \n" + respCtx.toString());
            resp = Response.extractFromEnvelope(respEnv, smr, respCtx);
// I got error right here

Did I miss something to make it work?  Do I need to write my own
deseralizer for the hashtable?  If yes, how to incorporate the
deseralizer to the main funciton?

Thanks in advance,

Donald            



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic