Search code examples
androidxmlxmlhttprequest

XmlPullParserException Unexpected token position:TEXT


I get error inside following method:

    public ResultUsers[] getContacts(java.lang.String user_id, java.lang.String offset, java.lang.String limit,
        java.lang.String phone_contacts) throws SoapFault {
    SoapObject _client = new SoapObject("urn:UserProfile", "GetContacts");
    _client.addProperty("user_id", user_id);
    _client.addProperty("offset", offset);
    _client.addProperty("limit", limit);
    _client.addProperty("phone_contacts", phone_contacts);
    SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    _envelope.bodyOut = _client;
HttpTransportSE _ht = new HttpTransportSE(Configuration.getWsUrl()); // line 378
        try {
            _ht.call("urn:UserProfile#GetContacts", _envelope);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
        return ResultUsers.toArray((Vector<SoapObject>) _envelope.getResponse());
}

Here is the logcat output:

org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT 
     Fatal error: Ca...@3:1 in java.io.InputStreamReader@41bab9b0) 
        at org.kxml2.io.KXmlParser.next(KXmlParser.java)
        at org.kxml2.io.KXmlParser.next(KXmlParser.java)
        at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java)
        at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
        at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
        at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:253)
        at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
        at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
        at com.virtulos.virtulosandroid.soap.userprofile.ServerServicePortType.getContacts(ServerServicePortType.java:375)
        at com.virtulos.virtulosandroid.model.db.service.ContactService.getContactsFromCloud(ContactService.java:79)
        at com.virtulos.virtulosandroid.task.LoadContactsTask.doInBackground(LoadContactsTask.java:58)
        at com.virtulos.virtulosandroid.task.LoadContactsTask.doInBackground(LoadContactsTask.java:1)
        at android.os.AsyncTask$2.call(AsyncTask.java)
        at java.util.concurrent.FutureTask.run(FutureTask.java)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
        at java.lang.Thread.run(Thread.java)
     null
     java.lang.NullPointerException
        at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:521)
        at com.virtulos.virtulosandroid.soap.userprofile.ServerServicePortType.getContacts(ServerServicePortType.java:387)
        at com.virtulos.virtulosandroid.model.db.service.ContactService.getContactsFromCloud(ContactService.java:79)
        at com.virtulos.virtulosandroid.task.LoadContactsTask.doInBackground(LoadContactsTask.java:58)
        at com.virtulos.virtulosandroid.task.LoadContactsTask.doInBackground(LoadContactsTask.java:1)
        at android.os.AsyncTask$2.call(AsyncTask.java)
        at java.util.concurrent.FutureTask.run(FutureTask.java)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java)
        at java.lang.Thread.run(Thread.java)

What i found on google is that there are 3 characters at the beginning of the resonse which normally are not known by parser in android, and that is why it crashes. But i am not sure how do i get rid of those characters, if that is the problem, how do i fix it considering that i need to return the results directly. Any help would be much appreciated.


Solution

  • Get the WSDL url ex: http://abc.xyz/ws/User.wsdl

    Then find service name; It probably will be at the end of the page.

    ex:

    <wsdl:service name="servicename">
            <wsdl:port name="userport" binding="tns:usrbinding">
                <soap:address
                    location="http://abc.xyz/soap/ws/ServerWSDL.php" />
            </wsdl:port>
    </wsdl:service>
    

    The location is your main url; you have to set header to that location url. and all done.

    NOTE: Don't change the soapAction URL.