parent
baae8ddd3e
commit
5ac57e8ea6
|
@ -33,6 +33,7 @@ import javax.websocket.Endpoint;
|
||||||
import javax.websocket.Extension;
|
import javax.websocket.Extension;
|
||||||
import javax.websocket.server.ServerEndpointConfig;
|
import javax.websocket.server.ServerEndpointConfig;
|
||||||
|
|
||||||
|
import io.undertow.server.HttpServerExchange;
|
||||||
import io.undertow.server.HttpUpgradeListener;
|
import io.undertow.server.HttpUpgradeListener;
|
||||||
import io.undertow.servlet.api.InstanceFactory;
|
import io.undertow.servlet.api.InstanceFactory;
|
||||||
import io.undertow.servlet.api.InstanceHandle;
|
import io.undertow.servlet.api.InstanceHandle;
|
||||||
|
@ -51,6 +52,7 @@ import io.undertow.websockets.jsr.handshake.JsrHybi07Handshake;
|
||||||
import io.undertow.websockets.jsr.handshake.JsrHybi08Handshake;
|
import io.undertow.websockets.jsr.handshake.JsrHybi08Handshake;
|
||||||
import io.undertow.websockets.jsr.handshake.JsrHybi13Handshake;
|
import io.undertow.websockets.jsr.handshake.JsrHybi13Handshake;
|
||||||
import io.undertow.websockets.spi.WebSocketHttpExchange;
|
import io.undertow.websockets.spi.WebSocketHttpExchange;
|
||||||
|
import org.xnio.StreamConnection;
|
||||||
|
|
||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
|
@ -161,39 +163,31 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat
|
||||||
|
|
||||||
HttpServletRequest servletRequest = getHttpServletRequest(request);
|
HttpServletRequest servletRequest = getHttpServletRequest(request);
|
||||||
HttpServletResponse servletResponse = getHttpServletResponse(response);
|
HttpServletResponse servletResponse = getHttpServletResponse(response);
|
||||||
|
|
||||||
final ServletWebSocketHttpExchange exchange = createHttpExchange(servletRequest, servletResponse);
|
final ServletWebSocketHttpExchange exchange = createHttpExchange(servletRequest, servletResponse);
|
||||||
exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap());
|
exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap());
|
||||||
|
|
||||||
ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest);
|
ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest);
|
||||||
final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer);
|
final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer);
|
||||||
|
|
||||||
final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint(
|
final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint(
|
||||||
selectedProtocol, selectedExtensions, endpoint, servletRequest);
|
selectedProtocol, selectedExtensions, endpoint, servletRequest);
|
||||||
|
|
||||||
final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint);
|
final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint);
|
||||||
|
|
||||||
HttpUpgradeListener upgradeListener = (HttpUpgradeListener) Proxy.newProxyInstance(
|
exchange.upgradeChannel(new HttpUpgradeListener() {
|
||||||
getClass().getClassLoader(), new Class<?>[] {HttpUpgradeListener.class},
|
@Override
|
||||||
new InvocationHandler() {
|
public void handleUpgrade(StreamConnection connection, HttpServerExchange serverExchange) {
|
||||||
@Override
|
Object bufferPool = ReflectionUtils.invokeMethod(getBufferPoolMethod, exchange);
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
WebSocketChannel channel = (WebSocketChannel) ReflectionUtils.invokeMethod(
|
||||||
if ("handleUpgrade".equals(method.getName())) {
|
createChannelMethod, handshake, exchange, connection, bufferPool);
|
||||||
Object connection = args[0]; // currently an XNIO StreamConnection
|
if (peerConnections != null) {
|
||||||
Object bufferPool = ReflectionUtils.invokeMethod(getBufferPoolMethod, exchange);
|
peerConnections.add(channel);
|
||||||
WebSocketChannel channel = (WebSocketChannel) ReflectionUtils.invokeMethod(
|
}
|
||||||
createChannelMethod, handshake, exchange, connection, bufferPool);
|
endpointSessionHandler.onConnect(exchange, channel);
|
||||||
if (peerConnections != null) {
|
}
|
||||||
peerConnections.add(channel);
|
});
|
||||||
}
|
|
||||||
endpointSessionHandler.onConnect(exchange, channel);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// any java.lang.Object method: equals, hashCode, toString...
|
|
||||||
return ReflectionUtils.invokeMethod(method, this, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
exchange.upgradeChannel(upgradeListener);
|
|
||||||
handshake.handshake(exchange);
|
handshake.handshake(exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue