You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Stephen Kilburn <sk...@geopraxis.ca> on 2008/06/04 22:39:39 UTC

Problem using Spring/ArrayList

Hi,

 

I'm trying to use Axis2 1.4 Spring as a transport for objects containing an
ArrayList.  This is not working for me.

 

XP SP2/JDK1.6.0_06/Apache 2.2/Tomcat 5.5/Axis 2 1.4 using war install.

 

Using the WeatherSpringService example, I modify the Weather class to
contain ArrayList<String> comments.  I add getter and setter methods.  I set
a comment.

 

Generated WSDL shows:

 

<xs:complexType name="Weather">

<xs:sequence>

<xs:element minOccurs="0" name="comments" nillable="true"
type="xs:anyType"/>

<xs:element minOccurs="0" name="forecast" nillable="true" type="xs:string"/>

<xs:element minOccurs="0" name="howMuchRain" type="xs:float"/>

<xs:element minOccurs="0" name="rain" type="xs:boolean"/>

<xs:element minOccurs="0" name="temperature" type="xs:float"/>

</xs:sequence>

</xs:complexType>

 

When I execute the getWeather method the SOAP passed back shows:

 

<ns:return type="sample.spring.bean.Weather">

<ax21:comments>it's nice now!</ax21:comments>

<ax21:forecast>le matin</ax21:forecast>

<ax21:howMuchRain>0.1</ax21:howMuchRain>

<ax21:rain>true</ax21:rain>

<ax21:temperature>37.2</ax21:temperature>

</ns:return>

 

(i.e. the set value is being transported) 

 

During testing, I added a setComments(ArrayList<String> cmt) function to the
bean.  Later on, I included the following line after setting the internal
variable:

 

comments.add("setComments(ArrayList) was called with an array sized " +
cmts.size());

 

This is set and says that the passed array was sized 0, so I conclude that
something in the transport is creating an ArrayList<String> and attempting
to set the bean with it, but doesn't populate the ArrayList first.

 

Am I missing something here?  Has anyone made something like this work
successfully?  It would make my life easier if I could make this work.

_____________________________________________________________
Stephen Kilburn
GeoPraxis Inc.

 


RE: Problem using Spring/ArrayList

Posted by Stephen Kilburn <sk...@geopraxis.ca>.
Further on this problem.  After a bunch of experimenting I was getting weird
ClassCastException errors from my ArrayList (which I declared as <String>
and set with a bunch of string values.  I altered my client, adding the
following:

 

comments = result.getComments();

// (Check that the variable isn't null - it isn't and has one element.)

System.out.println("comments exists and is of type " + comments.getClass());

Object o;

o = comments.get(i);

System.out.println("comment " + i + " class is " + o.getClass());

 

This returned:

 

comments exists and is of type class java.util.ArrayList

comment 0 class is class org.apache.axiom.om.impl.llom.OMElementImpl  (?!?)

 

I'm concluding that for my ArrayList Axis2/Spring is calling the
setComments(ArrayList al) method but is populating the ArrayList without
converting the transport elements back into String first.

 

I have fallen back on using fixed arrays.  These are more hassle but they
work right now.

_____________________________________________________________
Stephen Kilburn, GeoPraxis Inc.

 

From: Stephen Kilburn [mailto:skilburn@geopraxis.ca] 
Sent: June 4, 2008 16:40
To: axis-user@ws.apache.org
Subject: Problem using Spring/ArrayList

 

Hi,

 

I'm trying to use Axis2 1.4 Spring as a transport for objects containing an
ArrayList.  This is not working for me.

 

XP SP2/JDK1.6.0_06/Apache 2.2/Tomcat 5.5/Axis 2 1.4 using war install.

 

Using the WeatherSpringService example, I modify the Weather class to
contain ArrayList<String> comments.  I add getter and setter methods.  I set
a comment.

 

Generated WSDL shows:

 

<xs:complexType name="Weather">

<xs:sequence>

<xs:element minOccurs="0" name="comments" nillable="true"
type="xs:anyType"/>

<xs:element minOccurs="0" name="forecast" nillable="true" type="xs:string"/>

<xs:element minOccurs="0" name="howMuchRain" type="xs:float"/>

<xs:element minOccurs="0" name="rain" type="xs:boolean"/>

<xs:element minOccurs="0" name="temperature" type="xs:float"/>

</xs:sequence>

</xs:complexType>

 

When I execute the getWeather method the SOAP passed back shows:

 

<ns:return type="sample.spring.bean.Weather">

<ax21:comments>it's nice now!</ax21:comments>

<ax21:forecast>le matin</ax21:forecast>

<ax21:howMuchRain>0.1</ax21:howMuchRain>

<ax21:rain>true</ax21:rain>

<ax21:temperature>37.2</ax21:temperature>

</ns:return>

 

(i.e. the set value is being transported) 

 

During testing, I added a setComments(ArrayList<String> cmt) function to the
bean.  Later on, I included the following line after setting the internal
variable:

 

comments.add("setComments(ArrayList) was called with an array sized " +
cmts.size());

 

This is set and says that the passed array was sized 0, so I conclude that
something in the transport is creating an ArrayList<String> and attempting
to set the bean with it, but doesn't populate the ArrayList first.

 

Am I missing something here?  Has anyone made something like this work
successfully?  It would make my life easier if I could make this work.

_____________________________________________________________
Stephen Kilburn
GeoPraxis Inc.