Reputation: 21
can anyone tell me how i can customize http codes and reasonphrase in JBoss AS 7?
basically i have a REST webservice that returns a nonstandard status code '499' with reasonphrase 'app error'
In standalone.xml
, I set the org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER
to true
under systemproperties
, but AS still overrides the HTTP error message.
Upvotes: 2
Views: 941
Reputation: 663
There seems to be a mistake in JBoss documentation, the correct property name is:
org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER
So in the standalone you should have something like this:
<system-properties>
<property name="org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER" value="true"/>
</system-properties>
Upvotes: 1
Reputation: 46836
I assume that the REST service is interpretted using RestEasy.
That provides a nice feature of injecting a HTTP response object using @Context:
The @Context annotation allows you to inject instances of javax.ws.rs.core.HttpHeaders, javax.ws.rs.core.UriInfo, javax.ws.rs.core.Request, javax.servlet.HttpServletRequest, javax.servlet.HttpServletResponse, javax.servlet.ServletConfig, javax.servlet.ServletContext, and javax.ws.rs.core.SecurityContext objects.
@Path("/")
public class MyService {
@Context org.jboss.resteasy.spi.HttpResponse response;
@GET @Path("/") public void myMethod(){
response.sendError(499, "The file was censored by NSA.")
}
}
But maybe you should rather consider using a proprietary HTTP header:
response.getOutputHeaders().putSingle("X-MyApp-Error",
"499 Our server is down and admin is on holiday. Mañana.");
Upvotes: 0