我正在使用hessdroid代理在我的android应用程序和我的webservice / hessianservlet之间进行通信。它在启动应用程序后立即工作,但是当我等待一段时间让应用程序再次调用网络功能(例如logout())时,我收到以下错误消息:
com.caucho.hessian.client.HessianConnectionException: 500: java.io.EOFException
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:197)
at $Proxy1.getPassword(Native Method)
at tsch.serviceApp.net.DataHandler.getPassword(DataHandler.java:50)
at tsch.serviceApp.PageSystemApps$1$1.run(PageSystemApps.java:91)
Caused by: java.io.EOFException
at libcore.io.Streams.readAsciiLine(Streams.java:203)
at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:167)
public String login() {
HessianProxyFactory factory = new HessianProxyFactory();
String url = "http://192.168.56.1:8080/hessianServer";
factory.setHessian2Reply(false); // avoid hessian reply error
try {
userCon = (IUserService) factory.create(IUserService.class, url+"/IUserService");
} catch (MalformedURLException e) {
e.printStackTrace();
}
return "Logged in!";
}
public void logout() {
userCon.logout();
}
答案 0 :(得分:1)
我在android 4.1上遇到了同样的问题,但在android 4.0.3上它没问题。我添加了一个声明“conn.setRequestProperty(”Connection“,”Close“);”在类HessianProxyFactory的方法openConnection中。
protected URLConnection openConnection(URL url)
throws IOException {
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
if (_readTimeout > 0) {
try {
conn.setReadTimeout((int) _readTimeout);
} catch (Throwable e) { // intentionally empty
}
}
conn.setRequestProperty("Content-Type", "x-application/hessian");
conn.setRequestProperty("Connection", "Close");
if (_basicAuth != null)
conn.setRequestProperty("Authorization", _basicAuth);
else if (_user != null && _password != null) {
_basicAuth = "Basic " + base64(_user + ":" + _password);
conn.setRequestProperty("Authorization", _basicAuth);
}
return conn;
}
问题就消失了。
答案 1 :(得分:0)
使用Flamingo代替Hessdroid,一切正常!