WLResourceRequest onSuccess抛出错误

时间:2016-06-16 08:10:18

标签: ibm-mobilefirst mobilefirst-server

我在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();永远是空的。

2 个答案:

答案 0 :(得分:2)

答案 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();
                        }

                    }
                });