Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4976

QueryParam of type Integer produces 404 when param value not parsable as Integer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Invalid
    • 2.6.3
    • Invalid
    • JAX-RS
    • None
    • Unknown

    Description

      Hello,

      My JAXRS resource is:

      public Response listSafe(
                @QueryParam("index") Integer paginateIndex,
                @QueryParam("max_results") Integer paginateSize) {
          return something...;
        }
      

      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

       
          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;
          }
      

      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:

       
        @Override
        public Integer fromString(String s) {
          try {
            return Integer.parseInt(s);
          } catch ( NumberFormatException e ) {
            throw new IntegerValueException();
          }
        }
      

      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.

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            sebastienlorber Sebastien Lorber
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: