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

WebSocket/CDI integration is broken in Jetty 10 #6106

Closed
rdicroce opened this issue Mar 25, 2021 · 2 comments
Closed

WebSocket/CDI integration is broken in Jetty 10 #6106

rdicroce opened this issue Mar 25, 2021 · 2 comments
Assignees

Comments

@rdicroce
Copy link

Jetty version
10.0.1

Java version
11.0.8

OS type/version
Windows 10 Pro 20H2

Description
Classes annotated with @ServerEndpoint do not receive CDI integration. You can reproduce the problem easily by upgrading https://github.com/jetty-project/embedded-jetty-weld to Jetty 10. The code needs a few tweaks since some things were moved around, but after that's fixed, you'll notice that TimeSocket blows up due to a NPE because the logger hasn't been injected. After digging around in the code a bit, the cause appears to be that nothing ever calls the ObjectFactory to decorate the actual endpoint class.

Workaround: specify a Configurator on the @ServerEndpoint. However, this does not work:

	@Override
	public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
		return CDI.current().select(endpointClass).get();
	}

At least, it doesn't work if you're using Weld and the endpoint class is ApplicationScoped. In that case, Weld will return a proxy subclass, which creates a problem in JavaxWebSocketServerFrameHandlerFactory#getMetadata() because it looks for @ServerEndpoint but that annotation is not @Inherited. Therefore the annotation is not found and the configuration is ignored.

Instead, this works, if all you need is injection:

	@Override
	public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
		return new Unmanaged<>(endpointClass).newInstance().produce().inject().get();
	}
lachlan-roberts added a commit that referenced this issue Mar 31, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Mar 31, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Apr 6, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Apr 6, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Apr 6, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Apr 14, 2021
…t upgrade.

Decoration should not be delayed until onOpen it should be during the call to
the WebSocketUpgradeFilter or WebSocketServlet.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Apr 30, 2021
Issue #6106 - Fix WebSocket/CDI integration in Jetty 10
@lachlan-roberts
Copy link
Contributor

@rdicroce this issue is fixed by PR #6106, I have verified that https://github.com/jetty-project/embedded-jetty-weld now works if you run it against the current 10.0.x branch. This fix will be released in 10.0.3.

@rdicroce
Copy link
Author

@lachlan-roberts Thanks for the fix!

sbordet added a commit to cometd/cometd that referenced this issue May 24, 2021
…oject#6106.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants