Vaishakhi,

Are you using a new version of Axis and perhaps are your fields public?

I see from the original error message that the problem was with field
"password" and your bean accessors are (apparently) setPasswd and
getPasswd.   So if "password" is sent over the wire and the bean property
is "passwd" the 'old' Axis code would fail.

I made a change (about two weeks ago) that would improve deserialization
processing by considering public fields.  Which may be the reason why your
code is now working.

Please consider doing the following:
   * Use private implementation fields if you have public accessors.
   * Make sure to name your accessors to be consistent with the name passed
over the wire.  For example setPassword and getPassword will default to
passing "password" over the wire.
   * Consider generating the initial bean classes using WSDL2Java.

Hope this answers your questions.  Thanks for using Axis.

Rich Scheuerle
XML & Web Services Development
512-838-5115  (IBM TL 678-5115)


                                                                                       
                                     
                      "Vaishakhi                                                       
                                     
                      Ajmera"                  To:       <[EMAIL PROTECTED]>    
                                     
                      <vaishakhi.ajmera        cc:                                     
                                     
                      @ardec.com>              Subject:  Re: NullPointerException 
while returning an arbitrary Java object  
                                                                                       
                                     
                      04/29/2002 03:33                                                 
                                     
                      PM                                                               
                                     
                      Please respond to                                                
                                     
                      axis-user                                                        
                                     
                                                                                       
                                     
                                                                                       
                                     



I was finally able to resolve my issue but the resolution confuses me so I
still need some insight from anyone who can give me some.

My User class that I was trying to return from the webservice has a
constructor as follows

public User(String vFname, String vLname, String vPassword,
     String vUuid, String vLogin)
 {
   //first name
  _fname=vFname;
  _lname=vLname;
  _password=vPassword;
  _uuid=vUuid;
  _login=vLogin;
 }

My webservice method that returned me a User object is as follows

public User getObject()
 {
  return new User("John", "Doe", "doe", "111-11-1111", "jdoe")
}

Now all I did was remove the constructor from the User object and create
the
user object in the webservice using its default constructor and set the
fields using the set methods and IT WORKED!

My new webservice method looks like this

public User getObject()
 {
  User user = new User();
  user.setFname("John");
  user.setLname("Doe");
  user.setPasswd("doe");
  user.setUuid("111-11-1111");
  user.setLogin("jdoe");
  return user;
 }

What does this mean? Why did this work? Does it mean that when I claim that
a class is bean like then it is not supposed to have a constructor? What
was
wrong with my constructor?

I would appreciate if someone could answer these questions of mine.

Thanks
Vaishakhi
----- Original Message -----
From: "Vaishakhi Ajmera" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 29, 2002 11:43 AM
Subject: NullPointerException while returning an arbitrary Java object


> Hello,
> I have a webservice method that returns to me a User object which is a
bean
> like class have getters and setters for fields like firstname, lastname,
> password.
>
> My deploy.wsdd looks like this
> <deployment xmlns="http://xml.apache.org/axis/wsdd/";
>             xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";>
>
>  <service name="TestWs" provider="java:RPC">
>   <parameter name="className" value="com.ardec.ebf.test.TestWebService"/>
>   <parameter name="allowedMethods" value="*"/>
>
>   <beanMapping qname="myNS:User" xmlns:myNS="urn:TestWebService"
>                languageSpecificType="java:com.ardec.ebf.usermgr.User"/>
>  </service>
>
> </deployment>
>
> and the client call is as follows
>
> String endpoint = http://localhost:8080/usermgr/services/TestWs
> Service  service = new Service();
> Call     call    = (Call) service.createCall();
>
> call.setTargetEndpointAddress( new java.net.URL(endpoint) );
> call.setOperationName( "getObject" );
>
> QName    qn      = new QName( "urn:TestWebService", "User" );
>
> call.registerTypeMapping(User.class, qn,
>                       new
> org.apache.axis.encoding.ser.BeanSerializerFactory(User.class, qn),
>                       new
> org.apache.axis.encoding.ser.BeanDeserializerFactory(User.class, qn));
>
> call.setReturnType(qn);
>
> User usr = (User) call.invoke( new Object [] {});
>
>
> Now when I run this class to call the service and get me the user object
I
> get the following error
>
> - Could not convert java.lang.String to bean field 'password', type
> java.lang.String
>     [junit] - Exception:
>     [junit] java.lang.NullPointerException
>     [junit]  at
org.apache.axis.encoding.ser.BeanPropertyTarget.set(Unknown
> Source)
>     [junit]  at
> org.apache.axis.encoding.DeserializerImpl.valueComplete(Unknown Source)
>     [junit]  at
org.apache.axis.encoding.DeserializerImpl.endElement(Unknown
> Source)
>     [junit]  at
> org.apache.axis.encoding.DeserializationContextImpl.endElement(Unknown
> Source)
>     [junit]  at org.apache.axis.message.SAX2EventRecorder.replay(Unknown
> Source)
>     [junit]  at
> org.apache.axis.message.MessageElement.publishToHandler(Unknown Source)
>     [junit]  at
> org.apache.axis.encoding.DeserializerImpl.startElement(Unknown Source)
>     [junit]  at
> org.apache.axis.encoding.DeserializationContextImpl.startElement(Unknown
> Source)
>     [junit]  at org.apache.axis.message.SAX2EventRecorder.replay(Unknown
> Source)
>     [junit]  at
> org.apache.axis.message.MessageElement.publishToHandler(Unknown Source)
>     [junit]  at org.apache.axis.message.RPCElement.deserialize(Unknown
> Source)
>     [junit]  at org.apache.axis.message.RPCElement.getParams(Unknown
Source)
>     [junit]  at org.apache.axis.client.Call.invoke(Unknown Source)
>     [junit]  at org.apache.axis.client.Call.invoke(Unknown Source)
>     [junit]  at org.apache.axis.client.Call.invoke(Unknown Source)
>     [junit]  at com.ardec.ebf.test.TestWsClient.testGetObject(Unknown
> Source)
>     [junit]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
>     [junit]  at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39

> )
>     [junit]  at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl

> .java:25)
>     [junit]  at java.lang.reflect.Method.invoke(Method.java:324)
> .
> .
> .
> .
>
> I have tried to follow the example 5 and I know there are many of you who
> have tried to return a Java object from the webservice. Please check my
wsdd
> and client class. What am I doing wrong here. Please help me.
>
> Thanks a lot
> Vaishakhi





Reply via email to