1 Reply Latest reply on Jan 6, 2014 11:32 AM by csa

    Problem with RPC Interceptor (CastException error cast Object to Response)

    shut_desert

      I have a problem when using RpcInterceptor. Throws CastException when casting Object to Response.

       

      @Remote
      @SuppressWarnings("unused")
      public interface UserDetailsService {
          @InterceptedCall(RpcServicesInterceptor.class)
          public ServerMessage getServerMessage();
      }
      

       

      @Service
      @ApplicationScoped
      @SuppressWarnings("unused")
      public class UserDetailsServiceImpl implements UserDetailsService {
          @Override
          public ServerMessage getServerMessage() {
              Calendar calendar = Calendar.getInstance();
              Date currentDate = calendar.getTime();
              return new ServerMessage("Server response",currentDate);
          }
      }
      

       

      @SuppressWarnings("unused")
      public class RpcServicesInterceptor implements RpcInterceptor {
          @Override
          public void aroundInvoke(final RemoteCallContext context) {
              context.proceed(new ResponseCallback() {
                  @Override
                  public void callback(Response response) {
                      int statusCode = response.getStatusCode();
                      if (statusCode == 200) {
                          context.setResult(Marshalling.fromJSON(response.getText()));
                          GWT.log("it's oook");
                      }
                      if (statusCode == 401) {
                          // forward to login page
                      }
                  }
              });
          }
      }
      

       

       remoteService.call(new RemoteCallback<ServerMessage>() {
                          @Override
                          public void callback(ServerMessage response) {
                              Window.alert(response.getText());
                          }
                      }).getServerMessage();
      
        • 1. Re: Problem with RPC Interceptor (CastException error cast Object to Response)
          csa

          Hi Yernar,

           

          The ResponseCallback class is for HTTP/REST based communication using Errai JAX-RS. Unfortunately, it won't work for plain Errai/RPC. Errai's RPC mechanism uses our message bus. There's no guarantee that the message bus will use plain HTTP requests at runtime (i.e. it could use websockets instead if available).

           

          So, in this case you will have to use RemoteCallback directly.

           

          Cheers,

          Christian