java - How to catch 404 (NotFoundException) without being depndant on a JAX-RS implemenation? -
typically 1 uses exceptionmapper
grab exceptions, log them, homecoming customized error messages.
however while jax-rs provides notfoundexception
in api, implementations (jeresy, cxf,...) provide own notfoundexception (such com.sun.jersey.api.notfoundexception
) doesn't extends jax-rs one.
leaving sole alternative of having in our code implementation specific imports. makes hard if 1 wants switch implementations.
is there way this, avoid dependency on specific implementation?
"is there way this, avoid dependency on specific implementation?"
use newer vendor version, supports jax-rs 2.0.
the webapplicationexception hierarchy (i.e. javax.ws.rs.notfoundexception
included) wasn't introduced until 2.0, though webapplicationexception
has existed since 1.0. beingness said, below vendors , versions started using jax-rs 2.0
for prior releases, utilize webapplicationexception
wrap response/status, throw new webapplicationexception(response.status.not_found)
. map exception mapper, , getresponse().getstatus()
exception if needed check response status.
any jax-rs related exception, not thrown wrapped in webapplicationexception
, having mapper map webapplicationexception
should allow need. bit of hassle checks.
java exception-handling jax-rs
No comments:
Post a Comment