You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by "Todd D. Johnson" <to...@amadeustechnology.com> on 2002/06/10 02:06:57 UTC

Problems with Serializers/Deserializers

I am using the following environment
	java 1.4
	Tomcat 4.0.3
	Soap 2.3

I have written a simple class that implements not only the class functions,
but the serialization and deserialization as well.  I am having problems
calling a simple function on the class that returns itself.  Right now the
class has only one member (a string) and thus the marshall and unmarshall
functions are responsible for handling just that member.  When a client
calls the function, apache tomcat loads the constructor, calls the function,
but never calls the marshall function (as reported through the apache
console).  The only thing returned to the client is

	Fault Code = SOAP-ENV:Server
	Fault String = java.lang.NullPointerException

Does anyone have any ideas?  I've gotten the simple soap examples to run
just fine.  (And subsequently my code and descriptor are pretty identical)
Could this be problem with implementing the serializer and deserializer in
my class??

Thanks,

Todd D. Johnson

President
Salar, Inc.
2400 Boston St.
Suite 350
Baltimore, MD 21224

410.327.9153 x 3 PH
410.327.4086 FAX

todd@salarinc.com
www.salarinc.com


RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
I apologize for teh duplicate post (typing error)...

Xerces tends to be a growing problem on my system.  It seems every piece of
software I install these days installs a newer version of xerces.  I am,
however, pointing to xerces 1.4.4 in the classpath in the tomcat script (and
have verified that xerces is not in my jre ext dir).  I attached the code to
the bottom of this email.

todd

-----Original Message-----
From: Henk Schipper [mailto:henk.schipper@software684.com]
Sent: Monday, June 10, 2002 10:18 AM
To: soap-dev@xml.apache.org
Subject: RE: Problems with Serializers/Deserializers


Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>


Implementing server class:

    public Guide getSampleGuide(int guideSeq){
		System.out.println("Guide.getSampleGuide called");
        setGuideName("Sample Tickler Guide");
        //g.setGuideType("DefaultGuidePublishingAgentImpl");
        System.out.println("Guide.getSampleGuide exiting");
        return this;
    }

DeploymentDescriptor:

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:tickler">
     <isd:provider type="java" scope="Request" methods="getSampleGuide">
        <isd:java class="com.salarinc.tickler.foundation.Guide"
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:x="urn:tickler-guide" qname="x:guide"
                  javaType="com.salarinc.tickler.foundation.Guide"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

Client code:

Integer x=new Integer(7);
        Integer y=new Integer(8);
        final String urn= "urn:tickler";

        Vector params = new Vector();

        URL url = null;
        try{
            url = new URL("http://" + serverhost + ":" + serverport+
soapservlet);
        }catch(java.net.MalformedURLException e){
            System.out.println("Error creating a url: "+e.getMessage());
        }

        ServiceManagerClient client = new ServiceManagerClient(url);
        try{
            String[] apps = client.list();
            System.out.println("Deployed Services at "+url.toString()+"
are:");
            for(int i = 0; i < apps.length; i++){
                System.out.println("\t"+apps[i]);
                DeploymentDescriptor desc = client.query(apps[i]);
                System.out.println("\t\tMethods for
"+desc.getScriptFilenameOrString()+" are:");
                String[] methods = desc.getMethods();
                for(int j = 0; j < methods.length; j++){
                    System.out.println("\t\t\t"+methods[j]);
                }
            }
        }catch(SOAPException e){
            System.out.println("Could not connect to ServiceManager at
"+url.toString()+": "+e.getMessage());
        }

        // Build the call.
		Call call = new Call();
		SOAPHTTPConnection shc = new SOAPHTTPConnection ();
	    shc.setMaintainSession (true);
	    call.setSOAPTransport(shc);
        call.setTargetObjectURI(urn);

call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");

        call.setMethodName("getSampleGuide");

        params.addElement(new Parameter("guideSeq" , Integer.class,  new
Integer(7), null));

        call.setParams(params);
        GuideSerializer ser_0 = new GuideSerializer();
        SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
		smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
		      "urn:tickler-guide", "guide"), Guide.class, ser_0, ser_0);
	  call.setSOAPMappingRegistry(smr);
        Response resp = null;
        try{
            resp = call.invoke(url,"");
        }catch(org.apache.soap.SOAPException e){
            System.out.println("Got a soap exception while invoking
"+e.getMessage());
            System.exit(1);
        }

        if (resp.generatedFault()) {
            Fault fault = resp.getFault();
            System.out.println("Ouch, the call failed: ");
            System.out.println("  Fault Code   = " + fault.getFaultCode());
            System.out.println("  Fault String = " +
fault.getFaultString());
        } else {
            Parameter result = resp.getReturnValue();
            if(result.getType() == Guide.class){
                Guide g = (Guide)result.getValue();
                System.out.println("The guide name is " + g.getGuideName());
            }else{
                System.out.println("ERROR server returned a
:"+result.getType().toString());
                System.exit(1);
            }

        }

Serializer/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);
   	    Guide target;

   	    try
   	    {
   	      target =
   	        (Guide)Guide.class.newInstance
   	        ();
   	    }
   	    catch (Exception e)
   	    {
   	      throw new IllegalArgumentException("Problem instantiating bean: "
   	        + e.getMessage());
   	    }

   	    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("name"))
   	      {
   	        target.setGuideName((java.lang.String)param.getValue());
   	      }

   	      tempEl = DOMUtils.getNextSiblingElement(tempEl);
   	    }

   	    return new Bean(Guide.class, target);
     	}

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

   		Guide src2 = (Guide)src;
   		Parameter param;

   		param = new Parameter("namme", String.class, new String
   		  ("Test"), null);
   		xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
   		sink, nsStack, ctx);
   		sink.write(StringUtils.lineSeparator);

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

       nsStack.popScope();
    }





RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
Xerces tends to be a growing problem on my system.  It seems every piece of
software I install these days installs a newer version of xerces.  I am,
however, pointing to xerces 1.4.4 in the classpath in the tomcat script (and
have verified that xerces is not in my jre ext dir).  I attached the

-----Original Message-----
From: Henk Schipper [mailto:henk.schipper@software684.com]
Sent: Monday, June 10, 2002 10:18 AM
To: soap-dev@xml.apache.org
Subject: RE: Problems with Serializers/Deserializers


Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>






RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
Xerces tends to be a growing problem on my system.  It seems every piece of
software I install these days installs a newer version of xerces.  I am,
however, pointing to xerces 1.4.4 in the classpath in the tomcat script (and
have verified that xerces is not in my jre ext dir).  I attached the

-----Original Message-----
From: Henk Schipper [mailto:henk.schipper@software684.com]
Sent: Monday, June 10, 2002 10:18 AM
To: soap-dev@xml.apache.org
Subject: RE: Problems with Serializers/Deserializers


Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>






RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
I apologize for teh duplicate post (typing error)...

Xerces tends to be a growing problem on my system.  It seems every piece of
software I install these days installs a newer version of xerces.  I am,
however, pointing to xerces 1.4.4 in the classpath in the tomcat script (and
have verified that xerces is not in my jre ext dir).  I attached the code to
the bottom of this email.

todd

-----Original Message-----
From: Henk Schipper [mailto:henk.schipper@software684.com]
Sent: Monday, June 10, 2002 10:18 AM
To: soap-dev@xml.apache.org
Subject: RE: Problems with Serializers/Deserializers


Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>


Implementing server class:

    public Guide getSampleGuide(int guideSeq){
		System.out.println("Guide.getSampleGuide called");
        setGuideName("Sample Tickler Guide");
        //g.setGuideType("DefaultGuidePublishingAgentImpl");
        System.out.println("Guide.getSampleGuide exiting");
        return this;
    }

DeploymentDescriptor:

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:tickler">
     <isd:provider type="java" scope="Request" methods="getSampleGuide">
        <isd:java class="com.salarinc.tickler.foundation.Guide"
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:x="urn:tickler-guide" qname="x:guide"
                  javaType="com.salarinc.tickler.foundation.Guide"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

Client code:

Integer x=new Integer(7);
        Integer y=new Integer(8);
        final String urn= "urn:tickler";

        Vector params = new Vector();

        URL url = null;
        try{
            url = new URL("http://" + serverhost + ":" + serverport+
soapservlet);
        }catch(java.net.MalformedURLException e){
            System.out.println("Error creating a url: "+e.getMessage());
        }

        ServiceManagerClient client = new ServiceManagerClient(url);
        try{
            String[] apps = client.list();
            System.out.println("Deployed Services at "+url.toString()+"
are:");
            for(int i = 0; i < apps.length; i++){
                System.out.println("\t"+apps[i]);
                DeploymentDescriptor desc = client.query(apps[i]);
                System.out.println("\t\tMethods for
"+desc.getScriptFilenameOrString()+" are:");
                String[] methods = desc.getMethods();
                for(int j = 0; j < methods.length; j++){
                    System.out.println("\t\t\t"+methods[j]);
                }
            }
        }catch(SOAPException e){
            System.out.println("Could not connect to ServiceManager at
"+url.toString()+": "+e.getMessage());
        }

        // Build the call.
		Call call = new Call();
		SOAPHTTPConnection shc = new SOAPHTTPConnection ();
	    shc.setMaintainSession (true);
	    call.setSOAPTransport(shc);
        call.setTargetObjectURI(urn);

call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");

        call.setMethodName("getSampleGuide");

        params.addElement(new Parameter("guideSeq" , Integer.class,  new
Integer(7), null));

        call.setParams(params);
        GuideSerializer ser_0 = new GuideSerializer();
        SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
		smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
		      "urn:tickler-guide", "guide"), Guide.class, ser_0, ser_0);
	  call.setSOAPMappingRegistry(smr);
        Response resp = null;
        try{
            resp = call.invoke(url,"");
        }catch(org.apache.soap.SOAPException e){
            System.out.println("Got a soap exception while invoking
"+e.getMessage());
            System.exit(1);
        }

        if (resp.generatedFault()) {
            Fault fault = resp.getFault();
            System.out.println("Ouch, the call failed: ");
            System.out.println("  Fault Code   = " + fault.getFaultCode());
            System.out.println("  Fault String = " +
fault.getFaultString());
        } else {
            Parameter result = resp.getReturnValue();
            if(result.getType() == Guide.class){
                Guide g = (Guide)result.getValue();
                System.out.println("The guide name is " + g.getGuideName());
            }else{
                System.out.println("ERROR server returned a
:"+result.getType().toString());
                System.exit(1);
            }

        }

Serializer/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);
   	    Guide target;

   	    try
   	    {
   	      target =
   	        (Guide)Guide.class.newInstance
   	        ();
   	    }
   	    catch (Exception e)
   	    {
   	      throw new IllegalArgumentException("Problem instantiating bean: "
   	        + e.getMessage());
   	    }

   	    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("name"))
   	      {
   	        target.setGuideName((java.lang.String)param.getValue());
   	      }

   	      tempEl = DOMUtils.getNextSiblingElement(tempEl);
   	    }

   	    return new Bean(Guide.class, target);
     	}

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

   		Guide src2 = (Guide)src;
   		Parameter param;

   		param = new Parameter("namme", String.class, new String
   		  ("Test"), null);
   		xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
   		sink, nsStack, ctx);
   		sink.write(StringUtils.lineSeparator);

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

       nsStack.popScope();
    }





RE: Problems with Serializers/Deserializers

Posted by Henk Schipper <he...@software684.com>.
Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>




RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
I've now attached the code.  I've also read that this might be a classloader
or xml parser issue.   Any help would be great.   thanks

> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> The server is failing on line 138 of RPCRouterServlet.  Could it be having
problems loading the class that implements the serializer/deserializer?
>
> Thanks,
>
> Todd D. Johnson
>

Implementing server class:

    public Guide getSampleGuide(int guideSeq){
		System.out.println("Guide.getSampleGuide called");
        setGuideName("Sample Tickler Guide");
        //g.setGuideType("DefaultGuidePublishingAgentImpl");
        System.out.println("Guide.getSampleGuide exiting");
        return this;
    }

DeploymentDescriptor:

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:tickler">
     <isd:provider type="java" scope="Request" methods="getSampleGuide">
        <isd:java class="com.salarinc.tickler.foundation.Guide"
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:x="urn:tickler-guide" qname="x:guide"
                  javaType="com.salarinc.tickler.foundation.Guide"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

Client code:

Integer x=new Integer(7);
        Integer y=new Integer(8);
        final String urn= "urn:tickler";

        Vector params = new Vector();

        URL url = null;
        try{
            url = new URL("http://" + serverhost + ":" + serverport+
soapservlet);
        }catch(java.net.MalformedURLException e){
            System.out.println("Error creating a url: "+e.getMessage());
        }

        ServiceManagerClient client = new ServiceManagerClient(url);
        try{
            String[] apps = client.list();
            System.out.println("Deployed Services at "+url.toString()+"
are:");
            for(int i = 0; i < apps.length; i++){
                System.out.println("\t"+apps[i]);
                DeploymentDescriptor desc = client.query(apps[i]);
                System.out.println("\t\tMethods for
"+desc.getScriptFilenameOrString()+" are:");
                String[] methods = desc.getMethods();
                for(int j = 0; j < methods.length; j++){
                    System.out.println("\t\t\t"+methods[j]);
                }
            }
        }catch(SOAPException e){
            System.out.println("Could not connect to ServiceManager at
"+url.toString()+": "+e.getMessage());
        }

        // Build the call.
		Call call = new Call();
		SOAPHTTPConnection shc = new SOAPHTTPConnection ();
	    shc.setMaintainSession (true);
	    call.setSOAPTransport(shc);
        call.setTargetObjectURI(urn);

call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");

        call.setMethodName("getSampleGuide");

        params.addElement(new Parameter("guideSeq" , Integer.class,  new
Integer(7), null));

        call.setParams(params);
        GuideSerializer ser_0 = new GuideSerializer();
        SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
		smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
		      "urn:tickler-guide", "guide"), Guide.class, ser_0, ser_0);
	  call.setSOAPMappingRegistry(smr);
        Response resp = null;
        try{
            resp = call.invoke(url,"");
        }catch(org.apache.soap.SOAPException e){
            System.out.println("Got a soap exception while invoking
"+e.getMessage());
            System.exit(1);
        }

        if (resp.generatedFault()) {
            Fault fault = resp.getFault();
            System.out.println("Ouch, the call failed: ");
            System.out.println("  Fault Code   = " + fault.getFaultCode());
            System.out.println("  Fault String = " +
fault.getFaultString());
        } else {
            Parameter result = resp.getReturnValue();
            if(result.getType() == Guide.class){
                Guide g = (Guide)result.getValue();
                System.out.println("The guide name is " + g.getGuideName());
            }else{
                System.out.println("ERROR server returned a
:"+result.getType().toString());
                System.exit(1);
            }

        }

Serializer/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);
   	    Guide target;

   	    try
   	    {
   	      target =
   	        (Guide)Guide.class.newInstance
   	        ();
   	    }
   	    catch (Exception e)
   	    {
   	      throw new IllegalArgumentException("Problem instantiating bean: "
   	        + e.getMessage());
   	    }

   	    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("name"))
   	      {
   	        target.setGuideName((java.lang.String)param.getValue());
   	      }

   	      tempEl = DOMUtils.getNextSiblingElement(tempEl);
   	    }

   	    return new Bean(Guide.class, target);
     	}

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

   		Guide src2 = (Guide)src;
   		Parameter param;

   		param = new Parameter("namme", String.class, new String
   		  ("Test"), null);
   		xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
   		sink, nsStack, ctx);
   		sink.write(StringUtils.lineSeparator);

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

       nsStack.popScope();
    }


RE: Problems with Serializers/Deserializers

Posted by "Todd D. Johnson" <to...@salarinc.com>.
I've now attached the code.  I've also read that this might be a classloader
or xml parser issue.   Any help would be great.   thanks

> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> The server is failing on line 138 of RPCRouterServlet.  Could it be having
problems loading the class that implements the serializer/deserializer?
>
> Thanks,
>
> Todd D. Johnson
>

Implementing server class:

    public Guide getSampleGuide(int guideSeq){
		System.out.println("Guide.getSampleGuide called");
        setGuideName("Sample Tickler Guide");
        //g.setGuideType("DefaultGuidePublishingAgentImpl");
        System.out.println("Guide.getSampleGuide exiting");
        return this;
    }

DeploymentDescriptor:

<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:tickler">
     <isd:provider type="java" scope="Request" methods="getSampleGuide">
        <isd:java class="com.salarinc.tickler.foundation.Guide"
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:x="urn:tickler-guide" qname="x:guide"
                  javaType="com.salarinc.tickler.foundation.Guide"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
  </isd:mappings>
</isd:service>

Client code:

Integer x=new Integer(7);
        Integer y=new Integer(8);
        final String urn= "urn:tickler";

        Vector params = new Vector();

        URL url = null;
        try{
            url = new URL("http://" + serverhost + ":" + serverport+
soapservlet);
        }catch(java.net.MalformedURLException e){
            System.out.println("Error creating a url: "+e.getMessage());
        }

        ServiceManagerClient client = new ServiceManagerClient(url);
        try{
            String[] apps = client.list();
            System.out.println("Deployed Services at "+url.toString()+"
are:");
            for(int i = 0; i < apps.length; i++){
                System.out.println("\t"+apps[i]);
                DeploymentDescriptor desc = client.query(apps[i]);
                System.out.println("\t\tMethods for
"+desc.getScriptFilenameOrString()+" are:");
                String[] methods = desc.getMethods();
                for(int j = 0; j < methods.length; j++){
                    System.out.println("\t\t\t"+methods[j]);
                }
            }
        }catch(SOAPException e){
            System.out.println("Could not connect to ServiceManager at
"+url.toString()+": "+e.getMessage());
        }

        // Build the call.
		Call call = new Call();
		SOAPHTTPConnection shc = new SOAPHTTPConnection ();
	    shc.setMaintainSession (true);
	    call.setSOAPTransport(shc);
        call.setTargetObjectURI(urn);

call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");

        call.setMethodName("getSampleGuide");

        params.addElement(new Parameter("guideSeq" , Integer.class,  new
Integer(7), null));

        call.setParams(params);
        GuideSerializer ser_0 = new GuideSerializer();
        SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
		smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
		      "urn:tickler-guide", "guide"), Guide.class, ser_0, ser_0);
	  call.setSOAPMappingRegistry(smr);
        Response resp = null;
        try{
            resp = call.invoke(url,"");
        }catch(org.apache.soap.SOAPException e){
            System.out.println("Got a soap exception while invoking
"+e.getMessage());
            System.exit(1);
        }

        if (resp.generatedFault()) {
            Fault fault = resp.getFault();
            System.out.println("Ouch, the call failed: ");
            System.out.println("  Fault Code   = " + fault.getFaultCode());
            System.out.println("  Fault String = " +
fault.getFaultString());
        } else {
            Parameter result = resp.getReturnValue();
            if(result.getType() == Guide.class){
                Guide g = (Guide)result.getValue();
                System.out.println("The guide name is " + g.getGuideName());
            }else{
                System.out.println("ERROR server returned a
:"+result.getType().toString());
                System.exit(1);
            }

        }

Serializer/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);
   	    Guide target;

   	    try
   	    {
   	      target =
   	        (Guide)Guide.class.newInstance
   	        ();
   	    }
   	    catch (Exception e)
   	    {
   	      throw new IllegalArgumentException("Problem instantiating bean: "
   	        + e.getMessage());
   	    }

   	    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("name"))
   	      {
   	        target.setGuideName((java.lang.String)param.getValue());
   	      }

   	      tempEl = DOMUtils.getNextSiblingElement(tempEl);
   	    }

   	    return new Bean(Guide.class, target);
     	}

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

   		Guide src2 = (Guide)src;
   		Parameter param;

   		param = new Parameter("namme", String.class, new String
   		  ("Test"), null);
   		xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
   		sink, nsStack, ctx);
   		sink.write(StringUtils.lineSeparator);

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

       nsStack.popScope();
    }


RE: Problems with Serializers/Deserializers

Posted by Henk Schipper <he...@software684.com>.
Todd,

Place than also the definition for the deploiment.
We all can have a look.
Question: Are you using xerces? if so, which version?

Greetz,

Henk Schipper.

-----Original Message-----
From: Scott Nichol [mailto:snicholnews@scottnichol.com]
Sent: Monday, 10 June, 2002 4:05 PM
To: soap-dev@xml.apache.org
Subject: Re: Problems with Serializers/Deserializers


Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>




Re: Problems with Serializers/Deserializers

Posted by Scott Nichol <sn...@scottnichol.com>.
Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>


Re: Problems with Serializers/Deserializers

Posted by Scott Nichol <sn...@scottnichol.com>.
Todd,

If you can post the code to this list, someone may be able to track down the
problem.

Scott Nichol

----- Original Message -----
From: "Todd D. Johnson" <to...@amadeustechnology.com>
To: <so...@xml.apache.org>
Sent: Sunday, June 09, 2002 8:06 PM
Subject: Problems with Serializers/Deserializers


> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class functions,
> but the serialization and deserialization as well.  I am having problems
> calling a simple function on the class that returns itself.  Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member.  When a client
> calls the function, apache tomcat loads the constructor, calls the function,
> but never calls the marshall function (as reported through the apache
> console).  The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas?  I've gotten the simple soap examples to run
> just fine.  (And subsequently my code and descriptor are pretty identical)
> Could this be problem with implementing the serializer and deserializer in
> my class??
>
> Thanks,
>
> Todd D. Johnson
>
> President
> Salar, Inc.
> 2400 Boston St.
> Suite 350
> Baltimore, MD 21224
>
> 410.327.9153 x 3 PH
> 410.327.4086 FAX
>
> todd@salarinc.com
> www.salarinc.com
>
>