Results 1 to 5 of 5
- 11-28-2009, 01:51 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
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?
- 11-28-2009, 04:11 PM #2
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[] ?
or, if starting from an list, make it into an array before invoking the web service call.Java Code:ArrayList res = new ArrayList(); int x[] = {23,2,5,15,24}; String ret = (String) call.invoke( new Object [] { x });
where an array of Integer objects should likely also be serializable as an array of int primitives.Java Code:List<Integer> aList = new ArrayList<Integer>(); //aList.add(new Integer(8)); Integer[] res = aList.toArray(new Integer[0]); }
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 requiredLast edited by travishein; 11-28-2009 at 04:14 PM.
- 11-28-2009, 09:42 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
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
- 11-29-2009, 01:16 AM #4
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.
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.Java 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);
- 11-29-2009, 05:33 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
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>
Similar Threads
-
Web service client
By Tshegofatsom in forum New To JavaReplies: 1Last Post: 09-09-2009, 02:31 PM -
Consume a .net web service with a java client
By pauldj54 in forum New To JavaReplies: 3Last Post: 07-15-2009, 11:53 AM -
Update Web Service Client
By gio in forum Advanced JavaReplies: 0Last Post: 09-26-2008, 10:21 AM -
Input parameter of Main method
By Java Tip in forum Java TipReplies: 1Last Post: 07-12-2008, 06:24 PM -
Problem while running web service client
By krsv36 in forum Other IDEsReplies: 0Last Post: 05-15-2008, 05:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks