How should I log uncaught exceptions in my RESTful JAX-RS web service?

For lack of a better way to implement logging for uncaught JAX-RS exceptions, using a catch-all ExceptionMapper as in Other Ideas: #1 seems to be the cleanest, simplest way to add this functionality. Here’s my implementation: @Provider public class ThrowableExceptionMapper implements ExceptionMapper<Throwable> { private static final Logger log = Logger.getLogger(ThrowableExceptionMapper.class); @Context HttpServletRequest request; @Override public … Read more

How to set response header in JAX-RS so that user sees download popup for Excel?

You don’t need HttpServletResponse to set a header on the response. You can do it using javax.ws.rs.core.Response. Just make your method to return Response instead of entity: return Response.ok(entity).header(“Content-Disposition”, “attachment; filename=\”” + fileName + “\””).build() If you still want to use HttpServletResponse you can get it either injected to one of the class fields, or … Read more

Encoded slash (%2F) with Spring RequestMapping path param gives HTTP 400

for spring-boot, the following did the trick @SpringBootApplication public class Application extends WebMvcConfigurerAdapter { public static void main(String[] args) throws Exception { System.setProperty(“org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH”, “true”); SpringApplication.run(Application.class, args); } @Override public void configurePathMatch(PathMatchConfigurer configurer) { UrlPathHelper urlPathHelper = new UrlPathHelper(); urlPathHelper.setUrlDecode(false); configurer.setUrlPathHelper(urlPathHelper); } }