I need to implement a function that calls a web service and return the response.
I tried
public String getFolderJson(String path) {
Stri
I guess the builder.sendRequest(xxx) will return something like a Future,and you can get the result from that object.What you are using is an asynchronous method of RequestBuilder,there should be some synchronous method as well.
what does RequestBuilder come from? I can check the api for you.
OK,try this:
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);
final SynchronousQueue resultQueue = new SynchronousQueue();
try {
builder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response) {
resultQueue.put(response.getText());
System.out.println(response.getText());
}
@Override
public void onError(Request request, Throwable exception) {
}
});
return resultQueue.take();
} catch (RequestException e) {
}
return result;
}
It seems RequestBuilder does not have any Synchronous method to get the result only a callback.
Be careful this method will block until the response is recieved. If this method is called in an event processing thread of gwt,this would be a bad practice.