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 Raghavan Srinivasan <ra...@iplanet.com> on 2001/12/15 03:26:55 UTC

Base Complex Type ?

I tried tweaking the address2 Serializers class and created a
BaseSerializer that dynamically loads up other serializers and
deserializers based on the type of the object /
name of the XML element as follows .

public class BaseSerializer
{
public void marshall    (....)
{
        serHandlerType  = complexType + "Serializer" ;
        System.out.println ("BaseSerializer Loading Serializer:" +
serHandlerType) ;
        IPMSerializer serHandler =
(IPMSerializer)Class.forName(serHandlerType).newInstance() ;
        serHandler.serialize(inScopeEncStyle, javaType, src, context ,
sink ,
                                    nsStack, xjmr, ctx ) ;

}

  public Bean unmarshall(String inScopeEncStyle, QName elementType,
                            Node src, XMLJavaMappingRegistry xjmr,
SOAPContext ctx)
         throws IllegalArgumentException
  {
        Class deSerHandlerType = null ;
        IPMSerializer deSerHandler = null ;
        Bean retVal = null ;

        try
        {
            deSerHandlerType = xjmr.queryJavaType( elementType ,
inScopeEncStyle ) ;
            deSerHandler = (IPMSerializer)deSerHandlerType.newInstance()
;

            retVal = deSerHandler.objectify(inScopeEncStyle ,
elementType, src, xjmr , ctx ) ;
        }



The actual objects serializers extend the BaseSerializer and implement
the serialize() and objectify() methods
as follows

    public void serialize( String inScopeEncStyle, Class javaType,
                               Object src, Object context, Writer sink,
                               NSStack nsStack, XMLJavaMappingRegistry
xjmr, SOAPContext ctx )
                throws Exception
    {
        // what am i deserializing ..
        try
        {
            System.out.println ("Inside Address Serializer marshall ") ;

            nsStack.pushScope();

            SoapEncUtils.generateStructureHeader(inScopeEncStyle,
javaType, context,
            sink, nsStack, xjmr);

           // rest of logic here  ......
            ......
    }


    // objectify....
    public Bean objectify(String inScopeEncStyle, QName elementType,
                  Node src, XMLJavaMappingRegistry xjmr, SOAPContext
ctx)
                    throws Exception
    {
        samples.testbase.Address target = null ;

        try
        {
            Element root = (Element)src;
            Element tempEl = DOMUtils.getFirstChildElement(root);
            try
            {
            target =

(samples.testbase.Address)samples.testbase.Address.class.newInstance
                ();
            }

             // rest of logic here
   }

The XML deployment descriptor looks as follows......

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:AddressFetcher2">
  <isd:provider type="java"
                scope="Session"
                methods="getAddressFromName addEntry getAllListings
putListings
>
    <isd:java class="samples.testbase.AddressBook" static="false"/>
  </isd:provider>


<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener

  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:x="urn:xml-soap-address-demo" qname="x:address"
             javaType="samples.testbase.BaseType"
             java2XMLClassName="samples.testbase.BaseSerializer"
             xml2JavaClassName="samples.testbase.BaseSerializer"/>
  </isd:mappings>
</isd:service>


I also tweaked Address , Phone etc to extend samples.testbase.BaseType ,
hoping that the same BaseSerializer would get called when either Phone /
Address needed
to be marshalled / unmarshalled . Somehow Apache seems to be unable to
recognize this relationship and throws the followign exception .....

Inside ABProxy.addEntry():Purdue Boilermaker
Exception in thread "main" [SOAPException: faultCode=SOAP-ENV:Client;
msg=No Ser
ializer found to serialize a 'samples.testbase.Address' using encoding
style 'ht
tp://schemas.xmlsoap.org/soap/encoding/'.;
targetException=java.lang.IllegalArgumentException: No Serializer found
to serialize a 'samples.testbase.Address' usi
ng encoding style 'http://schemas.xmlsoap.org/soap/encoding/'.]
        at
org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnec
tion.java:324)
        at org.apache.soap.rpc.Call.invoke(Call.java:205)
        at
samples.testbase.AddressBookProxy.addEntry(AddressBookProxy.java:132)

        at samples.testbase.Main.doit(Main.java:91)
        at samples.testbase.Main.main(Main.java:133)


Has anyone tried something like this before and got it to work ?

Thanks -
Raghavan