我在WLResourceRequest
的onsuccess回调中收到错误,错误如下。
com.sun.jdi.InternalException:意外的JDWP错误:14无法评估com.worklight.wlclient.api.WLResponse.toString()
为什么我们会收到此错误?有没有办法跳过这个。
我使用的代码是
它运行正常我在使用时得到了响应 WLHttpResponseListener 而不是WLResponseListener。
wlResponse.getResponseText();给出空洞的回应。
WLResourceRequest request = new WLResourceRequest("Actual server path here", GET);
request.addHeader(new BasicHeader("IfAnyHeader", "here"));
request.send(new ResponseListener());
private class ResponseListener implements WLResponseListener {
@Override
public void onSuccess(WLResponse wlResponse) {
responseCode = wlResponse.getStatus();
final String result = wlResponse.getResponseText();
}
@Override
public void onFailure(WLFailResponse wlFailResponse) {
responseCode = wlFailResponse.getStatus();
final String result = wlFailResponse.getResponseText();
}
我在onSuccess方法上得到错误... wlResponse.getResponseText();永远是空的。
答案 0 :(得分:2)
WLResponseListener支持WLClient.invokeProcedure。
WLHTTPResponseListener支持发送WLResourceRequests http://www.ibm.com/support/knowledgecenter/en/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjava-worklight-android-native/html/com/worklight/wlclient/api/WLHttpResponseListener.html
由于您使用的是WLResourceRequest(最佳做法),因此这是预期的行为。
答案 1 :(得分:1)
我终于找到了解决这个问题的方法。
request.send( new WLHttpResponseListener() {
@Override
public void onSuccess(HttpResponse httpResponse) {
BufferedReader reader = null;
try {
// responseCode = httpResponse.getStatusLine();
WLResponse wlResponse=new WLResponse(httpResponse);
int responseCode=wlResponse.getStatus();
reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
// used a function to convert reader to string
final String result = entityToString(reader);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(HttpResponse httpResponse, Exception e) {
BufferedReader reader = null;
try {
responseCode = new WLFailResponse(new WLResponse(httpResponse)).getStatus();
reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String result = entityToString(reader);
} catch (IOException eec) {
e.printStackTrace();
}
}
});