Skip to content
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

Merged
merged 1 commit into from
Mar 7, 2019

Conversation

senivam
Copy link
Contributor

@senivam senivam commented Jul 19, 2018

Fixes issue #3796

Signed-off-by: Maxim Nesen maxim.nesen@oracle.com

Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
@senivam senivam requested a review from jansupol July 19, 2018 11:45
//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"));
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@m0mus m0mus left a comment

Choose a reason for hiding this comment

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

LGTM

@senivam senivam merged commit b84ec48 into eclipse-ee4j:master Mar 7, 2019
@mkarg
Copy link
Member

mkarg commented Mar 7, 2019

@senivam Thanks a lot for fixing this! :-)

@Conrad-T-Pino
Copy link

Conrad-T-Pino commented Aug 25, 2024

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)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants