Search code examples
androidsoapksoap2

Android KSoap2 and Array issue


I am using Ksoap2 to call a web service from Android. I build the request, but the .call() method throws the following exception:

07-22 11:12:57.718: W/System.err(9582): java.lang.NumberFormatException: Invalid int: "][2"
07-22 11:12:57.728: W/System.err(9582):     at java.lang.Integer.invalidInt(Integer.java:138)
07-22 11:12:57.728: W/System.err(9582):     at java.lang.Integer.parse(Integer.java:375)
07-22 11:12:57.738: W/System.err(9582):     at java.lang.Integer.parseInt(Integer.java:366)
07-22 11:12:57.738: W/System.err(9582):     at java.lang.Integer.parseInt(Integer.java:332)
07-22 11:12:57.738: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.getIndex(SoapSerializationEnvelope.java:287)
07-22 11:12:57.748: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.readVector(SoapSerializationEnvelope.java:304)
07-22 11:12:57.758: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:446)
07-22 11:12:57.758: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:387)
07-22 11:12:57.768: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
07-22 11:12:57.768: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
07-22 11:12:57.788: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
07-22 11:12:57.788: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
07-22 11:12:57.798: W/System.err(9582):     at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
07-22 11:12:57.798: W/System.err(9582):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
07-22 11:12:57.798: W/System.err(9582):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
07-22 11:12:57.808: W/System.err(9582):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:253)
07-22 11:12:57.808: W/System.err(9582):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
07-22 11:12:57.808: W/System.err(9582):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)

If I put the exact same request into SoapUI, the call works.

Even using KSoap2, I get a response back, but the error seems to be in Ksoap2 parsing the response.

I believe it is this portion of the response that is causing the error:

<data soapenc:arrayType="xsd:anyType[][2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

Ksoap2 is thinking that the ][2 of anyType[][2] is supposed to be an int.

Is this a bug in ksoap2? Is there a workaround for this?


Solution

  • 07-22 11:12:57.738: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.getIndex(SoapSerializationEnvelope.java:287)

    From the source of ksoap v2.1.2: this is the SoapSerializationEnvelope.getIndex(String value, int start, int dflt) method that causes the NumberFormatException:

    private int getIndex(String value, int start, int dflt) {
        if (value == null)
        return dflt;
    
        return value.length() - start < 3 ? dflt : Integer.parseInt(value.substring(start + 1, value.length() - 1));
    }
    

    And this is the SoapSerializationEnvelope.getIndex(String value, int start, int dflt) method from v2.0.1:

    private int getIndex(String value, int start, int dflt) {
        if (value == null)
        return dflt;
    
        return value.length() - start < 3
        ? dflt
        : Integer.parseInt(value.substring(start + 1, value.length() - 1));
        }
    

    Take a look at the bug report filed at http://sourceforge.net/p/kobjects/bugs/14/. Its the same problem as yours. The bug report mentions the version 2.0.1. And getIndex(String value, int start, int dflt) hasn't changed between releases 2.0.1 and 2.1.2.

    Another report: Can't handle two dimensional arrays