Skip to content

Commit

Permalink
Add undertow 1.1.0.Final support
Browse files Browse the repository at this point in the history
Upgrade undertow dependency to 1.1.0.Final.
Add support for undertow 1.1.0.Final in the
UndertowRequestUpgradeStrategy, after a breaking change in the
`io.undertow.websockets.jsr.ConfiguredServerEndpoint` constructor.

Issue: SPR-12302
  • Loading branch information
bclozel committed Nov 24, 2014
1 parent 161d3e3 commit bb150c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -54,7 +54,7 @@ configure(allprojects) { project ->
ext.tiles3Version = "3.0.5"
ext.tomcatVersion = "8.0.15"
ext.tyrusVersion = "1.3.5"
ext.undertowVersion = "1.0.17.Final"
ext.undertowVersion = "1.1.0.Final"
ext.woodstoxVersion = "4.4.1"
ext.xstreamVersion = "1.4.7"

Expand Down
Expand Up @@ -28,19 +28,22 @@
import javax.websocket.Encoder;
import javax.websocket.Endpoint;
import javax.websocket.Extension;
import javax.websocket.server.ServerEndpointConfig;

import io.undertow.server.HttpServerExchange;
import io.undertow.server.HttpUpgradeListener;
import io.undertow.servlet.api.InstanceFactory;
import io.undertow.servlet.api.InstanceHandle;
import io.undertow.servlet.websockets.ServletWebSocketHttpExchange;
import io.undertow.util.PathTemplate;
import io.undertow.websockets.core.WebSocketChannel;
import io.undertow.websockets.core.WebSocketVersion;
import io.undertow.websockets.core.protocol.Handshake;
import io.undertow.websockets.jsr.ConfiguredServerEndpoint;
import io.undertow.websockets.jsr.EncodingFactory;
import io.undertow.websockets.jsr.EndpointSessionHandler;
import io.undertow.websockets.jsr.ServerWebSocketContainer;
import io.undertow.websockets.jsr.annotated.AnnotatedEndpointFactory;
import io.undertow.websockets.jsr.handshake.HandshakeUtil;
import io.undertow.websockets.jsr.handshake.JsrHybi07Handshake;
import io.undertow.websockets.jsr.handshake.JsrHybi08Handshake;
Expand All @@ -64,20 +67,38 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat

private static final Constructor<ServletWebSocketHttpExchange> exchangeConstructor;

private static final Constructor<ConfiguredServerEndpoint> endpointConstructor;

private static final boolean undertow10Present;

private static final boolean undertow11Present;

static {
Class<ServletWebSocketHttpExchange> type = ServletWebSocketHttpExchange.class;
Class<?>[] paramTypes = new Class<?>[] {HttpServletRequest.class, HttpServletResponse.class, Set.class};
if (ClassUtils.hasConstructor(type, paramTypes)) {
exchangeConstructor = ClassUtils.getConstructorIfAvailable(type, paramTypes);
Class<ServletWebSocketHttpExchange> exchangeType = ServletWebSocketHttpExchange.class;
Class<?>[] exchangeParamTypes = new Class<?>[] {HttpServletRequest.class, HttpServletResponse.class, Set.class};
if (ClassUtils.hasConstructor(exchangeType, exchangeParamTypes)) {
exchangeConstructor = ClassUtils.getConstructorIfAvailable(exchangeType, exchangeParamTypes);
undertow10Present = false;
}
else {
paramTypes = new Class<?>[] {HttpServletRequest.class, HttpServletResponse.class};
exchangeConstructor = ClassUtils.getConstructorIfAvailable(type, paramTypes);
exchangeParamTypes = new Class<?>[] {HttpServletRequest.class, HttpServletResponse.class};
exchangeConstructor = ClassUtils.getConstructorIfAvailable(exchangeType, exchangeParamTypes);
undertow10Present = true;
}

Class<ConfiguredServerEndpoint> endpointType = ConfiguredServerEndpoint.class;
Class<?>[] endpointParamTypes = new Class<?>[] {ServerEndpointConfig.class, InstanceFactory.class,
PathTemplate.class, EncodingFactory.class, AnnotatedEndpointFactory.class};
if (ClassUtils.hasConstructor(endpointType, endpointParamTypes)) {
endpointConstructor = ClassUtils.getConstructorIfAvailable(endpointType, endpointParamTypes);
undertow11Present = true;
}
else {
endpointParamTypes = new Class<?>[] {ServerEndpointConfig.class, InstanceFactory.class,
PathTemplate.class, EncodingFactory.class};
endpointConstructor = ClassUtils.getConstructorIfAvailable(endpointType, endpointParamTypes);
undertow11Present = false;
}
}

private static final String[] supportedVersions = new String[] {
Expand Down Expand Up @@ -174,12 +195,21 @@ private ConfiguredServerEndpoint createConfiguredServerEndpoint(String selectedP
endpointRegistration.setSubprotocols(Arrays.asList(selectedProtocol));
endpointRegistration.setExtensions(selectedExtensions);

return new ConfiguredServerEndpoint(endpointRegistration, new EndpointInstanceFactory(endpoint), null,
new EncodingFactory(
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap()));
EncodingFactory encodingFactory = new EncodingFactory(
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap());
try {
return undertow11Present ?
endpointConstructor.newInstance(endpointRegistration,
new EndpointInstanceFactory(endpoint), null, encodingFactory, null) :
endpointConstructor.newInstance(endpointRegistration,
new EndpointInstanceFactory(endpoint), null, encodingFactory);
}
catch (Exception ex) {
throw new HandshakeFailureException("Failed to instantiate ConfiguredServerEndpoint", ex);
}
}


Expand Down

0 comments on commit bb150c4

Please sign in to comment.