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 David Turner <tu...@genome.wi.mit.edu> on 2001/10/25 16:12:16 UTC

Serializers/Deserializers

Has anyone developed their own serializers & deserializers for their
classes instead of using the BeanSerializer?

I've attempted to write my own serializer/deserializer for the
java.net.URL class in order to pass URL's to my service method, but the
server sends back a fault:
      Fault Code = SOAP-ENV:Server.Exception:
      Fault String = org/apache/soap/util/xml/Deserializer

I've attempted to write serializers/deserializers for a simple class
also (class contains only Strings) instead of the BeanSerializer and I
still get the above exception.

Anybody know what's going wroing?  How do you set this up on both the
client and server (deployment descr)?

Below is the code:

Deployment Descriptor
--------------------------------------------------------------------------------------------------------------

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:SimpleURLService">
  <isd:provider type="java"
                scope="Session"
                methods="serviceMethod">
    <isd:java
class="examples.omnitide.SimpleURLService.SimpleURLService"
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:xsd="http://www.w3.org/1999/XMLSchema"
qname="xsd:URL"
             javaType="java.net.URL"

xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>

  </isd:mappings>

</isd:service>



Client that calls soap service
--------------------------------------------------------------------------------------------------------------

      // Map the types
       SOAPMappingRegistry smr = new SOAPMappingRegistry();

       URLSerializer ser = new URLSerializer();
       URLDeserializer des = new URLDeserializer();

       smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
QName("urn:SimpleURLService", "URL"),
           URL.class, ser, des);

       // Build the call
       Call call = new Call();
       call.setSOAPMappingRegistry(smr);
       call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
       call.setTargetObjectURI("urn:SimpleURLService");
       call.setMethodName("serviceMethod");

       Vector params = new Vector();
       params.addElement(new Parameter("request", URL.class, url,
null));
       call.setParams(params);



Serializer
--------------------------------------------------------------------------------------------------------------

import java.net.URL;

public class URLSerializer implements Serializer
{

  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);

      sink.write(StringUtils.lineSeparator);

      URL src2 = (URL) src;

      Parameter param;

      param = new Parameter("URL", String.class, src2.toString(), null);

      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
                    sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);

      sink.write("</" + context + ">");

      nsStack.popScope();
  }
}



Deserializer
--------------------------------------------------------------------------------------------------------------

public class URLDeserializer implements Deserializer
{
  public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
src,
                         XMLJavaMappingRegistry xjmr, SOAPContext ctx)
                          throws IllegalArgumentException
  {
    Element root = (Element)src;
    Element tempEl = DOMUtils.getFirstChildElement(root);

    URL url = null;

    while (tempEl != null)
    {
        Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
RPCConstants.Q_ELEM_PARAMETER,
                                         tempEl, ctx);
        Parameter param = (Parameter)paramBean.value;
        String tagName = tempEl.getTagName();

        if (tagName.equals("URL"))
        {
            try
            {
                url = new URL( (String)param.getValue() );
            }
            catch (Exception e)
            {
                throw new IllegalArgumentException("Problem
instantianting bean: " + e.getMessage());
            }

        }

        tempEl = DOMUtils.getNextSiblingElement(tempEl);
    }


    return new Bean(URL.class, url);
  }
}


question on inter-operability

Posted by Amit Rana <ra...@mbc2.co.jp>.
Hi,
	Is it possible to call a service hosted using Microsoft Soap Development
Kit using Apache Soap.

	I mean Apache Soap at one end and Microsoft Soap on another.

Best Regards,
Amit.


question on inter-operability

Posted by Amit Rana <ra...@mbc2.co.jp>.
Hi,
	Is it possible to call a service hosted using Microsoft Soap Development
Kit using Apache Soap.

	I mean Apache Soap at one end and Microsoft Soap on another.

Best Regards,
Amit.


Re: Serializers/Deserializers

