cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebastien Lorber (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CXF-4976) QueryParam of type Integer produces 404 when param value is not an parsable
Date Fri, 19 Apr 2013 15:11:15 GMT
Sebastien Lorber created CXF-4976:
-------------------------------------

             Summary: QueryParam of type Integer produces 404 when param value is not an parsable
                 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

Mime
View raw message