Search code examples
google-app-enginegwtrequestfactory

GWT RequestFactory not firing properly after using edit()


I have a problem using "fire()" with a GWT RequestFactory after I've used it to unfreeze and edit a proxy.

If I have two request factory objects and their associated contexts like this:

private SyntheticRequest req1 = requestFactory.someRequest(); 
private Request<xProxy> sendRequest1 = req1.something(); 

private SyntheticRequest req2 = requestFactory.someRequest(); 
private Request<xProxy> sendRequest2 = req2.something();

using "fire()" on the first request works fine:

sendRequest1.fire(new Receiver<xProxy>() {
    @Override
    public void onSuccess(xProxy response) {
        ...
        if (somethingIsTrue){
               xProxy x = req2.edit(response);  //<-- **I think this causes a problem later, although the proxy "x" works as expected here.**
               x.setSomething("something"); 
               update();                
         }
});

that part runs ok because I get to the "onSuccess". But when this one runs "update()", which looks like this:

private void update(){
  sendRequest2.fire(new Receiver<xProxy>(){
       ...onFailure...
       ...onSuccess...
  });
}

sendRequest2 always fails, with the error

Server Error Index:0 Size:0

and I put a breakpoint in the code for the "something()" service and it never even gets to that code! There must be something about the "req2.edit()" that hurts req2 and sendRequest2, but what?

Thanks.


Solution

  • what is 'b'? the line xProxy x = req2.edit(b); is the first time it's mentioned? is it supposed to be xProxy x = req2.edit(response);

    Anyway.. that is not the problem.. 'Server Error' indicates that RequestFactory caught an exception during the processing of a request, server-side. Something (but maybe not something()) is throwing an IndexOutOfBounds exception.

    If you have a look at RequestFactoryServlet.java (which you can replace with your own very easily btw) you can see it setting up a try catch block that catches all exceptions when processing a request. It passes them to 'DefaultExceptionHandler' which wraps them in a ServerFailure, and that gets returned to you GWT code as an onFailure() call.

    An easy way to find where the exception is being thrown is set a breakpoint on IndexOutOfBoundsException, making sure to catch 'caught' exceptions as well as uncaught.