Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientResponseFilter not called on UnknownHostException #684

Open
pavolloffay opened this issue Oct 23, 2018 · 9 comments
Open

ClientResponseFilter not called on UnknownHostException #684

pavolloffay opened this issue Oct 23, 2018 · 9 comments
Assignees
Labels
enhancement New feature or request spec

Comments

@pavolloffay
Copy link

pavolloffay commented Oct 23, 2018

At the moment there is no way how to intercept exceptions like UnknownHostException (maybe also RedirectionException) in ClientResponseFilter. Note that ClientRequestFilter is called for a such request. If the integration uses both filters and response filter is used to free up resources this leads to leaks.

@mkarg
Copy link
Contributor

mkarg commented Oct 23, 2018

I assume you meant to say Note that ClientRequestfilter is called for such a request.

Your approach is not specification compliant. According to JAX-RS 2.1 chapter 6.1 ...a ClientResponseFilter is executed upon receiving a server response.... In the case of UnknownHostException no response is actually received, hence it is obvious and correct that no response filter is invoked.

You need to attach your resources to the request object (as a request property), so they become eligible for GC once the request is cancelled. If this is not enough (e. g. too lazy), we need to extend a future version of the JAX-RS specification in a way that allows you to get an active callback on request cancellation. Is that what you strive for with this issue? In the end it would be solved by the proposal we already discussed shortly in a different thread: A custom Extension available on the client's Class-Path could be auto-discovered invoked before and and after talking HTTP, so it would be the right place to set up and tear down resources. But that was not wanted by some people, as we plan to add CDI SE support for JAX-RS 3.0 anyways.

@mkarg mkarg self-assigned this Oct 23, 2018
@mkarg mkarg added enhancement New feature or request spec labels Oct 23, 2018
@pavolloffay
Copy link
Author

Yes I meant ClientRequestfilter. I do not have a strong opinion how this should be done but I think jax-rs should provide an API to intercept all calls, even the failed ones.

we need to extend a future version of the JAX-RS specification in a way that allows you to get an active callback on request cancellation

Yes that is what I mean. We need a callback which is called always if the request filter was called.

I think we could go even further and have an interceptor per network attempt e.g. if the jax-rs supports redirects.

@mkarg
Copy link
Contributor

mkarg commented Oct 25, 2018

Understood and agreed. We just need to find a concensus whether it is enough to wait for CDI interception (3.x), or whether we have to invent our own technology before (2.x).

@najibk
Copy link

najibk commented Feb 23, 2022

Is there any known workarounds or implementation to achieve this ? I would also like to intercept i/o exceptions in a centralized manner.

@jansupol
Copy link
Contributor

Jersey supports a PostInvocationInterceptor that gathers the exceptions, including UnknownHostException. It is a proprietary solution, though.

Keep in mind that the MP REST Client will become a part of Jakarta REST and any changes in the client API should be compatible with it.

@najibk
Copy link

najibk commented Feb 23, 2022

thanks for your reply @jansupol,
my implementation is a RESTEasy client through quarkus so I can't use Jersey's solution unfortunately.

@jonatan-ivanov
Copy link

Hi,
Were there any updates on this? Can JAX-RS provide a similar mechanism to what Jersey has (see #684 (comment))?

@mkarg
Copy link
Contributor

mkarg commented Jun 1, 2024

Unfortunately I need to tell you that so far the vendors backing JAX-RS did not agree upon a cross-vendor API for this use case.

@jamezp @jansupol @jim-krueger WDYT?

@jamezp
Copy link
Contributor

jamezp commented Jun 4, 2024

I'm personally a +1 to waiting for the CDI integration to become defined so CDI interceptors can be used. That said, I don't see why you can't already use an interceptor as CDI, in containers at least, is supported.

If we're talking about a client side that runs outside of a container, I could see another API being useful. However, I think we need to decide what will happen with clients and CDI integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request spec
Projects
None yet
Development

No branches or pull requests

6 participants