[ 
https://issues.apache.org/jira/browse/CXF-4976?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13636833#comment-13636833
 ] 

Sergey Beryozkin commented on CXF-4976:
---------------------------------------

I'm afraid this is a won't fix issue as it is a spec compliant status 
reporting, for example, from the JAX-RS 2.0 PFD, section 3.2: 

"if the field or property is annotated with
@MatrixParam, @QueryParam or @PathParam then an implementation MUST generate an 
instance of
NotFoundException (404 status) that wraps the thrown exception and no entity
"

Similarly in 1.1 spec.

I kind of see where are you coming from, you know that the query parameter must 
be of integer type, so it is 400 as far as the server processing is concerned. 
On the other hand, given that this query parameter is within the URI, from the 
client perspective we are talking about a specific application state reference, 
and thus /?id=notparseable simply points to a piece of state which is not 
available, 404 in other words.

Please do not hesiate to open a JAX-RS spec JIRA if you feel strongly about it 
:-) 

                
> QueryParam of type Integer produces 404 when param value not parsable as 
> Integer
> --------------------------------------------------------------------------------
>
>                 Key: CXF-4976
>                 URL: https://issues.apache.org/jira/browse/CXF-4976
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.6.3
>            Reporter: Sebastien Lorber
>            Priority: Minor
>
> Hello,
> My JAXRS resource is:
> {code:java}
> public Response listSafe(
>           @QueryParam("index") Integer paginateIndex,
>           @QueryParam("max_results") Integer paginateSize) {
>     return something...;
>   }
> {code}
> When querying this resource with: ws?index=0&max_results=10
> It works fine.
> But when querying this resource with: 
> ws?index=0&max_results=anyUnparsableString
> I get a 404 error.
> The expected behaviour would rather be a 400 error.
> I guess this may only affect the Integer type, and not int type.
> These values are optional for my service.
> The CXF code involved seems to be here:
> org.apache.cxf.jaxrs.utils.HttpUtils#getParameterFailureStatus
> {code:java} 
>     public static Response.Status getParameterFailureStatus(ParameterType 
> pType) {
>         if (pType == ParameterType.MATRIX || pType == ParameterType.PATH
>             || pType == ParameterType.QUERY) {
>             return Response.Status.NOT_FOUND;
>         }
>         return Response.Status.BAD_REQUEST;
>     }
> {code} 
> It seems an unparsable attribute is considered like any other parameter 
> failure (like missing parameter?).
> The workaround that works for me is to declare an IntegerHandler:
> {code:java} 
>   @Override
>   public Integer fromString(String s) {
>     try {
>       return Integer.parseInt(s);
>     } catch ( NumberFormatException e ) {
>       throw new IntegerValueException();
>     }
>   }
> {code}
> And use a mapper for this exception, to return a 400 error.
> This would be nice to have 400 error too for boolean parsing, because using 
> valueOf will return false instead of error 400 for a booleanParam="anyString 
> "too.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to