Posted by Paramdeep Singh <ma...@yahoo.com>.
I have developed some serializers for some classes.
You can have a look at the WSTK from IBM.

It automatically generates the serializers/deserializers for you.

With warm regards
Paramdeep

----- Original Message -----
From: "David Turner" <tu...@genome.wi.mit.edu>
To: <so...@xml.apache.org>
Sent: Thursday, October 25, 2001 7:42 PM
Subject: Serializers/Deserializers


> Has anyone developed their own serializers & deserializers for their
> classes instead of using the BeanSerializer?
>
> I've attempted to write my own serializer/deserializer for the
> java.net.URL class in order to pass URL's to my service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String = org/apache/soap/util/xml/Deserializer
>
> I've attempted to write serializers/deserializers for a simple class
> also (class contains only Strings) instead of the BeanSerializer and I
> still get the above exception.
>
> Anybody know what's going wroing?  How do you set this up on both the
> client and server (deployment descr)?
>
> Below is the code:
>
> Deployment Descriptor
> --------------------------------------------------------------------------
------------------------------------
>
> <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
> class="examples.omnitide.SimpleURLService.SimpleURLService"
> static="false"/>
>   </isd:provider>
>
>
>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListene
r>
>
>   <isd:mappings>
>     <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>              xmlns:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
>
> xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
>
>   </isd:mappings>
>
> </isd:service>
>
>
>
> Client that calls soap service
> --------------------------------------------------------------------------
------------------------------------
>
>       // Map the types
>        SOAPMappingRegistry smr = new SOAPMappingRegistry();
>
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
>
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
>
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>        call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
>
>        Vector params = new Vector();
>        params.addElement(new Parameter("request", URL.class, url,
> null));
>        call.setParams(params);
>
>
>
> Serializer
> --------------------------------------------------------------------------
------------------------------------
>
> import java.net.URL;
>
> public class URLSerializer implements Serializer
> {
>
>   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);
>
>       sink.write(StringUtils.lineSeparator);
>
>       URL src2 = (URL) src;
>
>       Parameter param;
>
>       param = new Parameter("URL", String.class, src2.toString(), null);
>
>       xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
>
>       sink.write("</" + context + ">");
>
>       nsStack.popScope();
>   }
> }
>
>
>
> Deserializer
> --------------------------------------------------------------------------
------------------------------------
>
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
> src,
>                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
>                           throws IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl = DOMUtils.getFirstChildElement(root);
>
>     URL url = null;
>
>     while (tempEl != null)
>     {
>         Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl, ctx);
>         Parameter param = (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
>
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL( (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
>
>         }
>
>         tempEl = DOMUtils.getNextSiblingElement(tempEl);
>     }
>
>
>     return new Bean(URL.class, url);
>   }
> }


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Re: Serializers/Deserializers

Posted by Paramdeep Singh <ma...@yahoo.com>.
I have developed some serializers for some classes.
You can have a look at the WSTK from IBM.

It automatically generates the serializers/deserializers for you.

With warm regards
Paramdeep

----- Original Message -----
From: "David Turner" <tu...@genome.wi.mit.edu>
To: <so...@xml.apache.org>
Sent: Thursday, October 25, 2001 7:42 PM
Subject: Serializers/Deserializers


> Has anyone developed their own serializers & deserializers for their
> classes instead of using the BeanSerializer?
>
> I've attempted to write my own serializer/deserializer for the
> java.net.URL class in order to pass URL's to my service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String = org/apache/soap/util/xml/Deserializer
>
> I've attempted to write serializers/deserializers for a simple class
> also (class contains only Strings) instead of the BeanSerializer and I
> still get the above exception.
>
> Anybody know what's going wroing?  How do you set this up on both the
> client and server (deployment descr)?
>
> Below is the code:
>
> Deployment Descriptor
> --------------------------------------------------------------------------
------------------------------------
>
> <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
> class="examples.omnitide.SimpleURLService.SimpleURLService"
> static="false"/>
>   </isd:provider>
>
>
>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListene
r>
>
>   <isd:mappings>
>     <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>              xmlns:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
>
> xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
>
>   </isd:mappings>
>
> </isd:service>
>
>
>
> Client that calls soap service
> --------------------------------------------------------------------------
------------------------------------
>
>       // Map the types
>        SOAPMappingRegistry smr = new SOAPMappingRegistry();
>
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
>
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
>
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>        call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
>
>        Vector params = new Vector();
>        params.addElement(new Parameter("request", URL.class, url,
> null));
>        call.setParams(params);
>
>
>
> Serializer
> --------------------------------------------------------------------------
------------------------------------
>
> import java.net.URL;
>
> public class URLSerializer implements Serializer
> {
>
>   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);
>
>       sink.write(StringUtils.lineSeparator);
>
>       URL src2 = (URL) src;
>
>       Parameter param;
>
>       param = new Parameter("URL", String.class, src2.toString(), null);
>
>       xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
>
>       sink.write("</" + context + ">");
>
>       nsStack.popScope();
>   }
> }
>
>
>
> Deserializer
> --------------------------------------------------------------------------
------------------------------------
>
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
> src,
>                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
>                           throws IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl = DOMUtils.getFirstChildElement(root);
>
>     URL url = null;
>
>     while (tempEl != null)
>     {
>         Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl, ctx);
>         Parameter param = (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
>
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL( (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
>
>         }
>
>         tempEl = DOMUtils.getNextSiblingElement(tempEl);
>     }
>
>
>     return new Bean(URL.class, url);
>   }
> }


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Re: Serializers/Deserializers

Posted by k young <yo...@yahoo.com>.
Have you tried send the URL as a java.lang.String? 
You could reconstruct the URL on the otherside.


--- David Turner <tu...@genome.wi.mit.edu> wrote:
> Has anyone developed their own serializers &
> deserializers for their
> classes instead of using the BeanSerializer?
> 
> I've attempted to write my own
> serializer/deserializer for the
> java.net.URL class in order to pass URL's to my
> service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String =
> org/apache/soap/util/xml/Deserializer
> 
> I've attempted to write serializers/deserializers
> for a simple class
> also (class contains only Strings) instead of the
> BeanSerializer and I
> still get the above exception.
> 
> Anybody know what's going wroing?  How do you set
> this up on both the
> client and server (deployment descr)?
> 
> Below is the code:
> 
> Deployment Descriptor
>
--------------------------------------------------------------------------------------------------------------
> 
> <isd:service
>
xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
>
class="examples.omnitide.SimpleURLService.SimpleURLService"
> 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:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
> 
>
xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
> 
>   </isd:mappings>
> 
> </isd:service>
> 
> 
> 
> Client that calls soap service
>
--------------------------------------------------------------------------------------------------------------
> 
>       // Map the types
>        SOAPMappingRegistry smr = new
> SOAPMappingRegistry();
> 
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
> 
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
> 
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>       
> call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>       
> call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
> 
>        Vector params = new Vector();
>        params.addElement(new Parameter("request",
> URL.class, url,
> null));
>        call.setParams(params);
> 
> 
> 
> Serializer
>
--------------------------------------------------------------------------------------------------------------
> 
> import java.net.URL;
> 
> public class URLSerializer implements Serializer
> {
> 
>   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);
> 
>       sink.write(StringUtils.lineSeparator);
> 
>       URL src2 = (URL) src;
> 
>       Parameter param;
> 
>       param = new Parameter("URL", String.class,
> src2.toString(), null);
> 
>       xjmr.marshall(inScopeEncStyle,
> Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
> 
>       sink.write("</" + context + ">");
> 
>       nsStack.popScope();
>   }
> }
> 
> 
> 
> Deserializer
>
--------------------------------------------------------------------------------------------------------------
> 
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle,
> QName elementType, Node
> src,
>                          XMLJavaMappingRegistry
> xjmr, SOAPContext ctx)
>                           throws
> IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl =
> DOMUtils.getFirstChildElement(root);
> 
>     URL url = null;
> 
>     while (tempEl != null)
>     {
>         Bean paramBean =
> xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl,
> ctx);
>         Parameter param =
> (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
> 
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL(
> (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new
> IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
> 
>         }
> 
>         tempEl =
> DOMUtils.getNextSiblingElement(tempEl);
>     }
> 
> 
>     return new Bean(URL.class, url);
>   }
> }
> 


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

RE: Serializers/Deserializers

Posted by Rajasekhar <ra...@deploy.com>.
Hi,

Why aren't you using the Serializer you have written to serialize your
class. I don't see the line below in your DD.

java2XMLClassName="examples.omnitide.SimpleURLService.URLSerializer"/>

Any specific reason?

- Raj.



> -----Original Message-----
> From: David Turner [mailto:turner@genome.wi.mit.edu]
> Sent: Thursday, October 25, 2001 10:12 AM
> To: soap-user@xml.apache.org
> Subject: Serializers/Deserializers
>
>
> Has anyone developed their own serializers & deserializers for their
> classes instead of using the BeanSerializer?
>
> I've attempted to write my own serializer/deserializer for the
> java.net.URL class in order to pass URL's to my service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String = org/apache/soap/util/xml/Deserializer
>
> I've attempted to write serializers/deserializers for a simple class
> also (class contains only Strings) instead of the BeanSerializer and I
> still get the above exception.
>
> Anybody know what's going wroing?  How do you set this up on both the
> client and server (deployment descr)?
>
> Below is the code:
>
> Deployment Descriptor
> ------------------------------------------------------------------
> --------------------------------------------
>
> <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
> class="examples.omnitide.SimpleURLService.SimpleURLService"
> static="false"/>
>   </isd:provider>
>
>
> <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:fa
ultListener>
>
>   <isd:mappings>
>     <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>              xmlns:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
>
> xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
>
>   </isd:mappings>
>
> </isd:service>
>
>
>
> Client that calls soap service
> ------------------------------------------------------------------
> --------------------------------------------
>
>       // Map the types
>        SOAPMappingRegistry smr = new SOAPMappingRegistry();
>
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
>
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
>
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>        call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
>
>        Vector params = new Vector();
>        params.addElement(new Parameter("request", URL.class, url,
> null));
>        call.setParams(params);
>
>
>
> Serializer
> ------------------------------------------------------------------
> --------------------------------------------
>
> import java.net.URL;
>
> public class URLSerializer implements Serializer
> {
>
>   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);
>
>       sink.write(StringUtils.lineSeparator);
>
>       URL src2 = (URL) src;
>
>       Parameter param;
>
>       param = new Parameter("URL", String.class, src2.toString(), null);
>
>       xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
>
>       sink.write("</" + context + ">");
>
>       nsStack.popScope();
>   }
> }
>
>
>
> Deserializer
> ------------------------------------------------------------------
> --------------------------------------------
>
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
> src,
>                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
>                           throws IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl = DOMUtils.getFirstChildElement(root);
>
>     URL url = null;
>
>     while (tempEl != null)
>     {
>         Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl, ctx);
>         Parameter param = (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
>
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL( (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
>
>         }
>
>         tempEl = DOMUtils.getNextSiblingElement(tempEl);
>     }
>
>
>     return new Bean(URL.class, url);
>   }
> }
>


RE: Serializers/Deserializers

Posted by "Hung D. Viet" <di...@epiqus.com>.
This error seems that SOAP doesn't recorgnized your deserializer.

I have noticed you didn't declared properly the namespace for your
deserializer in deployment descriptor.

In client code, you registered:

<quote>
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
                new QName("urn:SimpleURLService", "URL"), URL.class, ser,
des);
</quote>

Hence in DD file, you should have the same namespace. Instead of using
namespace "http://www.w3.org/1999/XMLSchema", you should the namespace you
registered in client code, which is "urn:SimpleURLService".

It means, in your DD file, instead of:
     xmlns:xsd="http://www.w3.org/1999/XMLSchema" qname="xsd:URL"
You should change to:
     xmlns:xsd="urn:SimpleURLService" qname="xsd:URL"


That may get rid of the Deserializer error :-)

cheers,
Hung











-----Original Message-----
From: David Turner [mailto:turner@genome.wi.mit.edu]
Sent: Thursday, October 25, 2001 10:12 PM
To: soap-user@xml.apache.org
Subject: Serializers/Deserializers


Has anyone developed their own serializers & deserializers for their
classes instead of using the BeanSerializer?

I've attempted to write my own serializer/deserializer for the
java.net.URL class in order to pass URL's to my service method, but the
server sends back a fault:
      Fault Code = SOAP-ENV:Server.Exception:
      Fault String = org/apache/soap/util/xml/Deserializer

I've attempted to write serializers/deserializers for a simple class
also (class contains only Strings) instead of the BeanSerializer and I
still get the above exception.

Anybody know what's going wroing?  How do you set this up on both the
client and server (deployment descr)?

Below is the code:

Deployment Descriptor
----------------------------------------------------------------------------
----------------------------------

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:SimpleURLService">
  <isd:provider type="java"
                scope="Session"
                methods="serviceMethod">
    <isd:java
class="examples.omnitide.SimpleURLService.SimpleURLService"
static="false"/>
  </isd:provider>


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

  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:xsd="http://www.w3.org/1999/XMLSchema"
qname="xsd:URL"
             javaType="java.net.URL"

xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>

  </isd:mappings>

</isd:service>



Client that calls soap service
----------------------------------------------------------------------------
----------------------------------

      // Map the types
       SOAPMappingRegistry smr = new SOAPMappingRegistry();

       URLSerializer ser = new URLSerializer();
       URLDeserializer des = new URLDeserializer();

       smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
QName("urn:SimpleURLService", "URL"),
           URL.class, ser, des);

       // Build the call
       Call call = new Call();
       call.setSOAPMappingRegistry(smr);
       call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
       call.setTargetObjectURI("urn:SimpleURLService");
       call.setMethodName("serviceMethod");

       Vector params = new Vector();
       params.addElement(new Parameter("request", URL.class, url,
null));
       call.setParams(params);



Serializer
----------------------------------------------------------------------------
----------------------------------

import java.net.URL;

public class URLSerializer implements Serializer
{

  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);

      sink.write(StringUtils.lineSeparator);

      URL src2 = (URL) src;

      Parameter param;

      param = new Parameter("URL", String.class, src2.toString(), null);

      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
                    sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);

      sink.write("</" + context + ">");

      nsStack.popScope();
  }
}



Deserializer
----------------------------------------------------------------------------
----------------------------------

public class URLDeserializer implements Deserializer
{
  public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
src,
                         XMLJavaMappingRegistry xjmr, SOAPContext ctx)
                          throws IllegalArgumentException
  {
    Element root = (Element)src;
    Element tempEl = DOMUtils.getFirstChildElement(root);

    URL url = null;

    while (tempEl != null)
    {
        Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
RPCConstants.Q_ELEM_PARAMETER,
                                         tempEl, ctx);
        Parameter param = (Parameter)paramBean.value;
        String tagName = tempEl.getTagName();

        if (tagName.equals("URL"))
        {
            try
            {
                url = new URL( (String)param.getValue() );
            }
            catch (Exception e)
            {
                throw new IllegalArgumentException("Problem
instantianting bean: " + e.getMessage());
            }

        }

        tempEl = DOMUtils.getNextSiblingElement(tempEl);
    }


    return new Bean(URL.class, url);
  }
}


Re: Serializers/Deserializers

Posted by k young <yo...@yahoo.com>.
Have you tried send the URL as a java.lang.String? 
You could reconstruct the URL on the otherside.


--- David Turner <tu...@genome.wi.mit.edu> wrote:
> Has anyone developed their own serializers &
> deserializers for their
> classes instead of using the BeanSerializer?
> 
> I've attempted to write my own
> serializer/deserializer for the
> java.net.URL class in order to pass URL's to my
> service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String =
> org/apache/soap/util/xml/Deserializer
> 
> I've attempted to write serializers/deserializers
> for a simple class
> also (class contains only Strings) instead of the
> BeanSerializer and I
> still get the above exception.
> 
> Anybody know what's going wroing?  How do you set
> this up on both the
> client and server (deployment descr)?
> 
> Below is the code:
> 
> Deployment Descriptor
>
--------------------------------------------------------------------------------------------------------------
> 
> <isd:service
>
xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
>
class="examples.omnitide.SimpleURLService.SimpleURLService"
> 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:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
> 
>
xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
> 
>   </isd:mappings>
> 
> </isd:service>
> 
> 
> 
> Client that calls soap service
>
--------------------------------------------------------------------------------------------------------------
> 
>       // Map the types
>        SOAPMappingRegistry smr = new
> SOAPMappingRegistry();
> 
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
> 
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
> 
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>       
> call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>       
> call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
> 
>        Vector params = new Vector();
>        params.addElement(new Parameter("request",
> URL.class, url,
> null));
>        call.setParams(params);
> 
> 
> 
> Serializer
>
--------------------------------------------------------------------------------------------------------------
> 
> import java.net.URL;
> 
> public class URLSerializer implements Serializer
> {
> 
>   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);
> 
>       sink.write(StringUtils.lineSeparator);
> 
>       URL src2 = (URL) src;
> 
>       Parameter param;
> 
>       param = new Parameter("URL", String.class,
> src2.toString(), null);
> 
>       xjmr.marshall(inScopeEncStyle,
> Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
> 
>       sink.write("</" + context + ">");
> 
>       nsStack.popScope();
>   }
> }
> 
> 
> 
> Deserializer
>
--------------------------------------------------------------------------------------------------------------
> 
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle,
> QName elementType, Node
> src,
>                          XMLJavaMappingRegistry
> xjmr, SOAPContext ctx)
>                           throws
> IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl =
> DOMUtils.getFirstChildElement(root);
> 
>     URL url = null;
> 
>     while (tempEl != null)
>     {
>         Bean paramBean =
> xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl,
> ctx);
>         Parameter param =
> (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
> 
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL(
> (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new
> IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
> 
>         }
> 
>         tempEl =
> DOMUtils.getNextSiblingElement(tempEl);
>     }
> 
> 
>     return new Bean(URL.class, url);
>   }
> }
> 


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

RE: Serializers/Deserializers

Posted by "Hung D. Viet" <di...@epiqus.com>.
This error seems that SOAP doesn't recorgnized your deserializer.

I have noticed you didn't declared properly the namespace for your
deserializer in deployment descriptor.

In client code, you registered:

<quote>
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
                new QName("urn:SimpleURLService", "URL"), URL.class, ser,
des);
</quote>

Hence in DD file, you should have the same namespace. Instead of using
namespace "http://www.w3.org/1999/XMLSchema", you should the namespace you
registered in client code, which is "urn:SimpleURLService".

It means, in your DD file, instead of:
     xmlns:xsd="http://www.w3.org/1999/XMLSchema" qname="xsd:URL"
You should change to:
     xmlns:xsd="urn:SimpleURLService" qname="xsd:URL"


That may get rid of the Deserializer error :-)

cheers,
Hung











-----Original Message-----
From: David Turner [mailto:turner@genome.wi.mit.edu]
Sent: Thursday, October 25, 2001 10:12 PM
To: soap-user@xml.apache.org
Subject: Serializers/Deserializers


