On May 26, 2010, at 11:31 AM, Morten wrote:
> --- Den ons 26/5/10 skrev Paul Sandoz <Paul.Sandoz_at_Sun.COM>:
>> Reusing the response entity to return the stack trace is
>> problematic even in a "developer mode" as it might interfere
>> with the app. We have found that the best thing to do is for
>> Jersey to not interfere with the response entity.
>>
>> Modifying Jersey's UniformInterfaceException to
>> automatically include the response entity as the error
>> message of the exception is not the right thing to do as the
>> response entity could be application specific (and may not
>> translate to a String).
>
> Sorry, I can't see the problem here. I believe all this can be put
> into Jersey client if you do roughly like the source code I send.
> Depending on which error code the server returns I have either a
> String with the stacktrace OR the correct entity in the response.
> Jersey just have to look at the status code before taking message/
> entity out of the response. And throwing an
> UniformInterfaceException does what Jersey would do anyway if I try
> to get my entity in case of an error + it gives a nice stack trace
> in JUnit if a test on the client side fails.
>
>> I think we need to investigate adding an stack trace to a
>> response header. Then it should be possible to report
>> something in Jersey-client.
>
> Yes - also doable but I believe what I have shown works as-is.
>
Yes, but it is specific to your application.
The client is assuming that the response entity for a response of a
certain status code is appropriate as the message of a Java exception.
This assumption cannot be made for a general client-side solution.
What we require is some additional meta-data for this to work for
example:
1) Define a specific media type for the exception stack trace; or
2) Use a response header.
Potentially in development mode we could include the stack trance for
a 500 response if there is no entity present and use a media type of
say vnd.oracle.application/java-stack-trace. But i personally would
prefer not to add a response entity in such cases and would prefer a
more general solution as the application may have included their own
response entity.
Or we could include a response header:
X-Java-Stack-Trace:
and then the UnitformInterfaceException can check for that header.
Paul.