Tuesday, November 8, 2016

Re: JsonpRequestBuilder - Timeout while calling

JsonpRequestBuilder has a default timeout of 10 seconds, whereas RequestBuilder doesn't have a timeout by default.
Anyway, if you can setup CORS on your server (Access-Control-Allow-Origin response header whitelisting your client, or simply "*"), better use that and RequestBuilder than JSONP (better error handling, much better security, etc.): http://caniuse.com/cors

(talking about security: use com.google.gwt.core.client.JsonUtils to parse JSON, not eval() !)

On Monday, November 7, 2016 at 11:53:33 PM UTC+1, Velusamy Velu wrote:
Trying to retrieve an object in my GWT client using JsonpRequestBuilder from a cross domain server.  The call goes to server and server does respond with the correct value but the client keeps throwing "Timeout while calling http://localhost:8080/layouts/AVhARgXQW9-o1U_GgvJa" message. Here are the code snippets.

The call is made from this class -
public class EntityFisher {
   
public String fish(String id) {
       
JsonpRequestBuilder builder = new JsonpRequestBuilder();
       
String url = "http://localhost:8080/layouts/" + id;
       
AsyncCallback<LayoutJson> callback = new LayoutFisherCallback();
       
JsonpRequest<LayoutJson> layoutJson = builder.requestObject(url, callback);
 
...
       
return t;
   
}
}

LayoutJson.java
public class LayoutJson extends JavaScriptObject {
   
protected LayoutJson() {}
   
public static final native LayoutJson build(String json) /*-{
        return eval('(' + json + ')');
    }-*/
;

   
public final native JsonArray<PointJson> getCoordinates() /*-{
        return this.coordinates;
    }-*/
;
}

LayoutFisherCallback.java
public class LayoutFisherCallback implements AsyncCallback<LayoutJson> {
   
@Override
   
public void onFailure(Throwable caught) {UiFlag.flag(caught);}

   
@Override
   
public void onSuccess(LayoutJson layoutJson) {
       
JsonArray<PointJson> pointsJson = layoutJson.getCoordinates(); // code never reaches this point
       
UiFlag.flagNull("pointsJson", pointsJson);
       
ArrayList<Point> coordinates = new ArrayList<>();
       
UiFlag.flag(coordinates.toString());
   
}
}

the call is kicked off like this
   EntityFisher fisher = new EntityFisher();
   fisher
.fish(id);

I see everything done correctly on the server side and the JSON
{"coordinates":[{"x":100,"y":90,"z":0,"index":0,"time":1478546404606},{"x":118,"y":121,"z":0,"index":1,"time":1478547002023},{"x":154,"y":121,"z":0,"index":2,"time":1478547079871}]}
is sent back as expected but I keep getting the "Timeout while calling http://localhost:8080/layouts/AVhARgXQW9-o1U_GgvJa" on the client side. When I make the request through GWT RequestBuilder (as a same origin request) everything works good.

Any idea what's wrong in the above code?

I would appreciate any help.
Thanks

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment