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

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

    Yernar Adilbekov Newbie

      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();