Web Service - Axis und J2ME

T

Thomas Gärtner

Hello,

I have an axis web service and I want to access this with J2ME from an
Pocket PC.
I used Websphere Studio Device Devloper (WSDD) and his Webservice client
generator. But I encountered 2 strange problems.

+++++++++++++++++++
+++ 1. problem: +++
+++++++++++++++++++

I have several getter methods. If this have values for instance PersonType
defined (real case fron the databse) all works fine. But if there are no
persons
I get an NullPointer Exception in WSDD in my J2ME test class
(PersonArrayType
personArrayType = stub.getPersons("");). The same code with the axis stub in
Eclipse works again
(please see code snippets below).

******************************************************
2 persons defined in server class PersonBindingImpl
******************************************************
PersonType person1 = new PersonType();
person1.setFamilyName("Summer");
person1.setGivenName("Harry");
person1.setBirthdate("13.11.1951");

PersonType person2 = new PersonType();
person2.setFamilyName("Winter");
person2.setGivenName("Mike");
person2.setBirthdate("25.03.1948");

PersonArrayType arrayType = new PersonArrayType();
arrayType.setPerson(new PersonType[] {person1, person2});
// arrayType.setPerson(new PersonType[0]);
return arrayType;


output with the axis client stub
-------------------------------------------
getPersons
personArrayType:
de.mylonghomepagename.www.jws.example.PersonArrayType@f73ff65f
personTypes: [Lde.mylonghomepagename.www.jws.example.PersonType;@79ed7f
name: Summer
name: Winter

output in wsdd (J2ME client - WebServicesME.jar)
----------------------------------------------------
personArrayType: test.PersonArrayType@35133513
personTypes: [Ltest.PersonType;@35183518
name: Summer
name: Winter


******************************************************
No persons defined in server class PersonBindingImpl
******************************************************
PersonArrayType arrayType = new PersonArrayType();
arrayType.setPerson(new PersonType[0]);
return arrayType;

output with the axis client stub (OK)
----------------------------------------------------
getPersons
personArrayType: de.mylonghomepagename.www.jws.example.PersonArrayType@1
personTypes: null
no such elements


output in wsdd (J2ME client - WebServicesME.jar) (error ???)
----------------------------------------------------------------
....
java.lang.NullPointerException
at
com.ibm.pvcws.jaxrpc.rpc.OperationImpl.decodeElement(OperationImpl.java:999)
at
com.ibm.pvcws.jaxrpc.rpc.OperationImpl.decodeComplexType(OperationImpl.java:1294)
at
com.ibm.pvcws.jaxrpc.rpc.OperationImpl.decodeElement(OperationImpl.java:1016)
at
com.ibm.pvcws.jaxrpc.rpc.OperationImpl.decodeOperation(OperationImpl.java:842)
at com.ibm.pvcws.jaxrpc.rpc.OperationImpl.invoke(OperationImpl.java:388)
at test.Person_Stub.getPersons(Person_Stub.java:134)
at test.Test.main(Test.java:51)
javax.xml.rpc.JAXRPCException: java.lang.NullPointerException
at com.ibm.pvcws.jaxrpc.rpc.OperationImpl.invoke(OperationImpl.java:401)
at test.Person_Stub.getPersons(Person_Stub.java:134)
at test.Test.main(Test.java:51)

But how I can avoid this error message in wsdd? Why I get an Nullpointer by
invoking?

+++++++++++++++++++
+++ 2. problem: +++
+++++++++++++++++++

The second problem is still more strange. Assumed I have several similar web
service methos which
gets informations from a database and send it to the client.
The soap output from axis should be ok but I get with some methods the
following exception in WSDD:

javax.xml.rpc.JAXRPCException: java.rmi.MarshalException:
org.xml.sax.SAXParseException: FATAL ERROR: Unexpected end of input.
at com.ibm.pvcws.jaxrpc.rpc.OperationImpl.invoke(Unknown Source)
...

I have tried to encapsulate this to easy reproduce it without success.
I should mentioned that it allways worked with an axis client and sometimes
with the wsdd client.
Some methods in wsdd worked also allways.

The Axis webservice should be not the problem? The axis log shows no errors.

Any help is very appreciated! This problems are very urgent and important
for me.

Thank you very much, Thomas

************************

<?xml version="1.0" encoding="utf-8"?>
<definitions
targetNamespace="http://www.mylonghomepagename.de/jws/example"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ex="http://www.mylonghomepagename.de/jws/example"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

<types>
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://www.mylonghomepagename.de/jws/example">

<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="givenName" type="xsd:string" />
<xsd:element name="familyName" type="xsd:string" />
<xsd:element name="birthdate" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PersonArrayType">
<xsd:sequence>
<xsd:element name="Person" maxOccurs="unbounded"
type="ex:personType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PersonArrayType">
<xsd:sequence>
<xsd:element name="Person" minOccurs="0"
maxOccurs="unbounded" type="ex:personType" />
</xsd:sequence>
</xsd:complexType>
<!-- elements -->
<xsd:element name="PersonArray" type="ex:personArrayType" />
<xsd:element name="AverageAge" type="xsd:int" />
</xsd:schema>
</types>

<message name="getAverageAgeReq">
<part name="parameters" element="ex:personArray" />
</message>
<message name="getAverageAgeRes">
<part name="parameters" element="ex:AverageAge" />
</message>

<message name="getPersonsReq">
<part name="PersonsReq" type="xsd:string" />
</message>
<message name="getPersonsRes">
<part name="PersonsRes" type="ex:personArrayType" />
</message>

<portType name="PersonPort">
<!-- request - response operations -->
<operation name="getAverageAge">
<input message="ex:getAverageAgeReq" />
<output message="ex:getAverageAgeRes" />
</operation>
<operation name="getPersons">
<input message="ex:getPersonsReq" />
<output message="ex:getPersonsRes" />
</operation>
</portType>

<binding name="PersonBinding" type="ex:personPort">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getAverageAge">
<soap:eek:peration
soapAction="http://www.mylonghomepagename.de" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<operation name="getPersons">
<soap:eek:peration
soapAction="http://www.mylonghomepagename.de" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>

<service name="PersonService">
<port name="PersonService" binding="ex:personBinding">
<soap:address
location="http://localhost:7070/jwsage/services/PersonService" />
</port>
</service>

</definitions>

**************

package test;

import java.rmi.*;

import javax.xml.rpc.*;

// J2ME Test class
public class Test
{
public static void main(String[] args)
{
Person_Stub stub = new Person_Stub();

// test 1
PersonType person1 = new PersonType();
person1.setFamilyName("Schulze");
person1.setGivenName("Alfred");
person1.setBirthdate("13.11.1968");

PersonType person2 = new PersonType();
person2.setFamilyName("Lehmann");
person2.setGivenName("Manfred");
person2.setBirthdate("25.03.1972");

PersonType[] types = new PersonType[] { person1, person2 };
System.out.println("types: " + types.length);

PersonArrayType array = new PersonArrayType();
array.setPerson(types);

int age;

try
{
// test 1
age = stub.getAverageAge(array);
System.out.println("average age: " + age + " years\n");

// test 2
PersonArrayType personArrayType = stub.getPersons("");
System.out.println("personArrayType: " + personArrayType);
PersonType[] personTypes = personArrayType.getPerson();
System.out.println("personTypes: " + personTypes);

if (personTypes != null)
{
for (int i = 0; i < personTypes.length; i++)
{
PersonType personType = personTypes;
System.out.println("name: " + personType.getFamilyName());
}
}
else
System.out.println("no such elements");
}
catch (RemoteException e)
{
e.printStackTrace();
}
catch (JAXRPCException e)
{
e.printStackTrace();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top