HttpTransportSE.call方法返回NullPointerException异常频繁 [英] HttpTransportSE.call method returns NullPointerException frequently

查看:673
本文介绍了HttpTransportSE.call方法返回NullPointerException异常频繁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到一个WebService下载主数据我的应用程序。所以,在一个单一的下载应用程序将需要调用的WebService无的时期有不同的指标。

I connect to a webservice to download master data for my app. So, in a single download the app will need to call the webservice a no of times with different indexes.

在此期间,的 HttpTransportSE.call 的方法返回的NullPointerException 的有时为一些指标,否则它工作正常。

During this, HttpTransportSE.call method returns NullPointerException for some indexes sometimes, otherwise it works fine.

我的调用函数是:

public String SoapAction(String[] values){

String[] data = new String[] { "CompanyID", "Username", "Password", "indexNo", "DataString","lDate" };

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

for(int i = 0; i < data.length; i++){
  PropertyInfo property = new PropertyInfo();
  property.setName(data[i]);
  property.setNamespace(NAMESPACE);
  property.setType(PropertyInfo.STRING_CLASS);
  property.setValue(values[i]); 

  request.addProperty(property);
}

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);

try{
  HttpTransportSE http = new HttpTransportSE(URL);
  http.debug = true;
  System.setProperty("http.keepAlive", "false");

  http.call(SOAP_ACTION, envelope);
}catch (IOException e1) {
  e1.printStackTrace();         
  return "serverError";
} catch (XmlPullParserException e1) {
  e1.printStackTrace();
  return "serverError";     
} catch (Exception e) {
  e.printStackTrace();          
  return "serverError";
}

SoapPrimitive resultString = null;

try{
  resultString = (SoapPrimitive)envelope.getResponse();
}catch (SoapFault e) {
  e.printStackTrace();          
  return "serverError";
}

if(resultString != null){
  return resultString.toString();
} else {
  return "serverError";
}
}

我做了相当多的谷歌搜索,但没有找到一个解决方案。

I did quite a bit of googling, but couldn't find a solution

下面的堆栈跟踪:结果
02-06 14:01:14.136:W / System.err的(1504):显示java.lang.NullPointerException

Here's the stacktrace:
02-06 14:01:14.136: W/System.err(1504): java.lang.NullPointerException

14 02-06:01:14.136:W / System.err的(1504):在org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)

02-06 14:01:14.136: W/System.err(1504): at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)

14 02-06:01:14.136:W / System.err的(1504):在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:167)

02-06 14:01:14.136: W/System.err(1504): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:167)

14 02-06:01:14.136:W / System.err的(1504):在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)

02-06 14:01:14.136: W/System.err(1504): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)

14 02-06:29:50.026:W / System.err的(1504):在com.c2info.engine.WebServiceConnection.SoapAction(WebServiceConnection.java:49)

02-06 14:29:50.026: W/System.err(1504): at com.c2info.engine.WebServiceConnection.SoapAction(WebServiceConnection.java:49)

14 02-06:29:50.026:W / System.err的(1504):在com.c2info.engine.DownloadData.downloadTasks(DownloadData.java:800)

02-06 14:29:50.026: W/System.err(1504): at com.c2info.engine.DownloadData.downloadTasks(DownloadData.java:800)

14 02-06:29:50.026:W / System.err的(1504):在com.c2info.engine.DownloadData $ 3.run(DownloadData.java:187)

02-06 14:29:50.026: W/System.err(1504): at com.c2info.engine.DownloadData$3.run(DownloadData.java:187)

推荐答案

之后做一些研究,我发现,当服务器正忙,服务器处理您的请求,HttpTransportSE调用方法超时的时候它发生。默认的20年代中的超时值。所以,为了克服这个问题,

After doing some research, I found out that it happens when the server is busy and by the time the server processes your request, the HttpTransportSE call method times out. The default time-out values in 20s. So, to overcome this, :


  • 设置合适的超时值

  • Set a suitable time-out value

HttpTransportSE HTTP =新HttpTransportSE(URL,30000);

HttpTransportSE http = new HttpTransportSE(URL, 30000);

括在while循环中http.call方法,然后重试,直到'N'没有时间,直到你得到一个有效的响应

  • Enclose the http.call method in a while loop and retry till 'N' no of times till you get a valid response

    这篇关于HttpTransportSE.call方法返回NullPointerException异常频繁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