How to send a GWT RequestFactory request

Can I resend RequestFactory transfer? I would like to do the equivalent of this: How to resubmit an RPC GWT request when using RequestFactory. It is enough just to resend the same payload from the previous request, but I also need to send the call to the same method. Here is my RequestTransport class, and I hope to simply β€œrepair” the original request after it makes sure that the login credentials are requested to the user in this case:

package org.greatlogic.rfexample2.client; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.Response; import com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport; /** * Every request factory transmission will pass through the single instance of this class. This can * be used to ensure that when a response is received any global conditions (eg, the user is no * longer logged in) can be handled in a consistent manner. */ public class RFERequestTransport extends DefaultRequestTransport { //-------------------------------------------------------------------------------------------------- private IClientFactory _clientFactory; //================================================================================================== private final class RFERequestCallback implements RequestCallback { private RequestCallback _requestCallback; private RFERequestCallback(final RequestCallback requestCallback) { _requestCallback = requestCallback; } // RFERequestCallback() @Override public void onError(final Request request, final Throwable exception) { _requestCallback.onError(request, exception); } // onError() @Override public void onResponseReceived(final Request request, final Response response) { if (response.getStatusCode() == Response.SC_UNAUTHORIZED) { _clientFactory.login(); } else { _clientFactory.setLastPayload(null); _clientFactory.setLastReceiver(null); _requestCallback.onResponseReceived(request, response); } } // onResponseReceived() } // class RFERequestCallback //================================================================================================== @Override protected void configureRequestBuilder(final RequestBuilder builder) { super.configureRequestBuilder(builder); } // configureRequestBuilder() //-------------------------------------------------------------------------------------------------- @Override protected RequestCallback createRequestCallback(final TransportReceiver receiver) { return new RFERequestCallback(super.createRequestCallback(receiver)); } // createRequestCallback() //-------------------------------------------------------------------------------------------------- void initialize(final IClientFactory clientFactory) { _clientFactory = clientFactory; } // initialize() //-------------------------------------------------------------------------------------------------- @Override public void send(final String payload, final TransportReceiver receiver) { String actualPayload = _clientFactory.getLastPayload(); TransportReceiver actualReceiver; if (actualPayload == null) { actualPayload = payload; actualReceiver = receiver; _clientFactory.setLastPayload(payload); _clientFactory.setLastReceiver(receiver); } else { actualReceiver = _clientFactory.getLastReceiver(); } super.send(actualPayload, actualReceiver); } // send() //-------------------------------------------------------------------------------------------------- } 
+7
source share
2 answers

Based on Thomas’s assumption, I tried sending another request and simply replaced the payload and receiver in the RequestTransport.send() method, and it worked; I believe that no further context is saved at the factory request and that the response from the server is enough for the RF to determine what needs to be done to unpack the response outside of the request and response , which are returned in RequestCallback.onResponseReceived() . If anyone is interested in my code, just let me know and I will post it here.

+1
source

Perhaps, but you have a lot to do.

I had the same idea. And I was looking for a good solution for about 2 days. I tried to intercept the server call on RequestContext.java and other classes. But if you do, you must make your own implementation for almost every gwt requestfactories class. So I decided to go a lot easier.

Wherever I made the request, I processed the answer and fired again. Of course, you need to make sure that you do not fall into the loop.

0
source

All Articles