Difference between JAX-RS and Spring Rest

JAX-RS JAX-RS is a specification for implementing REST web services in Java, currently defined by the JSR-370. It is part of the Java EE technologies, currently defined by the JSR 366. Jersey (shipped with GlassFish and Payara) is the JAX-RS reference implementation, however there are other implementations such as RESTEasy (shipped with JBoss EAP and … Read more

JAX-RS / Jersey how to customize error handling?

There are several approaches to customize the error handling behavior with JAX-RS. Here are three of the easier ways. The first approach is to create an Exception class that extends WebApplicationException. Example: public class NotAuthorizedException extends WebApplicationException { public NotAuthorizedException(String message) { super(Response.status(Response.Status.UNAUTHORIZED) .entity(message).type(MediaType.TEXT_PLAIN).build()); } } And to throw this newly create Exception you simply: … Read more

What’s the difference between text/xml vs application/xml for webservice response

From the RFC (3023), under section 3, XML Media Types: If an XML document — that is, the unprocessed, source XML document — is readable by casual users, text/xml is preferable to application/xml. MIME user agents (and web user agents) that do not have explicit support for text/xml will treat it as text/plain, for example, … Read more