users@jersey.java.net

Re: [Jersey] Why do IllegalArgumentExceptions cause a 404 instead of a 400?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 17 Aug 2009 10:45:05 +0200

Hi,

I have fixed this in the trunk:

   https://jersey.dev.java.net/issues/show_bug.cgi?id=350

So you can do this:

   public class MyQueryParamMapper implements
ExceptionMapper<QueryParamException> {
     public Response toResponse(QueryParamException ex) {
       return
Response.fromResponse(ex.getResponse()).status(400).build();
     }
   }

The parameter name and default value are available from
QueryParamException, but not currently the String value(s), perhaps
we should include that as well?

I think we should also review other WebApplicationException thrown by
the runtime and classify them. For example the message body readers/
writers:

   public class ReaderWriterException extends WebApplicationException {
   }

   public class ReaderException extends ReaderWriterException {
   }

   public class WriterException extends ReaderWriterException {
   }

Paul.

On Aug 15, 2009, at 10:29 AM, Paul Sandoz wrote:

>
> On Aug 14, 2009, at 10:00 PM, DirkM wrote:
>
>>
>>
>> Paul Sandoz wrote:
>>>
>>> The EG opted for a 404 when extracting parameters from URI because
>>> strictly speaking if a String cannot be converted to say Integer
>>> then
>>> it is a matching error with the URI.
>>>
>>
>> Thanks for the quick response Paul.
>>
>> I guess you could look at it that way, but it seems quite
>> unintuitive to me
>> as a web developer, as opposed to someone initiated with the
>> details of the
>> JAX-RS standard.
>>
>> The http://www.ietf.org/rfc/rfc2616.txt HTTP standard states:
>> 10.4.1 400 Bad Request
>>
>> The request could not be understood by the server due to malformed
>> syntax. The client SHOULD NOT repeat the request without
>> modifications.
>>
>
> Yes. Originally we returned a 400 for all parameters then we changed
> it for Path, Matrix and Query parameters. But I can see the latter
> going either way.
>
> I do not think you can rely on IllegalArgumentException as the cause
> in WebApplcationException in all cases. I think the ExceptionMapper
> is an appropriate location to modify the default behavior but what
> we require is something like a ParameterProcessingException that
> extends WebApplcationException. The ParameterProcessingException
> would contain the type of the parameter, then you can map this
> exception.
>
> Could you log an issue. I will work on it.
>
> Thanks,
> Paul.
>
>>
>> --
>> View this message in context: http://n2.nabble.com/Why-do-IllegalArgumentExceptions-cause-a-404-instead-of-a-400--tp3447019p3447207.html
>> Sent from the Jersey mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>