How to handle requests with unsupported content type correctly?
I have a REST interface build with Jersey. Actually I only support as
content type only application/json for all incoming requests. That is why
I defined my message body reader and writer as
@Provider
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class MarshallerProvider
implements MessageBodyReader<Object>, MessageBodyWriter<Object>
{
}
Now I wrote a test where I try to get a document via GET and expected
content type application/xml. Jersey answers this request with an
MessageBodyProviderNotFoundException.
So what would be the best way to handle such unsupported requests
correctly? Should I write an exception mapper? Since it is an internal
exception I don't like this approach?
The solution should allow my to return an HTTP 415 (Unsupported Media Type).
No comments:
Post a Comment