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

Port resteasy fix for sub-resources #42905

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

maxr2011-tech11
Copy link
Contributor

@maxr2011-tech11 maxr2011-tech11 commented Aug 30, 2024

@quarkus-bot
Copy link

quarkus-bot bot commented Aug 30, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)

This message is automatically generated by a bot.

@maxr2011-tech11 maxr2011-tech11 changed the title issue-42851: port resteasy fix for sub-resources Issue-42851: port resteasy fix for sub-resources Aug 30, 2024
Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for tackling this!

I'll leave this to @manovotn and @jamezp to review. I just added a trivial comment.

Also keep in mind that when all the changes have been done, we'll need the commits to be squashed.

Finally, having a test verifying the change would be nice

@geoand geoand changed the title Issue-42851: port resteasy fix for sub-resources Port resteasy fix for sub-resources Aug 30, 2024
@gsmet
Copy link
Member

gsmet commented Aug 30, 2024

I concur it would be very nice to have a test. You should be able to add one in the deployment module (and worst case in the corresponding integration-tests module).

@quarkus-bot

This comment has been minimized.

@maxr2011-tech11 maxr2011-tech11 force-pushed the fix-resteasy-client-subresources branch 4 times, most recently from e0f3a31 to f72a099 Compare September 2, 2024 07:24
@manovotn
Copy link
Contributor

manovotn commented Sep 2, 2024

@maxr2011-tech11 please try to add a test for this change. The resteasy-microprofile PR you linked also has one, so it should be a matter of mimicking that same scenario here in the deployment module of this extension.

Otherwise, it looks OK.

@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@maxr2011
Copy link

maxr2011 commented Sep 2, 2024

@manovotn just added the SubResourceTest to the deployment module of the resteasy-classic/resteasy-client extension. also I did rewrite it a bit to use the quarkus integrated rest client inside the internal quarkus junit module instead of the Arquillian extension which resteasy uses (not sure if this works out)

CC @geoand

@quarkus-bot

This comment has been minimized.

@maxr2011-tech11 maxr2011-tech11 force-pushed the fix-resteasy-client-subresources branch 2 times, most recently from 46843b3 to 9df0827 Compare September 2, 2024 21:22
@geoand geoand requested a review from manovotn September 3, 2024 07:31
@quarkus-bot

This comment has been minimized.

@maxr2011
Copy link

maxr2011 commented Sep 3, 2024

@geoand
@manovotn

The pipeline checks report, that there are some tests failing, specifically those where a rest client is involved, so it has to be something in the code. No idea what it could be since I am not that deeply into the implementation of the rest client, maybe you could have a look or involve someone who has more insights?

CC @stesie

@manovotn
Copy link
Contributor

manovotn commented Sep 3, 2024

@geoand @manovotn

The pipeline checks report, that there are some tests failing, specifically those where a rest client is involved, so it has to be something in the code. No idea what it could be since I am not that deeply into the implementation of the rest client, maybe you could have a look or involve someone who has more insights?

CC @stesie

First of all, the test you added doesn't pass.
You can run that easily locally by building quarkus and then running the test:

  • Fast build with - mvn -Dquickly -Dno-test-modules -Dskip.gradle.build=true -T 4C
  • Execute the test you added with - mvn clean test -Dtest=SubResourceTest -f extensions/resteasy-classic/resteasy-client/deployment/

From a quick glance, you forgot to register the exception mapper to the rest client builder. This affects two of the tests.
So instead of:

        try (final ClientRootResource rootResource = RestClientBuilder.newBuilder().baseUrl(url)
                .build(ClientRootResource.class)) {

You want to do:

        try (final ClientRootResource rootResource = RestClientBuilder.newBuilder().baseUrl(url)
                .register(TestExceptionMapper.class)
                .build(ClientRootResource.class)) {

@manovotn
Copy link
Contributor

manovotn commented Sep 3, 2024

@maxr2011-tech11 I've pushed a commit fixing the test since I already had it locally.

I also added @Unremovable to the exception mapper - if it is supposed to be a bean (which I don't know?) you will need that as otherwise Quarkus will sweep it away as unused because it has no direct injection points.
Without the annotation, you can see a CDI warning in the output where some internals attempt to resolve it but fail.

@maxr2011-tech11 maxr2011-tech11 force-pushed the fix-resteasy-client-subresources branch 6 times, most recently from 1b7adff to 733c938 Compare September 4, 2024 10:56
@maxr2011
Copy link

maxr2011 commented Sep 4, 2024

@manovotn Just finalized the pull-request and fixed the issue inside the QuarkusProxyInvocationHandler:createProxy method to work correctly for the QuarkusRestClientBuilder, also cleaned up the Test.

-> Pipeline Checks should now be passing

CC @geoand @stesie

@geoand
Copy link
Contributor

geoand commented Sep 4, 2024

I have launched CI

@manovotn
Copy link
Contributor

manovotn commented Sep 4, 2024

@manovotn Just finalized the pull-request and fixed the issue inside the QuarkusProxyInvocationHandler:createProxy method to work correctly for the QuarkusRestClientBuilder, also cleaned up the Test.

-> Pipeline Checks should now be passing

CC @geoand @stesie

Right, I was just looking into it.
I do have a silly question though - what is the difference between the test you are using now and the original one you added? You are no longer using QuarkusRestClientBuilder API. Does that make a difference?

Also, running the test locally I am seeing the following logged (which may or may not be due to how the test is written, looking into that):

2024-09-04 13:17:43,223 WARN [org.jbo.res.res.i18n] (main) RESTEASY002160: Provider instance io.quarkus.restclient.exception.SubResourceTest$TestExceptionMapper is already registered. 2nd registration is being ignored.

@maxr2011-tech11 maxr2011-tech11 force-pushed the fix-resteasy-client-subresources branch 2 times, most recently from b9ce6d3 to 15f6a36 Compare September 4, 2024 11:52
@maxr2011
Copy link

maxr2011 commented Sep 4, 2024

@manovotn Just finalized the pull-request and fixed the issue inside the QuarkusProxyInvocationHandler:createProxy method to work correctly for the QuarkusRestClientBuilder, also cleaned up the Test.
-> Pipeline Checks should now be passing
CC @geoand @stesie

Right, I was just looking into it. I do have a silly question though - what is the difference between the test you are using now and the original one you added? You are no longer using QuarkusRestClientBuilder API. Does that make a difference?

Also, running the test locally I am seeing the following logged (which may or may not be due to how the test is written, looking into that):

2024-09-04 13:17:43,223 WARN [org.jbo.res.res.i18n] (main) RESTEASY002160: Provider instance io.quarkus.restclient.exception.SubResourceTest$TestExceptionMapper is already registered. 2nd registration is being ignored.

Also to answer this one:
I was wrong, the QuarkusRestClientBuilder is used just like within the Annotations and is equivalent to
RestClientBuilder.newBuilder().baseUrl(url).build(ClientRootResource.class);

but is directly injected into here:

@RestClient
ClientRootResource clientRootResource;

Just found out during debugging. So it should work either way.

But if you want I can add additional tests that use the QuarkusRestClientBuilder instead of the Annotations (but I don't think that would be necessary, since also the other test classes in general prefer to use the Annotations)

@manovotn
Copy link
Contributor

manovotn commented Sep 4, 2024

Just found out during debugging. So it should work either way.

Yes, I also found that out through debugging.
I was just curious why you changed it :)

But if you want I can add additional tests that use the QuarkusRestClientBuilder instead of the Annotations (but I don't think that would be necessary, since also the other test classes in general prefer to use the Annotations)

Since we now know it is used in either approach, you can keep it as is.

Assuming the CI passes, I have no further issues with this PR but we should wait for @jamezp to take a look as well.

@quarkus-bot

This comment has been minimized.

}
}

public static class TestExceptionMapper implements ResponseExceptionMapper<TestException> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a CDI qualifying annotation?

Copy link

@maxr2011 maxr2011 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will annotate it as 'Singleton' since it is also registered as @Provider it should be fine either way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no annotation needed here but it doesn't really matter that it is present.

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 4, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 9161d88.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@manovotn
Copy link
Contributor

manovotn commented Sep 4, 2024

@maxr2011-tech11 thanks for contributing! 👍

@manovotn manovotn merged commit f371f9e into quarkusio:main Sep 4, 2024
30 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.16 - main milestone Sep 4, 2024
@gsmet gsmet modified the milestones: 3.16 - main, 3.14.3 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

classic resteasy-client: ensure sub-resources are also proxied
6 participants