users@jersey.java.net

Re: [Jersey] ExceptionMapping - 500 or still no message

From: Daniel Manzke <daniel.manzke_at_googlemail.com>
Date: Fri, 21 May 2010 10:04:14 +0200

Hi Paul,

the responses of you and Marc were catched by GMail Spamfilter... :)

I'll have a look at it. At the moment it seems, that one of my servletfilter
didn't used Response.sendError. For Status-Codes > 500 I see the Error-Page
with Message and everything filled.



Thanks so far,
Daniel

2010/4/14 Paul Sandoz <Paul.Sandoz_at_sun.com>

> Hi Daniel,
>
> What version of Jersey are you using?
>
> Note that JSP error pages will only work if no response has been written.
>
> Would it be possible to send me a test web app exercising all the cases you
> describe? that way there will be no ambiguity in what you describe. And it
> will help me work out what we could do in terms of passing information to
> the error page.
>
>
> There is one case that may be causing some confusion. When an instance of
> WebApplicationException is thrown and
>
> - that exception is not mapped
> - the status code is 500
> - there is no entity present
>
> then Jersey will modify the response to contain the stack trace as the
> response entity.
>
> if (!mapped) {
> // Log the stack trace
> if (r.getStatus() >= 500 || request.isTracingEnabled()) {
> traceException(e, r);
> }
>
> if (r.getStatus() >= 500 && r.getEntity() == null) {
> // Write out the exception to a string
> StringWriter sw = new StringWriter();
> PrintWriter pw = new PrintWriter(sw);
> e.printStackTrace(pw);
> pw.flush();
>
> r = Response.status(r.getStatus()).entity(sw.toString()).
> type(MediaType.TEXT_PLAIN).build();
> }
> } else if (request.isTracingEnabled()) {
> traceException(e, r);
> }
>
> I think Jersey is in error here when it modifies the response.
>
> Often it is not recommended to present an error page with a stack trace for
> a public service as it can be a security risk. But this is something useful
> for development purposes. Including the stack trace as a response header
> could an option (although i dunno if this will result in length limits being
> reached for headers).
>
> Paul.
>
>
>
> On Apr 14, 2010, at 3:38 PM, Daniel Manzke wrote:
>
> Hi,
>>
>> I developed a Service with the help of JAX-RS and I'm fighting a little
>> bit with the Exception handling. I searched through the Mail-List and saw
>> that there was some similiar problem and it was fixed. Maybe I'm just doing
>> something wrong. ;)
>>
>>
>> I saw that when I'm using the WebApplicationException and just passing a
>> Status, I'll get the error page with the right code, but it's not possible
>> to write something in the message field.
>> So I created a Exception which inherits from WebApplicationException and
>> wraps up my thrown Exceptions. The Stacktrace will be displayed, but not the
>> Error-Page.
>>
>> So I did the next try with the ExceptionMapper. This will end in an
>> Error-Page with 500 and the "root causes" message, but the passed StatusCode
>> is ignored.
>>
>>
>>
>> What I want to do?
>> - throw a Exception with a Status Code
>> - display the Error-Page with the right Status Code and the Stacktrace
>>
>>
>> Any idea?
>>
>>
>> Thanks,
>> Daniel :)
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>


-- 
Mit freundlichen Grüßen
Daniel Manzke