简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM