-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Jersey creates multiple provider instances if a class implements more than one #3888
Conversation
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
...y-3796/src/test/java/org/glassfish/jersey/tests/integration/jersey3796/Jersey3796ITCase.java
Show resolved
Hide resolved
//Map shall contain ony keys Feature, Request and Response | ||
//Values of that keys shall be equals. | ||
//Equality of all values indicates the class is only one per all tested providers | ||
Assert.assertEquals(response.get("Feature"), response.get("Request")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be really the same instance instead of simply equals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the purpose here is to check if 1 class is initialized only once (thus it's the only instance). To check that a map of strings is used. It is initialized along with a class and each provider method puts a record inside. Class implements 3 interfaces each interface has 1 method, so there are 3 records at the end. All 3 records shall be in 1 map. This indicates the class is initialized only once. If map contains less instances (and/or NPE exception is thrown when a method tries to put a record into the map) that indicates the contract is broken and class is initialized more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@senivam Thanks a lot for fixing this! :-) |
I'm suggesting not fixed in Jersey 2.35 nor 2.44. I'm logging in no argument constructor and see four (4) log entries; one for each implemented Contract.class for the first request but not thereafter. Ideally I wanted singleton state as class field in singleton instance. Logs suggest I must use static field to circumvent multiple instances. public class ClientCapture implements
ClientRequestFilter, ClientResponseFilter, ReaderInterceptor, WriterInterceptor {
public ClientCapture() {
super();
logger.info("ClientCapture()");
}
...
} 25-Aug-2024 15:02:24.978 INFO [pool-6-thread-1] tmms.rest.ClientCapture.<init> ClientCapture()
25-Aug-2024 15:02:24.978 INFO [pool-6-thread-1] tmms.rest.ClientCapture.<init> ClientCapture()
25-Aug-2024 15:02:24.982 INFO [pool-6-thread-1] tmms.rest.ClientCapture.<init> ClientCapture()
25-Aug-2024 15:02:24.983 INFO [pool-6-thread-1] tmms.rest.ClientCapture.<init> ClientCapture()
25-Aug-2024 15:02:25.078 INFO [pool-6-thread-1] tmms.rest.ClientCapture.filter (ClientRequestContext)
25-Aug-2024 15:02:25.090 INFO [pool-6-thread-1] tmms.rest.ClientCapture.aroundWriteTo (WriterInterceptorContext)
25-Aug-2024 15:02:25.785 INFO [pool-6-thread-1] tmms.rest.ClientCapture.filter (ClientRequestContext, ClientResponseContext)
25-Aug-2024 15:02:25.790 INFO [pool-6-thread-1] tmms.rest.ClientCapture.aroundReadFrom (ReaderInterceptorContext) |
Fixes issue #3796
Signed-off-by: Maxim Nesen maxim.nesen@oracle.com