mfernandez82 / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

Nullpointer using envelope.getResponse() #128

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.I send a Soap-Request to my Webservice
2.The Webservice send me a response
3.httpresponsedump contains the full and valid response
4.envelope.bodyin is null

What is the expected output? What do you see instead?
getting anything returned when using envelope.getResponse()

java.lang.NullPointerException
at 
org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerialization
Envelope.java:521)

What version of the product are you using? On what operating system?
ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar

Please provide any additional information below.

Original issue reported on code.google.com by Kostro...@googlemail.com on 11 Jul 2012 at 1:56

GoogleCodeExporter commented 9 years ago
Here ist my code to call it:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        

//adding request.addAttribute

SoapSerializationEnvelope envelope = new 
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.setAddAdornments(false);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
    androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
    e.printStackTrace();
}
System.out.println(androidHttpTransport.requestDump); //The valid Response 
System.out.println(envelope.bodyIn); //null
envelope.getResponse(); //NullpointerException

Original comment by Kostro...@googlemail.com on 11 Jul 2012 at 2:00

GoogleCodeExporter commented 9 years ago
Dont use bodyIn... use getResponse instead.

Original comment by mosa...@gmail.com on 16 Jul 2012 at 4:34

GoogleCodeExporter commented 9 years ago
As i said, envelope.getResponse() is throwing a NullpointerException, not even 
returning null.
So using it wont work obviously

Original comment by Kostro...@googlemail.com on 16 Jul 2012 at 9:06

GoogleCodeExporter commented 9 years ago
can you attach a stack trace with the NPE? 

Original comment by mosa...@gmail.com on 16 Jul 2012 at 10:21

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 16 Jul 2012 at 10:22

GoogleCodeExporter commented 9 years ago
Sure, this is is:
Caused by: java.lang.NullPointerException
at 
org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerialization
Envelope.java:521)

Original comment by Kostro...@googlemail.com on 18 Jul 2012 at 6:02

GoogleCodeExporter commented 9 years ago
That npe is becuase bodyIn is null. Your responseDump must be null.. so you are 
not actually getting a response from your server at all. Try the requestDump 
with a debug tool like SoapUi and see what you get.

Original comment by mosa...@gmail.com on 18 Jul 2012 at 7:30

GoogleCodeExporter commented 9 years ago
The Point is, the ResponseDump is not null, there i find the valid Response.
SoapUI also returns the valid Response.

Original comment by Kostro...@googlemail.com on 18 Jul 2012 at 11:14

GoogleCodeExporter commented 9 years ago
I am not sure. Can you debug into the library and see what is wrong?

Original comment by mosa...@gmail.com on 24 Aug 2012 at 11:06

GoogleCodeExporter commented 9 years ago
Struggling with the same problem:( Using 
ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar

Original comment by odan...@gmail.com on 15 Jan 2013 at 9:46

GoogleCodeExporter commented 9 years ago
Guys, try to set System.setProperty("http.keepAlive", "false"); in your code it 
might help solving the issue.

Original comment by odan...@gmail.com on 15 Jan 2013 at 1:08

GoogleCodeExporter commented 9 years ago
where should we set the propery "http.keepAlive"

Original comment by rbhhere on 28 Jan 2013 at 10:38

GoogleCodeExporter commented 9 years ago
Before you execute your connection code.

Original comment by odan...@gmail.com on 29 Jan 2013 at 7:08

GoogleCodeExporter commented 9 years ago
Here is my connection code :
try{
  HttpTransportSE http = new HttpTransportSE(URL, 10000);
  http.debug = true;
  System.setProperty("http.keepAlive", "false");
  //System.setProperty("http.keepAlive", "false");
  http.call(SOAP_ACTION, envelope);
}catch (IOException e1) {
  e1.printStackTrace();
  Log.v("IOException", e1.toString());
  return "serverError";
}catch (XmlPullParserException e1) {
  e1.printStackTrace();
  Log.v("XmlPullParserException", e1.toString());
  return "serverError";
}catch (Exception e) {
  Log.v("Exception", e.toString());
  return "serverError";
}

Guess setProperty("http.keepAlive", "false") doesn't fix it. Still catches 
nullPointerException, not always, but some times.

Original comment by rbhhere on 29 Jan 2013 at 7:19

GoogleCodeExporter commented 9 years ago
I had the same problem.. :( ... I've readed that network calls must be executed 
in new thread.. 

Source:

http://stackoverflow.com/questions/8924882/androidhttptransport-call-throwing-nu
ll-exception-when-printing-using

Original comment by calber...@gmail.com on 5 Feb 2013 at 2:16

GoogleCodeExporter commented 9 years ago
of course, network calls cannot be made in the UI thread. But this problem 
still persists.

Original comment by rbhhere on 6 Feb 2013 at 5:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I had exactly the same issue.

Description of the issue :
- When server send back a faultcode that I have created, Android application 
catch an IOException, then in this case envelope.bodyIn is null and Exception 
is HTTP request failed, HTTP status: 500 (With version 
ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar ) but, everything 
working fine with the version 
(ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies.jar)

Original comment by kanazi...@gmail.com on 26 Mar 2013 at 10:01

GoogleCodeExporter commented 9 years ago
Hi,

I'm getting the same problem.

The code works for a little times, and after that it's getting 
NullPointerException at 
org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerialization
Envelope.java:521)

This is my code:
        String ws = "UtilWS";
        SoapObject soap = new SoapObject(URL_SOAP, "verificaDisponibilidade");

        Object retorno = null;

        // Cria o envelope com o objeto SOAP
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(soap);

        // Cria o HttpTransport para enviar os dados (SOAP)  
        if(URL == null){
            URL = getURL();
        }
        MyHttpTransport httpTransport = new MyHttpTransport(URL + ws, timeout);

        try {
            httpTransport.call("", envelope);

            retorno = envelope.getResponse();

            httpTransport.reset();

            if (retorno != null) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e){
            System.out.println("[SYNC] [ERRO] Exception no verificaDisponibilidade: " + e.getMessage());
            e.printStackTrace();
            return false;   
        }

When it works, this is my bodyIn: verificaDisponibilidadeResponse{return=MQ==; }
When it doesn't work, this is my bodyIn: null

I don't know why stop to work, I didn't anything, just my sync service, without 
any new data to sync, just checking if have something new.

Sometimes works for an hour, sometimes the problem happens with 10 minutes.

Original comment by William....@gmail.com on 8 Aug 2013 at 5:28

GoogleCodeExporter commented 9 years ago
I've have the same issue 
(ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar). An exception is 
raised in HttpsTransportSE.Call()(for example with invalid login credentials). 
The strange part of this when catching this exception it's null!
Than when calling the pEnvelope.getResponse() will raise a null pointer 
exception. 

The responseDump attribute of HttpsTransportSE is not null and is including the 
fault reason. But the envelope attributes bodyIn and headerIn are both null.

It's not possible to determine the reason why something is going wrong beacuse 
the exception is null and could not be cast to SoapFault. Maybe it has 
something to do with the exception type?

public Object call(String pAction, SoapSerializationEnvelope pEnvelope) {

                mEnvelope = pEnvelope;

        if (mKeyStore != null) {
            setDebug(true);
        }

        if (mUserName != null && mPassword != null) {
            pEnvelope.headerOut = addHeaders(mUserName, mPassword);
        }

        try {

            // Android 4.1 mobile connection disconnects on some mobile phones fix: override Connection paramater value
            // "close"
            List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
            headerList.add(new HeaderProperty("Connection", "keep-alive"));

            mHttpsConnection.call(pAction, pEnvelope, headerList);

        } catch (Exception pException) {   //This one is null!
            Log.e(getClass().getSimpleName(), "Error occured during SOAP call");
            if (pException != null) { // TODO
                pException.printStackTrace();
            }

                        if (e instanceof SoapFault) {
                mFaultCode = (SoapFault) e;
            }
                     return;
        }

    return pEnvelope.getResponse();
}

Original comment by peter...@gmail.com on 28 Aug 2013 at 10:37

GoogleCodeExporter commented 9 years ago
I had same problem with version 3.0.0 
(ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar).

My problem got resolved when I moved back to version 2.6.0 
(ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar)

Original comment by anil.kin...@gmail.com on 11 Sep 2013 at 12:05

GoogleCodeExporter commented 9 years ago
Using ksoap2-android-assembly-3.0.0-RC.4-jar-with-dependencies and enclosing 
the call() method in a while loop solved the problem for me. 
- Iterate the call method 'n' times till you get a valid response.

Original comment by rbhhere on 11 Sep 2013 at 4:46

GoogleCodeExporter commented 9 years ago
Yes I was facing same issue with 
ksoap2-android-assembly-3.0.0-jar-with-dependencies after that I have tried 
previous version and its was working for me

Original comment by anand.so...@gmail.com on 24 Sep 2013 at 8:02

GoogleCodeExporter commented 9 years ago
Hello every body i have the same problem, can you helpme please)

Original comment by jhuniore...@gmail.com on 4 Oct 2013 at 3:05

GoogleCodeExporter commented 9 years ago
Hey Guys 
I have same problem we need help

Original comment by agaoglu....@gmail.com on 26 May 2014 at 6:17

GoogleCodeExporter commented 9 years ago
Hello,

Use this attached latest 3.3.0 jar file, your issue will be resolved.

Just let me know weather its resolved or not...

Original comment by anand.so...@gmail.com on 27 May 2014 at 4:55

Attachments:

GoogleCodeExporter commented 9 years ago
It's a little while ago, but to solve the issue that the exception is null, is 
to put your break point after the line with the catch statement and not put it 
on the same line. So put the breakpoint at the first statement after the open 
curly bracket of the catch block. Than the Exception isn't null anymore.

Apparently, it has something to do with the debugger.

Original comment by peter...@gmail.com on 27 May 2014 at 1:14

GoogleCodeExporter commented 9 years ago
thank you thank you !!!!!!!!

use     ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar   :D 

it works ♥ ♥ 

Original comment by amir.lav...@gmail.com on 2 Jul 2014 at 9:12

GoogleCodeExporter commented 9 years ago
it is not working with ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar 
:(

Original comment by iqz...@gmail.com on 2 Apr 2015 at 1:24