I need to implement a function that calls a web service and return the response.
I tried
public String getFolderJson(String path) {
String result="initial_value";
StringBuilder param = new StringBuilder();
param.append("?sessionId=").append(getSessionId());
param.append("&path=").append(path);
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "https://localhost/folder" + param);
try {
builder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response) {
result = response.getText();
System.out.println(response.getText());
//I need to return "result"
}
@Override
public void onError(Request request, Throwable exception) {}
});
return result; //the result get returned before the response is recieved.So i am getting the return value "initial_value".
}
catch (RequestException e) {}
return null;
}
On calling getFolderJson()
the web service is called succesfully. But result
is returned before the respnse is recieved. So I am getting the retunr value "initial_value".
How to return the value from the response when getFolderJson()
function ?