-
1. Re: Problem with REST Service Interceptor
csa Dec 20, 2013 3:03 PM (in response to shut_desert)Hi,
Unfortunately, using two different type of callbacks (at the call site and in the interceptor) wasn't originally supported. You will need to upgrade to the latest 3.0-SNAPSHOTs or 2.4.4-SNAPSHOTs to make this work.
If you're intercepting the response using a different callback you will also need to make sure to set the result in the call context so that the original callback (the callback provided at the call site) can be invoked.
public class SimpleInterceptor implements RestClientInterceptor { @Override public void aroundInvoke(final RestCallContext context) { context.proceed(new ResponseCallback() { @Override public void callback(Response response) { int statusCode = response.getStatusCode(); if (statusCode == 200) { GWT.log("it's ok"); context.setResult(Marshalling.fromJSON(response.getText())); } if (statusCode == 404) { GWT.log("Error 404"); // to do something } } }); } }
-
2. Re: Re: Problem with REST Service Interceptor
csa Dec 20, 2013 3:24 PM (in response to csa)There's also an easier solution that doesn't require you to upgrade (using both a RemoteCallback and an ErrorCallback instead of a ResponseCallback in your interceptor):
public class SimpleInterceptor implements RestClientInterceptor { @Override public void aroundInvoke(final RestCallContext context) { context.proceed( new RemoteCallback<ServerMessage>() { @Override public void callback(ServerMessage serverMessage) { GWT.log("it's ok"); } }, new RestErrorCallback() { @Override public boolean error(Request message, Throwable throwable) { try { throw throwable; } catch(ResponseException re) { if (re.getResponse().getStatusCode() == 404) { // react to 404 } // react to other error codes... } catch (Throwable t) { } return false; } )); } }
Cheers,
Christian
-
3. Re: Problem with REST Service Interceptor
shut_desert Dec 25, 2013 7:08 AM (in response to csa)Christian,tell me please.I used for errai: 3.0.0.20131101-M2. I have a problem with the current task. When I call the service, there is an error: JSONException.
What am I doing wrong?