Has anyone developed their own serializers & deserializers for their
classes instead of using the BeanSerializer?

I've attempted to write my own serializer/deserializer for the
java.net.URL class in order to pass URL's to my service method, but the
server sends back a fault:
      Fault Code = SOAP-ENV:Server.Exception:
      Fault String = org/apache/soap/util/xml/Deserializer

I've attempted to write serializers/deserializers for a simple class
also (class contains only Strings) instead of the BeanSerializer and I
still get the above exception.

Anybody know what's going wroing?  How do you set this up on both the
client and server (deployment descr)?

Below is the code:

Deployment Descriptor
----------------------------------------------------------------------------
----------------------------------

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
             id="urn:SimpleURLService">
  <isd:provider type="java"
                scope="Session"
                methods="serviceMethod">
    <isd:java
class="examples.omnitide.SimpleURLService.SimpleURLService"
static="false"/>
  </isd:provider>


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

  <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:xsd="http://www.w3.org/1999/XMLSchema"
qname="xsd:URL"
             javaType="java.net.URL"

xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>

  </isd:mappings>

</isd:service>



Client that calls soap service
----------------------------------------------------------------------------
----------------------------------

      // Map the types
       SOAPMappingRegistry smr = new SOAPMappingRegistry();

       URLSerializer ser = new URLSerializer();
       URLDeserializer des = new URLDeserializer();

       smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
QName("urn:SimpleURLService", "URL"),
           URL.class, ser, des);

       // Build the call
       Call call = new Call();
       call.setSOAPMappingRegistry(smr);
       call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
       call.setTargetObjectURI("urn:SimpleURLService");
       call.setMethodName("serviceMethod");

       Vector params = new Vector();
       params.addElement(new Parameter("request", URL.class, url,
null));
       call.setParams(params);



Serializer
----------------------------------------------------------------------------
----------------------------------

import java.net.URL;

public class URLSerializer implements Serializer
{

  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);

      sink.write(StringUtils.lineSeparator);

      URL src2 = (URL) src;

      Parameter param;

      param = new Parameter("URL", String.class, src2.toString(), null);

      xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
                    sink, nsStack, ctx);
      sink.write(StringUtils.lineSeparator);

      sink.write("</" + context + ">");

      nsStack.popScope();
  }
}



Deserializer
----------------------------------------------------------------------------
----------------------------------

public class URLDeserializer implements Deserializer
{
  public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
src,
                         XMLJavaMappingRegistry xjmr, SOAPContext ctx)
                          throws IllegalArgumentException
  {
    Element root = (Element)src;
    Element tempEl = DOMUtils.getFirstChildElement(root);

    URL url = null;

    while (tempEl != null)
    {
        Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
RPCConstants.Q_ELEM_PARAMETER,
                                         tempEl, ctx);
        Parameter param = (Parameter)paramBean.value;
        String tagName = tempEl.getTagName();

        if (tagName.equals("URL"))
        {
            try
            {
                url = new URL( (String)param.getValue() );
            }
            catch (Exception e)
            {
                throw new IllegalArgumentException("Problem
instantianting bean: " + e.getMessage());
            }

        }

        tempEl = DOMUtils.getNextSiblingElement(tempEl);
    }


    return new Bean(URL.class, url);
  }
}


RE: Serializers/Deserializers

Posted by Rajasekhar <ra...@deploy.com>.
Hi,

Why aren't you using the Serializer you have written to serialize your
class. I don't see the line below in your DD.

java2XMLClassName="examples.omnitide.SimpleURLService.URLSerializer"/>

Any specific reason?

- Raj.



> -----Original Message-----
> From: David Turner [mailto:turner@genome.wi.mit.edu]
> Sent: Thursday, October 25, 2001 10:12 AM
> To: soap-user@xml.apache.org
> Subject: Serializers/Deserializers
>
>
> Has anyone developed their own serializers & deserializers for their
> classes instead of using the BeanSerializer?
>
> I've attempted to write my own serializer/deserializer for the
> java.net.URL class in order to pass URL's to my service method, but the
> server sends back a fault:
>       Fault Code = SOAP-ENV:Server.Exception:
>       Fault String = org/apache/soap/util/xml/Deserializer
>
> I've attempted to write serializers/deserializers for a simple class
> also (class contains only Strings) instead of the BeanSerializer and I
> still get the above exception.
>
> Anybody know what's going wroing?  How do you set this up on both the
> client and server (deployment descr)?
>
> Below is the code:
>
> Deployment Descriptor
> ------------------------------------------------------------------
> --------------------------------------------
>
> <isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
>              id="urn:SimpleURLService">
>   <isd:provider type="java"
>                 scope="Session"
>                 methods="serviceMethod">
>     <isd:java
> class="examples.omnitide.SimpleURLService.SimpleURLService"
> static="false"/>
>   </isd:provider>
>
>
> <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:fa
ultListener>
>
>   <isd:mappings>
>     <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>              xmlns:xsd="http://www.w3.org/1999/XMLSchema"
> qname="xsd:URL"
>              javaType="java.net.URL"
>
> xml2JavaClassName="examples.omnitide.SimpleURLService.URLDeserializer"/>
>
>   </isd:mappings>
>
> </isd:service>
>
>
>
> Client that calls soap service
> ------------------------------------------------------------------
> --------------------------------------------
>
>       // Map the types
>        SOAPMappingRegistry smr = new SOAPMappingRegistry();
>
>        URLSerializer ser = new URLSerializer();
>        URLDeserializer des = new URLDeserializer();
>
>        smr.mapTypes(Constants.NS_URI_SOAP_ENC, new
> QName("urn:SimpleURLService", "URL"),
>            URL.class, ser, des);
>
>        // Build the call
>        Call call = new Call();
>        call.setSOAPMappingRegistry(smr);
>        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
>        call.setTargetObjectURI("urn:SimpleURLService");
>        call.setMethodName("serviceMethod");
>
>        Vector params = new Vector();
>        params.addElement(new Parameter("request", URL.class, url,
> null));
>        call.setParams(params);
>
>
>
> Serializer
> ------------------------------------------------------------------
> --------------------------------------------
>
> import java.net.URL;
>
> public class URLSerializer implements Serializer
> {
>
>   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);
>
>       sink.write(StringUtils.lineSeparator);
>
>       URL src2 = (URL) src;
>
>       Parameter param;
>
>       param = new Parameter("URL", String.class, src2.toString(), null);
>
>       xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
>                     sink, nsStack, ctx);
>       sink.write(StringUtils.lineSeparator);
>
>       sink.write("</" + context + ">");
>
>       nsStack.popScope();
>   }
> }
>
>
>
> Deserializer
> ------------------------------------------------------------------
> --------------------------------------------
>
> public class URLDeserializer implements Deserializer
> {
>   public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
> src,
>                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
>                           throws IllegalArgumentException
>   {
>     Element root = (Element)src;
>     Element tempEl = DOMUtils.getFirstChildElement(root);
>
>     URL url = null;
>
>     while (tempEl != null)
>     {
>         Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
> RPCConstants.Q_ELEM_PARAMETER,
>                                          tempEl, ctx);
>         Parameter param = (Parameter)paramBean.value;
>         String tagName = tempEl.getTagName();
>
>         if (tagName.equals("URL"))
>         {
>             try
>             {
>                 url = new URL( (String)param.getValue() );
>             }
>             catch (Exception e)
>             {
>                 throw new IllegalArgumentException("Problem
> instantianting bean: " + e.getMessage());
>             }
>
>         }
>
>         tempEl = DOMUtils.getNextSiblingElement(tempEl);
>     }
>
>
>     return new Bean(URL.class, url);
>   }
> }
>