StatusCodeException Vs. RuntimeException in GWT

前端 未结 2 420
故里飘歌
故里飘歌 2021-01-12 10:16

In my GWT app. I overrode RemoteServiceServlet to check if the session is valid right before the service method is being called. I am trying to throw a RuntimeException(\"ex

相关标签:
2条回答
  • 2021-01-12 10:36

    The post looks too old, still here is the solution I have come up with. Override processCall(String payload) of RemoveServiceServlet, if the session is invalid execute the blow code else call super.processCall(payload).

    //Pass the exception to Client
    RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this);
    onAfterRequestDeserialized(rpcRequest);
    return RPC.encodeResponseForFailure(rpcRequest.getMethod(), new CustomException("Invalid Session!"),rpcRequest.getSerializationPolicy(), rpcRequest.getFlags());
    

    All the GWT services are servlets so GWT serializes the custom exception and sends to client as string, we follow the same :)

    0 讨论(0)
  • 2021-01-12 10:49

    All RuntimeExceptions thrown by Server side of gwt application has been wrapped as StatusCodeException if you did not declare them at your remote method declaration.

    EDIT :

    After, Thomas Broyer comment, I have learned that all exceptions (checked or unchecked) that are declared at remote method declaration are propagated to gwt client. Therefore all you have to do is just declare your remote method such as :

    public void myRemoteMethod() throws RuntimeException;
    
    0 讨论(0)
提交回复
热议问题