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 Han Ming Ong <ha...@chirpyfish.org> on 2002/02/01 19:08:35 UTC
[Solved] Customized Serializer
I guess my mail was way too long for people to actually read it :)
Anyway, based on the input of one kind soul, I explored further and
finally hit on something that worked. It might not be the right way but
it worked for now and I just want to share with the list, in case
someone else is banging his head on the wall:
1. Using a customized Encoding Style URI besides
Constants.NS_URI_SOAP_ENC always result in an exception something like
"Caught SOAPException (SOAP-ENV:Client): No Serializer found to
serialize a 'org.apache.soap.rpc.Parameter' using encoding style
'http://xxx.com/test'.
2. Using Constants.NS_URI_SOAP_ENC works. I made a mistake in my
serializer. I forgot the end tag
"</PurchaseOrder>". So if I had added
sink.write("</" + context + '>');
It worked for me.
That's all, Han Ming
> From: Han Ming Ong <ha...@chirpyfish.org>
> Date: Sun Jan 27, 2002 03:55:45 PM US/Pacific
> To: soap-user@xml.apache.org
> Subject: Customized Serializer
>
> Hi folks,
>
> Short:
> I know how to use a BeanSerializer or sub class of a BeanSerializer
> to serialize a customized class. I usually use
> Constants.NS_URI_SOAP_ENC when I insert it into SOAPMappingRegistry.
>
> But I would like to make use of a generic XML Serializer (e.g.
> http://www.csse.monash.edu.au/~bren/JSX/)
> What encoding style should I use?
>
>
>
> Long:
>
> This is my customized Java class:
>
> public class PurchaseOrder {
> ...
> }
>
> I would like to make use of a generic Java XML Serializer (e.g
> http://www.csse.monash.edu.au/~bren/JSX/) as the Serializer and
> Deserializer.
>
> public class PurchaseOrderSerializer implements Serializer,
> Deserializer {
> public void marshall(String inScopeEncStyle, Class javaType, Object
> src, Object context, Writer sink, NSStack nsStack,
> XMLJavaMappingRegistry xjmr, SOAPContext ctx) throws
> IllegalArgumentException, IOException {
>
> nsStack.pushScope();
>
> SoapEncUtils.generateStructureHeader(inScopeEncStyle, javaType,
> context, sink, nsStack, xjmr);
>
> // Magically obtain a serialized XML string, for example using JSX
> String xml = ....
>
> sink.write(xml);
>
> nsStack.popScope();
> }
>
> public Bean unmarshall(String inScopeEncStyle, QName elementType,
> Node src, XMLJavaMappingRegistry xjmr, SOAPContext ctx) throws
> IllegalArgumentException {
> Element root = (Element) src;
> PurchaseOrder target;
>
> // This is sad.
> String xml = DOMWriter.nodeToString(src);
>
> target = (PurchaseOrder).... // Use JSX to get back object
>
> return new Bean(PurchaseOrder.class, target);
> }
>
> So on the server end, I created this deployment descriptor
>
> <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
> id="urn:myServer">
> <isd:provider type="java"
> scope="Application"
> methods="SubmitOrder1">
> <isd:java class="xxx.com.Application" static="true"/>
> </isd:provider>
>
>
> <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
>
> <isd:mappings>
> <isd:map encodingStyle="http://xxx.com/test"
> xmlns:x="urn:wo-xml-demo" qname="x:PurchaseOrder"
> javaType="xxx.com.PurchaseOrder"
> java2XMLClassName="xxx.com.PurchaseOrderSerializer"
>
> xml2JavaClassName="xxx.com.PurchaseOrderSerializerOrderSerializer"/>
> </isd:mappings>
> </isd:service>
>
>
> This is how I execute my call from client
>
> PurchaseOrderSerializer poSer = new PurchaseOrderSerializer();
> SOAPMappingRegistry smr = new SOAPMappingRegistry();
> String myEnc = "http://xxx.com/test";
> // Map the types.
> smr.mapTypes(myEnc, new QName("urn:wo-xml-demo",
> "PurchaseOrder"), PurchaseOrder.class, poSer, poSer);
>
> // Build the call.
> call.setSOAPMappingRegistry(smr);
> call.setTargetObjectURI("urn:myServer");
> call.setMethodName("SubmitOrder1");
> call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
> params.addElement(new Parameter("CustomerID",
> java.lang.String.class, pin, Constants.NS_URI_SOAP_ENC));
> params.addElement(new Parameter("PurchaseOrder",
> PurchaseOrder.class, po, myEnc));
> call.setParams(params);
>
> // Invoke the call.
> try {
> resp = call.invoke(serviceURL, "");
> } catch (SOAPException e) {
> System.out.print("Caught SOAPException (" +
> e.getFaultCode() + "): " + e.getMessage());
> }
>
>
> Problems:
>
> I always get a SOAPException, something like "Caught SOAPException
> (SOAP-ENV:Client): No Serializer found to serialize a
> 'org.apache.soap.rpc.Parameter' using encoding style
> 'http://xxx.com/test'.
> (Here, I'm kind of surprised that the class is not xxx.com.PurchaseOrder
>
> If I used Constants.NS_URI_SOAP_ENC, the exception would be
>
> Caught SOAPException (SOAP-ENV:Client): Parsing error, response was:
> The element type "faultstring" must be terminated by the matching
> end-tag "</faultstring>".
>
> I also tried Constants.NS_URI_LITERAL_XML and Constants.NS_URI_XMI_ENC
> but no success.
>
> Help please?
>