-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Make the method really search for the @Path annotation in the ancestor h... #90
Conversation
…r hierarchy. Without this fix it is not possible to register proxied beans created by Spring because the annotation is in the super class
|
Can one of the admins verify this patch? |
|
Use case: http://stackoverflow.com/questions/21104567/springjersey-transactional-annotation/24554236#24554236 This can be used as a workaround for issue https://java.net/jira/browse/JERSEY-2301 |
|
Hi Constantino, thank you for the patch. Can you, please, include a test as well? Also, please, change the copyright year to 2013-2014. In order to be able to accept your contribution, we need you to sign Oracle Contributor Agreement (OCA). You can find more details here: https://jersey.java.net/scm.html#/Submitting_Patches_and_Contribute_Code Michal |
|
Hi, |
|
Jenkins, please test this patch. |
|
I saw the test failed, but it is giving errors in the last 4 builds, so most likely the problem was introduced at that time. The error is related with some ports not being available: either it is trying to run 2 tests that use the same port in parallel or another build in the same machine is interfering with Jersey build. |
|
The errors are: org.glassfish.jersey.test.spi.TestContainerException: java.net.BindException: Address already in use |
|
Jenkins, retest this patch. |
|
Verified manually. We'll merge this pull request once we get confirmation about your OCA. |
|
Hi, |
|
Jenkins, retest this patch. |
Make the method really search for the @path annotation in the ancestor h...
|
Thank you for your contribution, I just merged your pull request. |
|
Hi there, I found this fix by Googling about a different but probably related problem of jersey-spring3. After hours of time debugging, I concluded that my I tried with Jersey everything 2.19, Spring everything 4.1.6. Thank you! |
|
Hi, That was exactly the use case I had. The workaround I used was to let Spring create the beans and register them on Jersey after the proxy is created. When I first implemented this I had to fix another problem in Jersey, but now the fix is already integrated on the latest release, so it should work the way I described above. Let me know if you have further questions. Regards, Constantino Enviado do Yahoo Mail no Android De:"Bagana" notifications@github.com Hi there, I found this fix by Googling about a different but probably related problem of jersey-spring3. After hours of time debugging, I concluded that my @Context-annotated fields in Jersey resource and filter classes are ignored once I apply a Spring @transactional on them. So I suspected that could it be Spring providing sub-classed instances to Jersey, and jersey didn't search the super classes for @context annotation. I checked the diff of this fix but @context seems to be handled somewhere else. I'm not familiar with Spring internal, nor with Jersey's. Can anyone give me some direction? I tried with Jersey everything 2.19, Spring everything 4.1.6. Thank you! — |
|
Thanks for the reply and the idea, @ccronemberger. I came up with this solution: // "static", as long as it's singleton, should be fine.
// @Component makes it singleton anyway.
private static ResourceInfo resourceInfo;
// "final", so it won't be overridden by Spring (cglib).
// prints a warning message, though. (INFO level)
@ Context
public final void setResourceInfo( final ResourceInfo info) {
resourceInfo = info;
}
@ Override
public void filter( final ContainerRequestContext request) throws IOException {
resourceInfo.getResourceMethod()...
...
}So far it seems working fine. I guess this would probably be a better workaround, because if the problem should be solved in a future version, I only need to remove two key words. |
|
I'm afraid the solution in this patch is not correct. The JSR-339 specification in chapter 3.6 clearly states that annotations on a superclass take precedence over annotations on interfaces:
|
|
Yes, I understand that inheritance is supported only for methods and method parameters and not for classes. The patch is for classes, so it is clearly violating the spec. Besides disabling the fix it would be a good idea to add a comment to the code explaining why inheritance is not desirable in this case and ideally also explain why the spec states this. It would be nice to also have the test reworked so it can validate that it will not be implemented again. |
|
Hi, Marek was originally pointing out, that the search order is opposite than the specs requires. The other thing is, that the spec states that "inheritance of class or interface annotations is not supported". Well, if we should interpret that strictly, we would have to remove even the search in the interfaces already present before this patch. For now, we decided to interpret this statement more freely in the manner "this behaviour is neither specified, nor prohibited by the spec", so we just adjusted the patch so that it searches in the same order as specified for methods (superclasses first, interfaces if not found elsewhere). Your use case should still work and Jersey behaves at least in the spirit of the spec... Regards, |
...ierarchy. Without this fix it is not possible to register proxied beans created by Spring because the annotation is in the super class