Results 1 to 5 of 5
  1. #1
    mpouly is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    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?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    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[] ?
    Java 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.
    Java 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 04:14 PM.

  3. #3
    mpouly is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    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

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    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.

    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);
    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.

  5. #5
    mpouly is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    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>

Similar Threads

  1. Web service client
    By Tshegofatsom in forum New To Java
    Replies: 1
    Last Post: 09-09-2009, 02:31 PM
  2. Consume a .net web service with a java client
    By pauldj54 in forum New To Java
    Replies: 3
    Last Post: 07-15-2009, 11:53 AM
  3. Update Web Service Client
    By gio in forum Advanced Java
    Replies: 0
    Last Post: 09-26-2008, 10:21 AM
  4. Input parameter of Main method
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 07-12-2008, 06:24 PM
  5. Problem while running web service client
    By krsv36 in forum Other IDEs
    Replies: 0
    Last Post: 05-15-2008, 05:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •