I'm trying to follow the Jersey docs to enable a non-200 response if an error occured (https://jersey.java.net/documentation/latest/representations.html#d0e3586)
My code looks like :
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public ResponseBuilder getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
logger.error("Missing params for getData");
throw new WebApplicationException(501);
}
return Response.ok();
}
}
This unfortunately yields the following error :
[2015-02-01T16:13:02.157+0000] [glassfish 4.1] [SEVERE] [] [org.glassfish.jersey.message.internal.WriterInterceptorExecutor] [tid: _ThreadID=27 _ThreadName=http-listener-1(2)] [timeMillis: 1422807182157] [levelValue: 1000] [[ MessageBodyWriter not found for media type=text/plain, type=class org.glassfish.jersey.message.internal.OutboundJaxrsResponse$Builder, genericType=class javax.ws.rs.core.Response$ResponseBuilder.]]
The problem is the return type of your method. It has to be Response
instead of ResponseBuilder
.
Change your code to the following and it should work:
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response getData(@FormParam("one") String one,@FormParam("two") String two,@FormParam("three") String three) {
if(one.isEmpty() || two.isEmpty() || three.isEmpty()) {
logger.error("Missing params for getData");
throw new WebApplicationException(501);
}
return Response.ok();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With