Here is how i Build My Kosap request XML :
public static SoapSerializationEnvelope constructEnvelope (String METHOD_NAME, List<NameValuePair> properties) {
SoapObject request = new SoapObject(Constants.NAMESPACE, METHOD_NAME);
if (null != properties && !properties.isEmpty() && properties.size() > 0) {
for (NameValuePair prop : properties) {
request.addProperty(prop.getName(), prop.getValue());
}
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
if (null != properties && !properties.isEmpty() && properties.size() > 0) {
envelope.addMapping(Constants.NAMESPACE, METHOD_NAME, request.getClass());
}
return envelope;
}
Stack Trace :
04-08 16:46:42.292: WARN/System.err(19812): java.lang.NullPointerException
04-08 16:46:42.292: WARN/System.err(19812): at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)
04-08 16:46:42.292: WARN/System.err(19812): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:189)
04-08 16:46:42.292: WARN/System.err(19812): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
04-08 16:46:42.292: WARN/System.err(19812): at com.cantorfuturesexchange.CantorBinaryOptions.ui.LogInActivity$PracticeRegistration.doInBackground(LogInActivity.java:665)
04-08 16:46:42.292: WARN/System.err(19812): at com.cantorfuturesexchange.CantorBinaryOptions.ui.LogInActivity$PracticeRegistration.doInBackground(LogInActivity.java:623)
04-08 16:46:42.292: WARN/System.err(19812): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 16:46:42.292: WARN/System.err(19812): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-08 16:46:42.302: WARN/System.err(19812): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-08 16:46:42.302: WARN/System.err(19812): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-08 16:46:42.302: WARN/System.err(19812): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-08 16:46:42.302: WARN/System.err(19812): at java.lang.Thread.run(Thread.java:856)
04-08 16:46:42.342: ERROR/MP-Decision(1576): UP Ld:55 Nw:1.990000 Tw:140 rq:2.800000 seq:147.000000
04-08 16:46:42.793: ERROR/MP-Decision(1576): DOWN Ld:18 Ns:1.100000 Ts:190 rq:0.000000 seq:197.000000
04-08 16:46:43.574: WARN/PowerManagerService(718): Timer 0x7->0x3|0x0
Research effort :
By changing my envelope creation as explained in the following link : HttpTransportSE.call method returns NullPointerException frequently
public static SoapSerializationEnvelope constructEnvelope (String METHOD_NAME, List<NameValuePair> properties) {
SoapObject request = new SoapObject(Constants.NAMESPACE, METHOD_NAME);
if (null != properties && !properties.isEmpty() && properties.size() > 0) {
for (NameValuePair prop : properties) {
PropertyInfo property = new PropertyInfo();
{
property.name = prop.getName();
property.setNamespace(Constants.NAMESPACE);
property.setValue(prop.getValue());
}
request.addProperty(property);
}
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
if (null != properties && !properties.isEmpty() && properties.size() > 0) {
envelope.addMapping(Constants.NAMESPACE, METHOD_NAME, request.getClass());
}
return envelope;
}
I have even found few other links which i have tried everything like using Ksoap version 3.0.0 rather than version 3.0.0-rc4 nothing works. I even found a link which states something about checking the basics but i am not able to understand how to fix the issue. below is the link for that.
I have searched for many things on the null pointer exception some suggested to use Http keep-Alive and some suggested to use different versions for Ksoap2 none of them were helpful. So i started to mess with the sources. I have solved the problem by a simple hack. This hack helped me because i was only getting null pointer exceptions on the very first ksoap2 call i made. After the first call all the ksoap2 calls are successful. So i am not proposing this as an answer but in case if some one is also facing the same problem they can download ksoap2 sources and edit the HttpTransportSE's call function as follows.
public List call(String soapAction, SoapEnvelope envelope, List headers)
throws IOException, XmlPullParserException {
return call(soapAction, envelope, headers, null);
}
public List callWithRetry(String soapAction, SoapEnvelope envelope, List headers, int numRetries)
throws IOException, XmlPullParserException {
for (int i=0; i<=numRetries; i++) {
try {
return call(soapAction, envelope, headers, null);
} catch (IOException e) {
if (i==numRetries) {
throw e;
}
} catch (XmlPullParserException e) {
if (i==numRetries) {
throw e;
}
}
}
return null;
}
I just added the numOfRetries just in case if i needed more than a single try. And i called the callwithretry function where ever i get the null pointer exception. Every thing worked like a charm. Note: Here we are making the server request more than once if the call fails. If in any case you do not want that use the old call function.