I have a REST API Controller built using Quarkus RestEasyReactive
@Path("/hello")
public class HelloController {
@GET
@Produces({"application/json"})
public RestResponse<Greeting> greet(@Min(0) @RestQuery int value) {
return new Greeting("Hello" + value);
}
}
When I send following request, http://localhost:8080/hello?value=
Quarkus returns 404 Not Found
Error.
Investing Quarkus Implementation for RestEasy I found following code in ParameterHandler
if (defaultValue != null
&& (result == null || (isCollection && ((Collection) result).isEmpty()))) {
result = defaultValue;
}
Throwable toThrow = null;
if (converter != null && ((result != null) || isOptional)) {
// spec says:
/*
* 3.2 Fields and Bean Properties
* 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; if the field or property is annotated with @HeaderParam or @CookieParam then an implementation
* MUST generate an instance of BadRequestException (400 status) that wraps the thrown exception and
* no entity.
* 3.3.2 Parameters
* Exceptions thrown during construction of @FormParam annotated parameter values are treated the same as if
* the parameter were annotated with @HeaderParam.
*/
switch (parameterType) {
case COOKIE:
case HEADER:
case FORM:
try {
result = converter.convert(result);
} catch (WebApplicationException x) {
toThrow = x;
} catch (Throwable x) {
log.debug("Unable to handle parameter", x);
toThrow = new BadRequestException(x);
}
break;
case MATRIX:
case PATH:
case QUERY:
try {
result = converter.convert(result);
} catch (WebApplicationException x) {
toThrow = x;
} catch (Throwable x) {
log.debug("Unable to handle parameter", x);
toThrow = new NotFoundException(x);
}
break;
Based on the above code, result variable is blank and the converter which is an Integer converter tries to convert blank value to integer and throws exception.
One of the workaround could be that I convert all my query parameter definition as string and type cast to Integer in the code which doesn't seem to be that efficient from design perspective.
Is there anything in Quarkus to override this behavior or is there something wrong in my understanding in the way this scenario should be handled?