如何从MFP 8.0中的Java适配器异步调用javascript适配器?

时间:2019-01-21 21:30:38

标签: ibm-mobilefirst mobilefirst-adapters

在这里,我尝试从Java适配器异步调用多个js适配器,但是无法获取响应对象。谁能帮助我。我使用Callable and Future of java进行了尝试。

public JSONArray getResourceDataAsync() throws IOException, InterruptedException, ExecutionException
    HttpUriRequest request = adaptersAPI.createJavascriptAdapterRequest(randNumberAdapter, "getEmpDetails");
    addJsAdapterRequest(request);

    request = adaptersAPI.createJavascriptAdapterRequest(randTextAdapter, "getJson");
    addJsAdapterRequest(request);
    new Thread(new Runnable() {

        public void run() {
            System.out.println("Inside Thread Run method");
            HttpUriRequest req = adaptersAPI.createJavascriptAdapterRequest(randNumberAdapter, "getEmpDetails");
            HttpResponse res=null;
            try {
                res = adaptersAPI.executeAdapterRequest(req);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            JSONObject object=null;
            try {
                object = adaptersAPI.getResponseAsJSON(res);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println("The response from Thread Implementation is  -->" + object);
        }
    }).start();

1 个答案:

答案 0 :(得分:0)

适配器混搭调用-一个适配器调用另一个部署的适配器,只能同步完成。不支持异步调用。您所观察到的是预期的。

正确的方法是使用以下代码:

HttpUriRequest req = adaptersAPI.createJavascriptAdapterRequest(AdapterName, ProcedureName, [parameters]);
org.apache.http.HttpResponse response = adaptersAPI.executeAdapterRequest(req);
JSONObject jsonObj = adaptersAPI.getResponseAsJSON(response);

详细信息为here