Unfortunately, when I try to access the methods in the EJB without being properly authorized, I received a 500 BadRequest. Instead I would really like to have a 401 Unauthorized.
I posted a question on StackOverflow1, but I have found the solution2 in the mean time, which I also posted, and will repost here.
It is possible to add an ExceptionMapper to your Application, which can map between an Exception and an appropriate HTTP Response.
Note
My ApplicationConfig has now been expanded with aresources.add(mmud.exceptions.EJBAccessExceptionMapper.class);
.References
- [1] StackOverflow - REST-EJB AccessLocalException causes BadRequest(500) instead of Unauthorized(401)
- https://stackoverflow.com/questions/44351224/rest-ejb-accesslocalexception-causes-badrequest500-instead-of-unauthorized401
- [2] RESTful Java with JAX-RS 2.0 (Second Edition) - Exception Handling
- https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/en/part1/chapter7/exception_handling.html
- StackOverflow -
- https://stackoverflow.com/questions/3297048/403-forbidden-vs-401-unauthorized-http-responses
No comments:
Post a Comment