Skip to main content

JAX-RS (Jersey) Custom Reason Phrase (not working)

1 reply [Last post]
acidblue
Offline
Joined: 2003-06-13
Points: 0

I want to have a custom reason phrase in my HTTP response. Instead of "400 Bad Request" I want to have a 400 "ValidationFailed" (or whatever). The issue I have is that I have set a custom response in a WebApplicationException with something like this (sorry for the formatting, just how does one keep code formatted on this application?):

throw new WebApplicationException(Response
.status(new Response.StatusType() {
public int getStatusCode() {
return 400;
}

public Response.Status.Family getFamily() {
return Response.Status.Family.CLIENT_ERROR;
}

public String getReasonPhrase() {
return "ValidationFailed";
}
})
.type(resolveContent())
.entity(someEntity)
.build());

The issue is that I have a 400 response code showing up as I expected, but my reason phrase is still "Bad Request". What could I be doing wrong?

Thanks for you time.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
acidblue
Offline
Joined: 2003-06-13
Points: 0

BTW, I have done some googling but found issues regarding this from 2008. So, not sure if they have been addressed.