mdzh
mdzh

Reputation: 1050

JAX-RS how to handle wrong content-type

I have a REST service with a @POST method which @Consumes("application/xml)".

However, if I make a POST request from my browser and I don't add

Content-Type: application/xml

header to the request, I get an exception in my jboss

Failed executing POST : org.jboss.resteasy.spi.UnsupportedMediaTypeException: Cannot consume content type

How is my servlet supposed to handle such cases?

Upvotes: 0

Views: 1072

Answers (1)

John Ament
John Ament

Reputation: 11723

You can implement an ExceptionMapper for the UnsupportedMediaTypeException and choose to handle it however you wish. You're seeing this exception because you don't have a handler for it and resteasy is doing its out of the box handling.

Upvotes: 1

Related Questions