I didn't realize issue 4870 existed or I would have commented on it
long ago.

In our world, we like to set the HTTP response code to a non-SC_OK
response when the RPC service throws an Exception.  This way we can
easily grep our "access.log" for failed responses.  An the Exception
might be whatever class of exceptions our RPC services are allowed to
throw.  Custom Exceptions like ValidationException,
InvalidSessionException, ResourceUnavailableException.  Whatever.

GWT's RPC mechanisms make this impossible for two different reasons:

    1) Legacy RPC ignores the response.setStatus(<non-SC_OK>) by re-
setting it in RPCServletUtils.writeResponse()

    2) deRPC doesn't reset the response.setStatus(<non-SC_OK >) (which
is good!) but its client-side code sees that the response is non-SC_OK
and throws a StatusCodeException, making it impossible to get the
Exception my code threw.  (deRPC also just doesn't work in compiled
mode, but that's not relevant to this thread).

I posted about this back in March, and received no reply (http://
groups.google.com/group/google-web-toolkit-contributors/browse_thread/
thread/631b8c3177930913/688dd476a8d0e359?lnk=gst&q=Eric
+Ridge#688dd476a8d0e359).

What I think is a better solution is for the server-side to *not*
reset the response status, and for the client-side to examine the
encodedResponse when the status is not SC_OK.  If the encodedResponse
is an exception, it should decode it and throw it (rather than
throwing a StatusCodeException).

Otherwise, it should do what this changeset does.  Even in this case
it's not ideal because I can't seem to find a way to decode the
encodedResponse back into an Object.

Anyways, if this area is receiving some attention now, please consider
the above.

Thanks!

eric

On Aug 2, 9:21 am, drfibona...@google.com wrote:
> Reviewers: zundel,
>
> Description:Enhancementfor issue4870
>
> Please review this athttp://gwt-code-reviews.appspot.com/732801/show
>
> Affected files:
>    M user/src/com/google/gwt/user/client/rpc/StatusCodeException.java
>
> Index: user/src/com/google/gwt/user/client/rpc/StatusCodeException.java
> ===================================================================
> --- user/src/com/google/gwt/user/client/rpc/StatusCodeException.java    
> (revision 8450)
> +++ user/src/com/google/gwt/user/client/rpc/StatusCodeException.java    
> (working copy)
> @@ -23,23 +23,31 @@
>    */
>   public class StatusCodeException extends InvocationException {
>     private final int statusCode;
> +  private final String encodedResponse;
>
>     /**
>      * Construct an exception with the given status code and description.
>      *
>      * @param statusCode the HTTP status code to report
> -   * @param message a message to report
> +   * @param encodedResponse the HTTP response message to report
>      */
> -  public StatusCodeException(int statusCode, String message) {
> -    super(message);
> +  public StatusCodeException(int statusCode, String encodedResponse) {
> +    super(statusCode + " " + encodedResponse);
>       this.statusCode = statusCode;
> +    this.encodedResponse = encodedResponse;
>     }
>
>     /**
> +   * Returns the response message associated with the failed request.
> +   */
> +  public String getEncodedResponse() {
> +    return encodedResponse;
> +  }
> +
> +/**
>      * Returns the status code associated with the failed request.
>      */
>     public int getStatusCode() {
>       return statusCode;
>     }
> -}
> -
> +}
> \ No newline at end of file

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to