2 Replies Latest reply on Jan 6, 2014 12:49 PM by Yernar Adilbekov

    How to replace the class in Errai for ResponseException

    Yernar Adilbekov Newbie

      Guys, I want to replace the class HttpPollingHandler with class which I realized MyHttpPollingHandler. I added in app.gwt.xml:


        <replace-with class="org.jboss.errai.samples.restdemo.client.MyHttpPollingHandler">
              <when-type-is class="org.jboss.errai.bus.client.framework.transports.HttpPollingHandler"/>


      Unfortunately it did not help. These settings do not change the specified class. What am I doing wrong? May still need to add something?

        • 1. Re: How to replace the class in Errai for ResponseException
          Christian Sadilek Master



          replace-with in your gwt.xml defines a GWT rebind rule for deferred binding. We don't use deferred binding when creating instances of transport handlers. So, you cannot use this mechanism to override the behaviour in HttpPollingHandler. Also, Errai's message bus will use different transport handlers based on the capabilities of your browser and server. So, even if you could override HttpPollingHandler this wouldn't be a reliable solution.


          Can you elaborate why you want to do this? It sounds like switching to a plain REST based communication with Errai JAX-RS is a better solution in this case.



          • 2. Re: Re: How to replace the class in Errai for ResponseException
            Yernar Adilbekov Newbie

            We are developing an application where all the services are working only through RPC. When I call the service, I have to check the status code of the response. Then I have to handle this status code. For example, if the status is 401, I have to redirect to the login page. I used the Interceptor for service so, but nothing happens:


            public class SimpleInterceptor implements RpcInterceptor {
                public void aroundInvoke(final RemoteCallContext context) {
                    final RemoteCallback remoteCallback = new RemoteCallback() {
                        public void callback(Object response) {
                    final ErrorCallback errorCallback = new ErrorCallback() {
                        public boolean error(Object message, Throwable throwable) {
                            try {
                                throw throwable;
                            } catch (ResponseException responseException) {
                                int statusCode = responseException.getResponse().getStatusCode();
                                if (statusCode == 401) {
                            } catch (Throwable t) {
                            return false;
                    context.proceed(remoteCallback, errorCallback);


            Why would I want to replace the class HttpPollingHandler? I wanted to add my implementation to handle the different status code. How can I do this? Maybe do this through the GWT? Help solve this problem...