Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2009, 02:51 PM
Member
 
Join Date: Nov 2009
Posts: 3
Rep Power: 0
mpouly is on a distinguished road
Default Web service client and array as input parameter
I am trying to create a web service client in IBM websphere studio applicatin developer that accepts as operation input parameter an array of int. My code is

Service service = new Service();
Call call = (Call) service.createCall();

call.registerTypeMapping(ArrayList.class, XMLType.SOAP_ARRAY, new ArraySerializerFactory(), new ArrayDeserializerFactory());

call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName( "sortArray" );
call.addParameter("x", XMLType.SOAP_ARRAY, ParameterMode.IN);

call.setReturnType(XMLType.XSD_STRING);
ArrayList res = new ArrayList();
int x[] = {23,2,5,15,24};
for(int i=0;i<x.length;i++) {
res.add(new Integer(x[i]));
}

String ret = (String) call.invoke( new Object [] { res });

I am getting the error

java.lang.Exception: convert problem class java.util.ArrayList class [I

can anyone help?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-28-2009, 05:11 PM
travishein's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Canada
Posts: 280
Rep Power: 1
travishein is on a distinguished road
Default
probaby simiar to how apache axis 1 on its own can't serialize a collections object,(you have an ArrayList here.)

can you just send the array of int[] ?
Code:
ArrayList res = new ArrayList();
int x[] = {23,2,5,15,24};

String ret = (String) call.invoke( new Object [] { x });
or, if starting from an list, make it into an array before invoking the web service call.
Code:
List<Integer> aList = new ArrayList<Integer>();
//aList.add(new Integer(8));

Integer[] res = aList.toArray(new Integer[0]);
}
where an array of Integer objects should likely also be serializable as an array of int primitives.
the trick is not to use language array objects, and not use a java-specific construct such as anything that implements java.util.Collection, because web services try to achieve the lowest common denominator, to interoperate with arbitrary platforms and other programming languages.

There are extensions Im sure to do custom serialization of these collections interfaces, but then this would require the other end of the web services messaging would also support this kind of encoding. My impression was these extensions are a bit of an arms race, and it's difficult to find one that works well for all languages. Now if you are only ever targeting to support the one platform you can probably just use these then,

but I usually find its just easier to just send array objects into the messages and unpack array objects from the response back into collections if required

Last edited by travishein; 11-28-2009 at 05:14 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-28-2009, 10:42 PM
Member
 
Join Date: Nov 2009
Posts: 3
Rep Power: 0
mpouly is on a distinguished road
Smile
I made both of your suggestions but the error still exists. I don't know if it is there the problem, I guess the problem is somewhere in these 2 lines. Is the registerTypeMapping I am using correct?

call.registerTypeMapping(ArrayList.class, XMLType.SOAP_ARRAY, new ArraySerializerFactory(), new ArrayDeserializerFactory());

call.addParameter("x", XMLType.SOAP_ARRAY, ParameterMode.IN);


Moreover, the compiler doesn;t accept to write
List<Integer> aList = new ArrayList<Integer>();
but only accepts
List aList = new ArrayList();
do you know why?

Thank you in advance
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-29-2009, 02:16 AM
travishein's Avatar
Senior Member
 
Join Date: Sep 2009
Location: Canada
Posts: 280
Rep Power: 1
travishein is on a distinguished road
Default
Oh my, so that second error to not like List<Integer> most likely means it is still using Java 1.4, (the < type > generics were invented in Java 1.5). which is possible, it has been a while since I have used websphere products, but I remember them taking a little bit longer adopt the latest Java language.

or possibly if the environment is Java 1.5, it is currently in a 1.4 compatibility mode.


Hmm, for that first error, what about registering the Integer[] array as the type mapping.

Code:
// the thing we will use to stage the array of integers
List integerList = new ArrayList();
integerList.add(new Integer(4));
// and so on, building up the list of integers.


// convert the list into an Integer array and pass that into the SOAP request.
// that is, don't pass the List, but the array of Integer[] converted.
Integer[] intArray = (Integer[]) integerList.toArray(new Integer[0]);

call.registerTypeMapping(Integer[].class, XMLType.SOAP_ARRAY, new ArraySerializerFactory(), new ArrayDeserializerFactory());

call.addParameter("x", XMLType.SOAP_ARRAY, ParameterMode.IN);
though, I would have thought the Integer[] type mapping would have been registered already, and just doing the convert list to Integer[] thing and passing that in would work.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-29-2009, 06:33 PM
Member
 
Join Date: Nov 2009
Posts: 3
Rep Power: 0
mpouly is on a distinguished road
Post
Thank you very much for your interest but unfortuantely the problem still remains.. The error is

AxisFault
faultCode: Server.generalException
faultSubcode:
faultString: java.lang.Exception: convert problem class java.util.ArrayList class [I
faultActor:
faultNode:
faultDetail:

faultCode: Server.generalException
faultSubcode:
faultString: java.lang.Exception: convert problem class java.util.ArrayList class [I
faultActor:
faultNode:
faultDetail:

java.lang.Exception: convert problem class java.util.ArrayList class [I
at org.apache.axis.message.SOAPFaultBuilder.createFau lt(SOAPFaultBuilder.java:251)

here is also the portion of the wsdl concerning the array

<element name="sortArray">
<complexType>
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="x" type="xsd:int"/>
</sequence>
</complexType>
</element>
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Tags
array, arraylist, soap_array, web services

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web service client Tshegofatsom New To Java 1 09-09-2009 03:31 PM
Consume a .net web service with a java client pauldj54 New To Java 3 07-15-2009 12:53 PM
Update Web Service Client gio Advanced Java 0 09-26-2008 11:21 AM
Input parameter of Main method Java Tip Java Tips 1 07-12-2008 07:24 PM
Problem while running web service client krsv36 Other IDEs 0 05-15-2008 06:12 PM


All times are GMT +2. The time now is 05:54 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org