Skip to content

Conversation

@rnetuka
Copy link
Contributor

@rnetuka rnetuka commented May 23, 2018

JIRA: https://issues.jboss.org/browse/RESTEASY-1865

dispatcher.getRegistry().addSingletonResource(...) works for ResourceMethodInvoker (returned object is the proper singleton), but not for resourceContext.getResource(...). Here, the object being returned is simply constructed one by ResteasyProviderFactory using a constructor.

obj = factory.createResource(request, response, this);
}
else
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've not indented the else branch as it would have caused very confusing diff

@dansiviter
Copy link

dansiviter commented May 23, 2018

Would this be OK for other implementations of ResourceFactory other than SingletonResource? I know I'm changing the scope here, but I'd envisage that issue will come up. Can we not refer back to the main mechanism for creating/accessing resources?

@rnetuka
Copy link
Contributor Author

rnetuka commented May 24, 2018

@dansiviter This solution works and was tested for SingletonResource only. To have more generic solution, I advice to create it as a complex enhancement since we don't have any more relevant test cases.provided by the bug reporter.

*/
public <T> T injectedInstance(Class<? extends T> clazz, HttpRequest request, HttpResponse response)
{
Constructor<?> constructor = PickConstructor.pickSingletonConstructor(clazz);
Copy link
Member

Choose a reason for hiding this comment

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

The creation of the Constructor object should be moved within else part of the if you added below, shouldn't it?

@asoldano asoldano added the main label May 25, 2018
@rnetuka rnetuka force-pushed the register-singleton branch from 6dd43f9 to 1287f43 Compare June 4, 2018 11:26
@rnetuka
Copy link
Contributor Author

rnetuka commented Jun 4, 2018

@asoldano Done

Copy link
Member

@asoldano asoldano left a comment

Choose a reason for hiding this comment

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

I'm changing the review, as I've just noticed that there's a regression in unit tests; @rnetuka , can you have a look please?

@rnetuka rnetuka force-pushed the register-singleton branch 3 times, most recently from 66adf1c to 78f4e7e Compare July 18, 2018 15:00
@rnetuka rnetuka force-pushed the register-singleton branch from 78f4e7e to d4024f5 Compare July 18, 2018 15:04
@rnetuka
Copy link
Contributor Author

rnetuka commented Jul 18, 2018

Fixed. Please, review again. Particulary this line:
https://github.com/resteasy/Resteasy/pull/1520/files#diff-be425f1e75ab8a4f6b0a674dcc8d5136R2647

(within changed files)
ResteasyProviderFactory
obj = factory.createResource(request, response, this).toCompletableFuture().getNow(null);

@asoldano
Copy link
Member

@rnetuka thanks, sorry for the late reply, I've been on PTO and then catching up. I don't see problems in the line that you mentioned. Now that I think more about this PR, though, I'm thinking that the hashmap you're adding should be made a thread safe... WDYT?

@ronsigal
Copy link
Collaborator

Hi @rnetuka,

I don't see anything in the JAX-RS spec (2.0 or 2.1) that suggests that the resource returned by ResourceContext.getResource() should be any particular iinstance. The javadoc says

Get a resolved instance of a resource or sub-resource class.

[My bold emphasis.] Could you elaborate?

-Ron

@ronsigal
Copy link
Collaborator

Hi @rnetuka, there are a couple of outstanding questions here. Any thoughts?

@rsearls
Copy link
Contributor

rsearls commented Nov 26, 2019

Hi @rnetuka,
Please rebase again.
@ronsigal, Once rebased, this looks good to merge.

else root.addInvoker(classExpression, fullpath, locator);
}

if (rf instanceof SingletonResource) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @rnetuka,

I'm questioning whether this should be in

   protected void register(ResourceFactory rf, String base, ResourceClass resourceClass)
   {
      for (ResourceMethod method : resourceClass.getResourceMethods())
      {
         processMethod(rf, base, method);
      }
      for (ResourceLocator method : resourceClass.getResourceLocators())
      {
         processMethod(rf, base, method);
      }
   }

Otherwise, you'll be calling registerSingletonResource() for each method, no?

-Ron

@jamezp
Copy link
Contributor

jamezp commented Nov 29, 2022

Thank you for the contribution. We are cleaning up older PR's that seem to be stale. If you feel this is still an issue please feel free to re-open.

@jamezp jamezp closed this Nov 29, 2022
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.

6 participants