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

Rest Client Reactive - Filters not executed for non-successful return codes #16702

Closed
michalszynkiewicz opened this issue Apr 21, 2021 · 18 comments
Assignees
Labels
area/rest-client kind/bug Something isn't working

Comments

@michalszynkiewicz
Copy link
Member

CC @geoand I will try to attach a minimal reproducer tomorrow

@michalszynkiewicz michalszynkiewicz added the kind/bug Something isn't working label Apr 21, 2021
@geoand
Copy link
Contributor

geoand commented Apr 21, 2021

That would be great, thanks.

I'm actually very surprised the JAX-RS TCK doesn't test this...

@michalszynkiewicz
Copy link
Member Author

AFAIR the MicroProfile TCK tests this by returning an erroneous response from a filter, maybe JAX-RS one does it this way too?

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

Not sure TBH.

BTW, reading https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/reactive.20server.20.26.20client it seems like that issue was about ResponseExceptionMapper classes, but this issue is about ClientResponseFilter. Is that intentional?

Is ResponseExceptionMapper handled properly by the new REST Client?

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

Ah, now I see how it works.

So basically the rest-client engages ResponseExceptionMapper by implementing a ClientResponseFilter, so the problem is actually that ClientResponseFilter is not executed when an exception is thrown.

@michalszynkiewicz
Copy link
Member Author

Running the test from the example project you can see that the ClientResponseCompleteRestHandler is throwing an exception.

I think the exception could be thrown later, in ClientResponseCompleteRestHandler and not in ClientSetResponseEntityRestHandler if the status code is wrong.
Or maybe we could set the checkSuccessfulFamily to false for rest client? I'm not sure what's the best approach.

@michalszynkiewicz
Copy link
Member Author

changing how rest client reactive handles ResponseExceptionMapper is also an option :)

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021 via email

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

In https://github.com/geoand/quarkus/tree/%2316702 I made the ClientResponseFilter part of the abort handling chain, however the JAX-RS TCK did not pass (there was a test that failed with a NPE because it expected the HTTP status to be set).

Moreover, even with this change in place, the reproducer does not engage the MyResponseExceptionMapper.
So it looks like some other strategy will be needed to handle ResponseExceptionMapper.

Finally, in this specific, it doesn't really make sense IMHO to have ResponseExceptionMapper as the there was no response from the server - processing fails with java.net.UnknownHostException: restcountries.eu3: Name or service not known

So @michalszynkiewicz it's really up to you how you want to proceed on the MP REST Client. We can certainly make changes to the JAX-RS Client, but we still need to pass the TCK

@michalszynkiewicz
Copy link
Member Author

For unknown host, I agree, we should fail as we do now, I think.

I don't fully follow what happened in the jax-rs test, tried looking at it in the browser and it is not easy to follow :D

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

The spec isn't clear on whether or not ClientResponseFilter should be executed when there is an exception or not and the NPE in failing test isn't exactly indicative.

Does the old rest-client depend on this behavior?

@michalszynkiewicz
Copy link
Member Author

michalszynkiewicz commented Apr 22, 2021

Classic RestEasy uses a ClientResponseFilter for exception mapping:
https://github.com/resteasy/Resteasy/blob/main/resteasy-client-microprofile-base/src/main/java/org/jboss/resteasy/microprofile/client/ExceptionMapping.java

Does this answer your question?

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

OK, I guess then that I'll just disable the failing TCK test and open a PR.
But like I said, it won't be enough to fix the original problem, as it seems like the new rest-client does not register MyResponseExceptionMapper .
That you'll have to look into

@michalszynkiewicz
Copy link
Member Author

have you checked with the project I attached or the one the reporter provided? The latter was missing @RegisterProvider(...) on the client side IIRC

@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

Yes, I enabled that and still the mapper never seems to be engaged

geoand added a commit to geoand/quarkus that referenced this issue Apr 22, 2021
This doesn't seem to be specified by the spec or properly tested in the TCK
(I actually had to disable a single test that threw a NPE), but it does
seem to be what RESTEasy does

Relates to: quarkusio#16702
@geoand
Copy link
Contributor

geoand commented Apr 22, 2021

Here it is: #16731

geoand added a commit to geoand/quarkus that referenced this issue Apr 22, 2021
This doesn't seem to be specified by the spec or properly tested in the TCK
(I actually had to disable a single test that threw a NPE), but it does
seem to be what RESTEasy does

Relates to: quarkusio#16702
@michalszynkiewicz
Copy link
Member Author

I'll see why the exception mapper is not triggered tomorrow.

@michalszynkiewicz
Copy link
Member Author

michalszynkiewicz commented Apr 23, 2021

@geoand, programmatically registered exception mapper works with your changes :)

I'll try to create a fix for mappers registered with @RegisterProvider today

michalszynkiewicz added a commit that referenced this issue Apr 23, 2021
Execute ClientResponseFilter as part of the abort chain in JAX-RS Client
@geoand
Copy link
Contributor

geoand commented Apr 23, 2021

Cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants