Consistent ".jetty" and ".standard" subpackages; consolidated GlassFishRequestUpgradeStrategy implementation; renamed Text/BinaryWebSocketHandler and moved them to web.socket.support
This commit is contained in:
@@ -14,25 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket;
|
||||
|
||||
import org.glassfish.tyrus.core.EndpointWrapper;
|
||||
import org.glassfish.tyrus.core.TyrusEndpoint;
|
||||
import org.glassfish.tyrus.websockets.WebSocketApplication;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Extension of the {@link AbstractGlassFishRequestUpgradeStrategy} that provides support
|
||||
* for GlassFish 4.0.1 and beyond.
|
||||
* An interface for WebSocket handlers that support sub-protocols as defined in RFC 6455.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Michael Irwin
|
||||
* @since 4.0
|
||||
* @see WebSocketHandler
|
||||
* @see <a href="http://tools.ietf.org/html/rfc6455#section-1.9">RFC-6455 section 1.9</a>
|
||||
*/
|
||||
public class GlassFishRequestUpgradeStrategy extends AbstractGlassFishRequestUpgradeStrategy {
|
||||
public interface SubProtocolCapable {
|
||||
|
||||
@Override
|
||||
protected WebSocketApplication createTyrusEndpoint(EndpointWrapper endpoint) {
|
||||
return new TyrusEndpoint(endpoint);
|
||||
}
|
||||
/**
|
||||
* Return the list of supported sub-protocols.
|
||||
*/
|
||||
List<String> getSubProtocols();
|
||||
|
||||
}
|
||||
@@ -23,9 +23,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.Extension;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
@@ -177,64 +174,4 @@ public class WebSocketExtension {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
|
||||
// Standard WebSocketExtension adapters
|
||||
|
||||
public static class StandardToWebSocketExtensionAdapter extends WebSocketExtension {
|
||||
|
||||
public StandardToWebSocketExtensionAdapter(Extension ext) {
|
||||
super(ext.getName());
|
||||
for (Extension.Parameter p : ext.getParameters()) {
|
||||
super.getParameters().put(p.getName(), p.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class WebSocketToStandardExtensionAdapter implements Extension {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final List<Parameter> parameters = new ArrayList<Parameter>();
|
||||
|
||||
public WebSocketToStandardExtensionAdapter(final WebSocketExtension ext) {
|
||||
this.name = ext.getName();
|
||||
for (final String paramName : ext.getParameters().keySet()) {
|
||||
this.parameters.add(new Parameter() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return paramName;
|
||||
}
|
||||
@Override
|
||||
public String getValue() {
|
||||
return ext.getParameters().get(paramName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Parameter> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
}
|
||||
|
||||
// Jetty WebSocketExtension adapters
|
||||
|
||||
public static class WebSocketToJettyExtensionConfigAdapter extends ExtensionConfig {
|
||||
|
||||
public WebSocketToJettyExtensionConfigAdapter(WebSocketExtension extension) {
|
||||
super(extension.getName());
|
||||
for (Map.Entry<String,String> p : extension.getParameters().entrySet()) {
|
||||
super.setParameter(p.getKey(), p.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ package org.springframework.web.socket;
|
||||
* the exception is logged and the session closed with
|
||||
* {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)}. The exception handling
|
||||
* strategy is provided by
|
||||
* {@link org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
|
||||
* {@link org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator
|
||||
* ExceptionWebSocketHandlerDecorator} and it can be customized or replaced by decorating
|
||||
* the {@link WebSocketHandler} with a different decorator.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -25,7 +25,6 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
/**
|
||||
* An {@link org.springframework.http.HttpHeaders} variant that adds support for
|
||||
@@ -36,8 +35,6 @@ import org.springframework.web.socket.WebSocketExtension;
|
||||
*/
|
||||
public class WebSocketHttpHeaders extends HttpHeaders {
|
||||
|
||||
private static final long serialVersionUID = -6644521016187828916L;
|
||||
|
||||
public static final String SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept";
|
||||
|
||||
public static final String SEC_WEBSOCKET_EXTENSIONS = "Sec-WebSocket-Extensions";
|
||||
@@ -48,6 +45,9 @@ public class WebSocketHttpHeaders extends HttpHeaders {
|
||||
|
||||
public static final String SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
|
||||
|
||||
private static final long serialVersionUID = -6644521016187828916L;
|
||||
|
||||
|
||||
private final HttpHeaders headers;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +21,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.BinaryMessage;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
@@ -35,7 +37,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractWebSocketSesssion<T> implements WebSocketSession, NativeWebSocketSession {
|
||||
public abstract class AbstractWebSocketSession<T> implements NativeWebSocketSession {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -49,7 +51,7 @@ public abstract class AbstractWebSocketSesssion<T> implements WebSocketSession,
|
||||
* @param handshakeAttributes attributes from the HTTP handshake to make available
|
||||
* through the WebSocket session
|
||||
*/
|
||||
public AbstractWebSocketSesssion(Map<String, Object> handshakeAttributes) {
|
||||
public AbstractWebSocketSession(Map<String, Object> handshakeAttributes) {
|
||||
this.handshakeAttributes = handshakeAttributes;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.adapter.jetty;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.PongMessage;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* Adapts {@link WebSocketHandler} to the Jetty 9 WebSocket API.
|
||||
@@ -52,10 +52,8 @@ public class JettyWebSocketHandlerAdapter {
|
||||
|
||||
|
||||
public JettyWebSocketHandlerAdapter(WebSocketHandler webSocketHandler, JettyWebSocketSession wsSession) {
|
||||
|
||||
Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
|
||||
Assert.notNull(wsSession, "wsSession must not be null");
|
||||
|
||||
this.webSocketHandler = webSocketHandler;
|
||||
this.wsSession = wsSession;
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.adapter.jetty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.web.socket.PongMessage;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.AbstractWebSocketSession;
|
||||
|
||||
/**
|
||||
* A {@link WebSocketSession} for use with the Jetty 9 WebSocket API.
|
||||
@@ -42,7 +44,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class JettyWebSocketSession extends AbstractWebSocketSesssion<org.eclipse.jetty.websocket.api.Session> {
|
||||
public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
|
||||
|
||||
private HttpHeaders headers;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter.jetty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class WebSocketToJettyExtensionConfigAdapter extends ExtensionConfig {
|
||||
|
||||
public WebSocketToJettyExtensionConfigAdapter(WebSocketExtension extension) {
|
||||
super(extension.getName());
|
||||
for (Map.Entry<String,String> p : extension.getParameters().entrySet()) {
|
||||
super.setParameter(p.getKey(), p.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adapter classes for the Jetty WebSocket API.
|
||||
*/
|
||||
package org.springframework.web.socket.adapter.jetty;
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Classes adapting Spring's WebSocket API classes to and from WebSocket
|
||||
* implementations. Also contains convenient base classes for
|
||||
* {@link org.springframework.web.socket.WebSocketHandler} implementations.
|
||||
* Classes adapting Spring's WebSocket API to and from WebSocket providers.
|
||||
*/
|
||||
package org.springframework.web.socket.adapter;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import javax.websocket.DecodeException;
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
import javax.websocket.Extension;
|
||||
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StandardToWebSocketExtensionAdapter extends WebSocketExtension {
|
||||
|
||||
public StandardToWebSocketExtensionAdapter(Extension ext) {
|
||||
super(ext.getName());
|
||||
for (Extension.Parameter p : ext.getParameters()) {
|
||||
super.getParameters().put(p.getName(), p.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.PongMessage;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* Adapts a {@link WebSocketHandler} to the standard WebSocket for Java API.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.CloseReason.CloseCodes;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.Session;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -37,6 +38,7 @@ import org.springframework.web.socket.PongMessage;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.adapter.AbstractWebSocketSession;
|
||||
|
||||
/**
|
||||
* A {@link WebSocketSession} for use with the standard WebSocket for Java API.
|
||||
@@ -44,7 +46,7 @@ import org.springframework.web.socket.WebSocketExtension;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StandardWebSocketSession extends AbstractWebSocketSesssion<javax.websocket.Session> {
|
||||
public class StandardWebSocketSession extends AbstractWebSocketSession<Session> {
|
||||
|
||||
private final HttpHeaders handshakeHeaders;
|
||||
|
||||
@@ -119,7 +121,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSesssion<javax.we
|
||||
List<Extension> source = getNativeSession().getNegotiatedExtensions();
|
||||
this.extensions = new ArrayList<WebSocketExtension>(source.size());
|
||||
for(Extension e : source) {
|
||||
this.extensions.add(new WebSocketExtension.StandardToWebSocketExtensionAdapter(e));
|
||||
this.extensions.add(new StandardToWebSocketExtensionAdapter(e));
|
||||
}
|
||||
}
|
||||
return this.extensions;
|
||||
@@ -127,7 +129,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSesssion<javax.we
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return ((getNativeSession() != null) && getNativeSession().isOpen());
|
||||
return (getNativeSession() != null && getNativeSession().isOpen());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.websocket.Extension;
|
||||
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class WebSocketToStandardExtensionAdapter implements Extension {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final List<Parameter> parameters = new ArrayList<Parameter>();
|
||||
|
||||
public WebSocketToStandardExtensionAdapter(final WebSocketExtension ext) {
|
||||
this.name = ext.getName();
|
||||
for (final String paramName : ext.getParameters().keySet()) {
|
||||
this.parameters.add(new Parameter() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return paramName;
|
||||
}
|
||||
@Override
|
||||
public String getValue() {
|
||||
return ext.getParameters().get(paramName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Parameter> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adapter classes for the standard Java WebSocket API.
|
||||
*/
|
||||
package org.springframework.web.socket.adapter.standard;
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.net.URI;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
/**
|
||||
* Contract for initiating a WebSocket request. As an alternative considering using the
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
/**
|
||||
* A WebSocket connection manager that is given a URI, a {@link WebSocketClient}, and a
|
||||
|
||||
@@ -35,16 +35,17 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter;
|
||||
import org.springframework.web.socket.client.AbstractWebSocketClient;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Initiates WebSocket requests to a WebSocket server programatically through the Jetty
|
||||
* WebSocket API.
|
||||
* Initiates WebSocket requests to a WebSocket server programmatically
|
||||
* through the Jetty WebSocket API.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
@@ -177,7 +178,7 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Sma
|
||||
request.setSubProtocols(protocols);
|
||||
|
||||
for (WebSocketExtension e : extensions) {
|
||||
request.addExtensions(new WebSocketExtension.WebSocketToJettyExtensionConfigAdapter(e));
|
||||
request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
|
||||
}
|
||||
|
||||
for (String header : headers.keySet()) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Client-side support for the Jetty WebSocket API.
|
||||
*/
|
||||
package org.springframework.web.socket.client.jetty;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Session;
|
||||
@@ -28,7 +28,7 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.client.ConnectionManagerSupport;
|
||||
import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
|
||||
import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* A WebSocket connection manager that is given a URI, a {@link ServerEndpoint}-annotated
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -36,7 +36,7 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.client.ConnectionManagerSupport;
|
||||
import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
|
||||
import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* A WebSocket connection manager that is given a URI, an {@link Endpoint}, connects to a
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -37,8 +37,9 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.StandardWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.StandardWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter;
|
||||
import org.springframework.web.socket.client.AbstractWebSocketClient;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
@@ -123,7 +124,7 @@ public class StandardWebSocketClient extends AbstractWebSocketClient {
|
||||
private static List<Extension> adaptExtensions(List<WebSocketExtension> extensions) {
|
||||
List<Extension> result = new ArrayList<Extension>();
|
||||
for (WebSocketExtension e : extensions) {
|
||||
result.add(new WebSocketExtension.WebSocketToStandardExtensionAdapter(e));
|
||||
result.add(new WebSocketToStandardExtensionAdapter(e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
@@ -17,5 +17,5 @@
|
||||
/**
|
||||
* Client-side classes for use with standard Java WebSocket endpoints.
|
||||
*/
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* A registry for STOMP over WebSocket endpoints that maps the endpoints with a
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.springframework.web.socket.BinaryMessage;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
@@ -31,8 +31,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
* @author Phillip Webb
|
||||
* @since 4.0
|
||||
*/
|
||||
public class WebSocketHandlerAdapter implements WebSocketHandler {
|
||||
|
||||
public abstract class AbstractWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
* @author Phillip Webb
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BinaryWebSocketHandlerAdapter extends WebSocketHandlerAdapter {
|
||||
public class BinaryWebSocketHandler extends AbstractWebSocketHandler {
|
||||
|
||||
@Override
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.adapter;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
* @author Phillip Webb
|
||||
* @since 4.0
|
||||
*/
|
||||
public class TextWebSocketHandlerAdapter extends WebSocketHandlerAdapter {
|
||||
public class TextWebSocketHandler extends AbstractWebSocketHandler {
|
||||
|
||||
@Override
|
||||
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
@@ -32,7 +32,7 @@ public class WebSocketHandlerDecorator implements WebSocketHandler {
|
||||
|
||||
|
||||
public WebSocketHandlerDecorator(WebSocketHandler delegate) {
|
||||
Assert.notNull(delegate, "delegate must not be null");
|
||||
Assert.notNull(delegate, "Delegate must not be null");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* WebSocket-related classes used by client and server code such as
|
||||
* a {@link org.springframework.web.socket.support.WebSocketHandlerDecorator}
|
||||
* and sub-class implementations, as well as a
|
||||
* {@link org.springframework.web.socket.support.PerConnectionWebSocketHandler}.
|
||||
* Convenient {@link org.springframework.web.socket.WebSocketHandler}
|
||||
* implementations and decorators.
|
||||
*/
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
@@ -16,21 +16,32 @@
|
||||
|
||||
package org.springframework.web.socket.messaging;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.messaging.*;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.SubProtocolCapable;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.support.SubProtocolCapable;
|
||||
|
||||
/**
|
||||
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket
|
||||
@@ -45,11 +56,10 @@ import org.springframework.web.socket.support.SubProtocolCapable;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Andy Wilkinson
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SubProtocolWebSocketHandler
|
||||
implements SubProtocolCapable, WebSocketHandler, MessageHandler, SmartLifecycle {
|
||||
implements WebSocketHandler, SubProtocolCapable, MessageHandler, SmartLifecycle {
|
||||
|
||||
private final Log logger = LogFactory.getLog(SubProtocolWebSocketHandler.class);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.support.PerConnectionWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
||||
|
||||
/**
|
||||
* Contract for processing a WebSocket handshake request.
|
||||
|
||||
@@ -14,13 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.jetty;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@@ -33,6 +32,7 @@ import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
@@ -42,8 +42,9 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.jetty.WebSocketToJettyExtensionConfigAdapter;
|
||||
import org.springframework.web.socket.server.HandshakeFailureException;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
|
||||
@@ -83,22 +84,17 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
Assert.notNull(factory, "WebSocketServerFactory must not be null");
|
||||
this.factory = factory;
|
||||
this.factory.setCreator(new WebSocketCreator() {
|
||||
|
||||
@Override
|
||||
public Object createWebSocket(ServletUpgradeRequest request, ServletUpgradeResponse response) {
|
||||
// Cast to avoid infinite recursion
|
||||
return createWebSocket((UpgradeRequest) request, (UpgradeResponse) response);
|
||||
}
|
||||
|
||||
// For Jetty 9.0.x
|
||||
public Object createWebSocket(UpgradeRequest request, UpgradeResponse response) {
|
||||
|
||||
WebSocketHandlerContainer container = wsContainerHolder.get();
|
||||
Assert.state(container != null, "Expected WebSocketHandlerContainer");
|
||||
|
||||
response.setAcceptedSubProtocol(container.getSelectedProtocol());
|
||||
response.setExtensions(container.getExtensionConfigs());
|
||||
|
||||
return container.getHandler();
|
||||
}
|
||||
});
|
||||
@@ -173,33 +169,31 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
private final List<ExtensionConfig> extensionConfigs;
|
||||
|
||||
private WebSocketHandlerContainer(JettyWebSocketHandlerAdapter handler, String protocol,
|
||||
List<WebSocketExtension> extensions) {
|
||||
|
||||
public WebSocketHandlerContainer(JettyWebSocketHandlerAdapter handler, String protocol, List<WebSocketExtension> extensions) {
|
||||
this.handler = handler;
|
||||
this.selectedProtocol = protocol;
|
||||
|
||||
if (CollectionUtils.isEmpty(extensions)) {
|
||||
this.extensionConfigs = null;
|
||||
}
|
||||
else {
|
||||
this.extensionConfigs = new ArrayList<ExtensionConfig>();
|
||||
for (WebSocketExtension e : extensions) {
|
||||
this.extensionConfigs.add(new WebSocketExtension.WebSocketToJettyExtensionConfigAdapter(e));
|
||||
this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JettyWebSocketHandlerAdapter getHandler() {
|
||||
public JettyWebSocketHandlerAdapter getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
private String getSelectedProtocol() {
|
||||
public String getSelectedProtocol() {
|
||||
return this.selectedProtocol;
|
||||
}
|
||||
|
||||
private List<ExtensionConfig> getExtensionConfigs() {
|
||||
public List<ExtensionConfig> getExtensionConfigs() {
|
||||
return this.extensionConfigs;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Server-side support for the Jetty WebSocket API.
|
||||
*/
|
||||
package org.springframework.web.socket.server.jetty;
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.websocket.Endpoint;
|
||||
@@ -28,6 +29,7 @@ import javax.websocket.server.ServerContainer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
@@ -35,8 +37,10 @@ import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.StandardWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.StandardWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.standard.StandardToWebSocketExtensionAdapter;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter;
|
||||
import org.springframework.web.socket.server.HandshakeFailureException;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
|
||||
@@ -74,8 +78,8 @@ public abstract class AbstractStandardUpgradeStrategy implements RequestUpgradeS
|
||||
|
||||
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) {
|
||||
List<WebSocketExtension> result = new ArrayList<WebSocketExtension>();
|
||||
for(Extension e : container.getInstalledExtensions()) {
|
||||
result.add(new WebSocketExtension.StandardToWebSocketExtensionAdapter(e));
|
||||
for (Extension ext : container.getInstalledExtensions()) {
|
||||
result.add(new StandardToWebSocketExtensionAdapter(ext));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -95,7 +99,7 @@ public abstract class AbstractStandardUpgradeStrategy implements RequestUpgradeS
|
||||
|
||||
List<Extension> extensions = new ArrayList<Extension>();
|
||||
for (WebSocketExtension e : selectedExtensions) {
|
||||
extensions.add(new WebSocketExtension.WebSocketToStandardExtensionAdapter(e));
|
||||
extensions.add(new WebSocketToStandardExtensionAdapter(e));
|
||||
}
|
||||
|
||||
upgradeInternal(request, response, selectedProtocol, extensions, endpoint);
|
||||
@@ -14,63 +14,107 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.glassfish.tyrus.core.ComponentProviderService;
|
||||
import org.glassfish.tyrus.core.EndpointWrapper;
|
||||
import org.glassfish.tyrus.core.ErrorCollector;
|
||||
import org.glassfish.tyrus.core.RequestContext;
|
||||
import org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler;
|
||||
import org.glassfish.tyrus.spi.SPIEndpoint;
|
||||
import org.glassfish.tyrus.websockets.Connection;
|
||||
import org.glassfish.tyrus.websockets.Version;
|
||||
import org.glassfish.tyrus.websockets.WebSocketApplication;
|
||||
import org.glassfish.tyrus.websockets.WebSocketEngine;
|
||||
import org.glassfish.tyrus.websockets.WebSocketEngine.WebSocketHolderListener;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.server.HandshakeFailureException;
|
||||
|
||||
/**
|
||||
* GlassFish support for upgrading a request during a WebSocket handshake. To modify
|
||||
* properties of the underlying {@link javax.websocket.server.ServerContainer} you can use
|
||||
* {@link ServletServerContainerFactoryBean} in XML configuration or if using Java
|
||||
* configuration, access the container instance through the
|
||||
* "javax.websocket.server.ServerContainer" ServletContext attribute.
|
||||
* {@code RequestUpgradeStrategy} that provides support for GlassFish 4 and beyond.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Michael Irwin
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractGlassFishRequestUpgradeStrategy extends AbstractStandardUpgradeStrategy {
|
||||
public class GlassFishRequestUpgradeStrategy extends AbstractStandardUpgradeStrategy {
|
||||
|
||||
private final static Random random = new Random();
|
||||
|
||||
private static final Constructor<?> tyrusConnectionConstructor;
|
||||
|
||||
private static final Constructor<?> tyrusEndpointConstructor;
|
||||
|
||||
|
||||
static {
|
||||
ClassLoader cl = GlassFishRequestUpgradeStrategy.class.getClassLoader();
|
||||
try {
|
||||
// Tyrus ConnectionImpl is package-visible only
|
||||
Class<?> tyrusConnectionClass = cl.loadClass("org.glassfish.tyrus.servlet.ConnectionImpl");
|
||||
tyrusConnectionConstructor = tyrusConnectionClass.getDeclaredConstructor(
|
||||
TyrusHttpUpgradeHandler.class, HttpServletResponse.class);
|
||||
ReflectionUtils.makeAccessible(tyrusConnectionConstructor);
|
||||
|
||||
// TyrusEndpoint package location differs between GlassFish 4.0.0 and 4.0.1
|
||||
Class<?> tyrusEndpointClass;
|
||||
try {
|
||||
tyrusEndpointClass = cl.loadClass("org.glassfish.tyrus.core.TyrusEndpoint");
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
try {
|
||||
tyrusEndpointClass = cl.loadClass("org.glassfish.tyrus.server.TyrusEndpoint");
|
||||
}
|
||||
catch (ClassNotFoundException ex2) {
|
||||
// Propagate original exception for newer version of the class
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
tyrusEndpointConstructor = tyrusEndpointClass.getConstructor(SPIEndpoint.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("No compatible Tyrus version found", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getSupportedVersions() {
|
||||
return StringUtils.commaDelimitedListToStringArray(Version.getSupportedWireProtocolVersions());
|
||||
}
|
||||
|
||||
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) {
|
||||
try {
|
||||
return super.getInstalledExtensions(container);
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
return new ArrayList<WebSocketExtension>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
|
||||
String selectedProtocol, List<Extension> selectedExtensions,
|
||||
@@ -113,21 +157,21 @@ public abstract class AbstractGlassFishRequestUpgradeStrategy extends AbstractSt
|
||||
try {
|
||||
upgradeHandler = request.upgrade(TyrusHttpUpgradeHandler.class);
|
||||
}
|
||||
catch (ServletException e) {
|
||||
throw new HandshakeFailureException("Unable to create UpgardeHandler", e);
|
||||
catch (ServletException ex) {
|
||||
throw new HandshakeFailureException("Unable to create UpgradeHandler", ex);
|
||||
}
|
||||
|
||||
Connection connection = createConnection(upgradeHandler, response);
|
||||
|
||||
RequestContext wsRequest = RequestContext.Builder.create()
|
||||
.requestURI(URI.create(wsApp.getPath())).requestPath(wsApp.getPath())
|
||||
.connection(connection).secure(request.isSecure()).build();
|
||||
RequestContext wsRequest = RequestContext.Builder.create().
|
||||
requestURI(URI.create(wsApp.getPath())).requestPath(wsApp.getPath()).
|
||||
connection(connection).secure(request.isSecure()).build();
|
||||
|
||||
for (String header : headers.keySet()) {
|
||||
wsRequest.getHeaders().put(header, headers.get(header));
|
||||
}
|
||||
|
||||
return WebSocketEngine.getEngine().upgrade(connection, wsRequest, new WebSocketHolderListener() {
|
||||
return WebSocketEngine.getEngine().upgrade(connection, wsRequest, new WebSocketEngine.WebSocketHolderListener() {
|
||||
@Override
|
||||
public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) {
|
||||
upgradeHandler.setWebSocketHolder(webSocketHolder);
|
||||
@@ -138,7 +182,7 @@ public abstract class AbstractGlassFishRequestUpgradeStrategy extends AbstractSt
|
||||
private WebSocketApplication createTyrusEndpoint(HttpServletRequest request,
|
||||
Endpoint endpoint, String selectedProtocol, List<Extension> selectedExtensions) {
|
||||
|
||||
// shouldn't matter for processing but must be unique
|
||||
// Shouldn't matter for processing but must be unique
|
||||
String endpointPath = "/" + random.nextLong();
|
||||
ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint);
|
||||
endpointConfig.setSubprotocols(Arrays.asList(selectedProtocol));
|
||||
@@ -148,23 +192,21 @@ public abstract class AbstractGlassFishRequestUpgradeStrategy extends AbstractSt
|
||||
endpointConfig.getConfigurator()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the actual TyrusEndpoint
|
||||
* @param endpoint The WebSocket endpoint
|
||||
* @return The configured WebSocketApplication, most likely {@code TyrusEndpoint}
|
||||
*/
|
||||
abstract protected WebSocketApplication createTyrusEndpoint(EndpointWrapper endpoint);
|
||||
|
||||
private Connection createConnection(TyrusHttpUpgradeHandler handler, HttpServletResponse response) {
|
||||
try {
|
||||
String name = "org.glassfish.tyrus.servlet.ConnectionImpl";
|
||||
Class<?> clazz = ClassUtils.forName(name, GlassFishRequestUpgradeStrategy.class.getClassLoader());
|
||||
Constructor<?> constructor = clazz.getDeclaredConstructor(TyrusHttpUpgradeHandler.class, HttpServletResponse.class);
|
||||
ReflectionUtils.makeAccessible(constructor);
|
||||
return (Connection) constructor.newInstance(handler, response);
|
||||
return (Connection) tyrusConnectionConstructor.newInstance(handler, response);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to instantiate GlassFish connection", ex);
|
||||
throw new IllegalStateException("Failed to create GlassFish connection", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected WebSocketApplication createTyrusEndpoint(EndpointWrapper endpoint) {
|
||||
try {
|
||||
return (WebSocketApplication) tyrusEndpointConstructor.newInstance(endpoint);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to create GlassFish endpoint", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.server.ServerContainer;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
@@ -29,6 +28,7 @@ import javax.websocket.server.ServerEndpointConfig;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
@@ -14,13 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.Encoder;
|
||||
import javax.websocket.Endpoint;
|
||||
@@ -33,7 +32,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
|
||||
import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* An implementation of {@link javax.websocket.server.ServerEndpointConfig} for use in
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.web.context.ServletContextAware;
|
||||
* configuration.
|
||||
*
|
||||
* <p>This is useful even if the {@code ServerContainer} is not injected into any other
|
||||
* bean. For example, an application can configure a {@link DefaultHandshakeHandler}, a
|
||||
* bean. For example, an application can configure a {@link org.springframework.web.socket.server.support.DefaultHandshakeHandler}, a
|
||||
* {@link org.springframework.web.socket.sockjs.SockJsService}, or {@link ServerEndpointExporter},
|
||||
* and separately declare this FactoryBean in order to customize the properties of the
|
||||
* (one and only) {@code ServerContainer} instance.
|
||||
@@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
import javax.websocket.server.ServerEndpointConfig.Configurator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -14,14 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -29,6 +28,7 @@ import javax.websocket.Endpoint;
|
||||
import javax.websocket.Extension;
|
||||
|
||||
import org.apache.tomcat.websocket.server.WsServerContainer;
|
||||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Server-side classes for use with standard Java WebSocket endpoints.
|
||||
*/
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
@@ -33,26 +33,26 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.SubProtocolCapable;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeFailureException;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.support.SubProtocolCapable;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
/**
|
||||
* A default {@link org.springframework.web.socket.server.HandshakeHandler} implementation. Performs initial validation of the
|
||||
* WebSocket handshake request -- possibly rejecting it through the appropriate HTTP
|
||||
* status code -- while also allowing sub-classes to override various parts of the
|
||||
* negotiation process (e.g. origin validation, sub-protocol negotiation,
|
||||
* A default {@link org.springframework.web.socket.server.HandshakeHandler} implementation.
|
||||
* Performs initial validation of the WebSocket handshake request -- possibly rejecting it
|
||||
* through the appropriate HTTP status code -- while also allowing sub-classes to override
|
||||
* various parts of the negotiation process (e.g. origin validation, sub-protocol negotiation,
|
||||
* extensions negotiation, etc).
|
||||
*
|
||||
* <p>If the negotiation succeeds, the actual upgrade is delegated to a server-specific
|
||||
* {@link org.springframework.web.socket.server.RequestUpgradeStrategy}, which will update the response as necessary and
|
||||
* initialize the WebSocket. Currently supported servers are Tomcat 7 and 8, Jetty 9, and
|
||||
* Glassfish 4.
|
||||
* {@link org.springframework.web.socket.server.RequestUpgradeStrategy}, which will update
|
||||
* the response as necessary and initialize the WebSocket. Currently supported servers are
|
||||
* Tomcat 7 and 8, Jetty 9, and GlassFish 4.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
@@ -61,17 +61,14 @@ public class DefaultHandshakeHandler implements HandshakeHandler {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private static final boolean tomcatWsPresent = ClassUtils.isPresent(
|
||||
"org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", HandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean jettyWsPresent = ClassUtils.isPresent(
|
||||
"org.eclipse.jetty.websocket.server.WebSocketServerFactory", HandshakeHandler.class.getClassLoader());
|
||||
"org.eclipse.jetty.websocket.server.WebSocketServerFactory", DefaultHandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean tomcatWsPresent = ClassUtils.isPresent(
|
||||
"org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean glassFishWsPresent = ClassUtils.isPresent(
|
||||
"org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler", HandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean glassFish40WsPresent = ClassUtils.isPresent(
|
||||
"org.glassfish.tyrus.server.TyrusEndpoint", HandshakeHandler.class.getClassLoader());
|
||||
"org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
|
||||
|
||||
|
||||
private final RequestUpgradeStrategy requestUpgradeStrategy;
|
||||
@@ -90,29 +87,24 @@ public class DefaultHandshakeHandler implements HandshakeHandler {
|
||||
|
||||
private static RequestUpgradeStrategy initRequestUpgradeStrategy() {
|
||||
String className;
|
||||
if (tomcatWsPresent) {
|
||||
className = "org.springframework.web.socket.server.support.TomcatRequestUpgradeStrategy";
|
||||
if (jettyWsPresent) {
|
||||
className = "org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy";
|
||||
}
|
||||
else if (jettyWsPresent) {
|
||||
className = "org.springframework.web.socket.server.support.JettyRequestUpgradeStrategy";
|
||||
else if (tomcatWsPresent) {
|
||||
className = "org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy";
|
||||
}
|
||||
else if (glassFishWsPresent) {
|
||||
if (glassFish40WsPresent) {
|
||||
className = "org.springframework.web.socket.server.support.GlassFish40RequestUpgradeStrategy";
|
||||
}
|
||||
else {
|
||||
className = "org.springframework.web.socket.server.support.GlassFishRequestUpgradeStrategy";
|
||||
}
|
||||
className = "org.springframework.web.socket.server.standard.GlassFishRequestUpgradeStrategy";
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No suitable " + RequestUpgradeStrategy.class.getSimpleName());
|
||||
throw new IllegalStateException("No suitable default RequestUpgradeStrategy found");
|
||||
}
|
||||
try {
|
||||
Class<?> clazz = ClassUtils.forName(className, DefaultHandshakeHandler.class.getClassLoader());
|
||||
return (RequestUpgradeStrategy) BeanUtils.instantiateClass(clazz.getConstructor());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new IllegalStateException("Failed to instantiate " + className, t);
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Failed to instantiate RequestUpgradeStrategy: " + className, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.support;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.glassfish.tyrus.core.EndpointWrapper;
|
||||
import org.glassfish.tyrus.spi.SPIEndpoint;
|
||||
import org.glassfish.tyrus.websockets.WebSocketApplication;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
|
||||
/**
|
||||
* Extension of the {@link AbstractGlassFishRequestUpgradeStrategy} that provides support
|
||||
* for only GlassFish 4.0.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Michael Irwin
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GlassFish40RequestUpgradeStrategy extends AbstractGlassFishRequestUpgradeStrategy {
|
||||
|
||||
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) {
|
||||
try {
|
||||
return super.getInstalledExtensions(container);
|
||||
}
|
||||
catch (UnsupportedOperationException e) {
|
||||
return new ArrayList<WebSocketExtension>();
|
||||
}
|
||||
}
|
||||
|
||||
protected WebSocketApplication createTyrusEndpoint(EndpointWrapper endpoint) {
|
||||
try {
|
||||
String name = "org.glassfish.tyrus.server.TyrusEndpoint";
|
||||
Class<?> clazz = ClassUtils.forName(name, this.getClass().getClassLoader());
|
||||
Constructor<?> constructor = clazz.getConstructor(SPIEndpoint.class);
|
||||
return (WebSocketApplication) constructor.newInstance(endpoint);
|
||||
}
|
||||
catch (ReflectiveOperationException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
@@ -35,7 +36,7 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
*/
|
||||
public class HandshakeInterceptorChain {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebSocketHttpRequestHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(HandshakeInterceptorChain.class);
|
||||
|
||||
private final List<HandshakeInterceptor> interceptors;
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ package org.springframework.web.socket.server.support;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeFailureException;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* A {@link HttpRequestHandler} for processing WebSocket handshake requests.
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.web.HttpRequestHandler;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* An {@link HttpRequestHandler} that allows mapping a {@link SockJsService} to requests
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.web.socket.sockjs;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
|
||||
/**
|
||||
* The main entry point for processing HTTP requests from SockJS clients.
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.SockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession;
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSo
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SockJsWebSocketHandler extends TextWebSocketHandlerAdapter {
|
||||
public class SockJsWebSocketHandler extends TextWebSocketHandler {
|
||||
|
||||
private final SockJsServiceConfig sockJsServiceConfig;
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.springframework.web.socket.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An interface for WebSocket handlers that support sub-protocols as defined in RFC 6455.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
* @see <a href="http://tools.ietf.org/html/rfc6455#section-1.9">RFC-6455 section 1.9</a>
|
||||
*/
|
||||
public interface SubProtocolCapable {
|
||||
|
||||
/**
|
||||
* Return the list of supported sub-protocols.
|
||||
*/
|
||||
List<String> getSubProtocols();
|
||||
}
|
||||
@@ -31,8 +31,8 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.JettyRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
|
||||
/**
|
||||
* Base class for WebSocket integration tests.
|
||||
|
||||
@@ -26,15 +26,14 @@ import org.junit.runners.Parameterized;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.client.endpoint.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -67,7 +66,7 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTest
|
||||
headers.setSecWebSocketProtocol("foo");
|
||||
|
||||
WebSocketSession session = this.webSocketClient.doHandshake(
|
||||
new WebSocketHandlerAdapter(), headers, new URI(getWsBaseUrl() + "/ws")).get();
|
||||
new AbstractWebSocketHandler() {}, headers, new URI(getWsBaseUrl() + "/ws")).get();
|
||||
|
||||
assertEquals("foo", session.getAcceptedProtocol());
|
||||
}
|
||||
@@ -92,7 +91,7 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTest
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestServerWebSocketHandler extends TextWebSocketHandlerAdapter {
|
||||
private static class TestServerWebSocketHandler extends TextWebSocketHandler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,12 +39,13 @@ import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.ContextLoaderTestUtils;
|
||||
import org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test for {@link ConvertingEncoderDecoderSupport}.
|
||||
* Test for {@link org.springframework.web.socket.adapter.standard.ConvertingEncoderDecoderSupport}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
|
||||
@@ -21,11 +21,13 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketSession;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link JettyWebSocketHandlerAdapter}.
|
||||
* Test fixture for {@link org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
|
||||
@@ -25,13 +25,15 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.standard.StandardWebSocketSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link StandardWebSocketHandlerAdapter}.
|
||||
* Test fixture for {@link org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -45,11 +45,11 @@ public class WebSocketConnectionManagerTests {
|
||||
|
||||
@Test
|
||||
public void openConnection() throws Exception {
|
||||
|
||||
List<String> subprotocols = Arrays.asList("abc");
|
||||
|
||||
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
|
||||
WebSocketHandler handler = new WebSocketHandlerAdapter();
|
||||
WebSocketHandler handler = new AbstractWebSocketHandler() {
|
||||
};
|
||||
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/path/{id}", "123");
|
||||
manager.setSubProtocols(subprotocols);
|
||||
@@ -69,9 +69,9 @@ public class WebSocketConnectionManagerTests {
|
||||
|
||||
@Test
|
||||
public void syncClientLifecycle() throws Exception {
|
||||
|
||||
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
|
||||
WebSocketHandler handler = new WebSocketHandlerAdapter();
|
||||
WebSocketHandler handler = new AbstractWebSocketHandler() {
|
||||
};
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a");
|
||||
|
||||
manager.startInternal();
|
||||
@@ -85,7 +85,8 @@ public class WebSocketConnectionManagerTests {
|
||||
public void dontSyncClientLifecycle() throws Exception {
|
||||
|
||||
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(true);
|
||||
WebSocketHandler handler = new WebSocketHandlerAdapter();
|
||||
WebSocketHandler handler = new AbstractWebSocketHandler() {
|
||||
};
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a");
|
||||
|
||||
manager.startInternal();
|
||||
|
||||
@@ -32,10 +32,10 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class JettyWebSocketClientTests {
|
||||
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
|
||||
this.server = new TestJettyWebSocketServer(port, new TextWebSocketHandlerAdapter());
|
||||
this.server = new TestJettyWebSocketServer(port, new TextWebSocketHandler());
|
||||
this.server.start();
|
||||
|
||||
this.client = new JettyWebSocketClient();
|
||||
@@ -82,7 +82,7 @@ public class JettyWebSocketClientTests {
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||
headers.setSecWebSocketProtocol(Arrays.asList("echo"));
|
||||
|
||||
this.wsSession = this.client.doHandshake(new TextWebSocketHandlerAdapter(), headers, new URI(this.wsUrl)).get();
|
||||
this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
|
||||
|
||||
assertEquals(this.wsUrl, this.wsSession.getUri().toString());
|
||||
assertEquals("echo", this.wsSession.getAcceptedProtocol());
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.client.endpoint;
|
||||
package org.springframework.web.socket.client.standard;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
@@ -22,7 +22,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
@@ -30,10 +29,11 @@ import javax.websocket.WebSocketContainer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -57,7 +57,8 @@ public class StandardWebSocketClientTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.headers = new WebSocketHttpHeaders();
|
||||
this.wsHandler = new WebSocketHandlerAdapter();
|
||||
this.wsHandler = new AbstractWebSocketHandler() {
|
||||
};
|
||||
this.wsContainer = mock(WebSocketContainer.class);
|
||||
this.wsClient = new StandardWebSocketClient(this.wsContainer);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsHttpRequestHandler;
|
||||
import org.springframework.web.socket.support.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketHandlerRegistration;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||
@@ -59,7 +58,7 @@ public class AbstractWebSocketHandlerRegistrationTests {
|
||||
@Test
|
||||
public void minimal() {
|
||||
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandler();
|
||||
this.registration.addHandler(wsHandler, "/foo", "/bar");
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
@@ -77,7 +76,7 @@ public class AbstractWebSocketHandlerRegistrationTests {
|
||||
@Test
|
||||
public void interceptors() {
|
||||
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandler();
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||
|
||||
this.registration.addHandler(wsHandler, "/foo").addInterceptors(interceptor);
|
||||
@@ -94,7 +93,7 @@ public class AbstractWebSocketHandlerRegistrationTests {
|
||||
@Test
|
||||
public void interceptorsPassedToSockJsRegistration() {
|
||||
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandler();
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||
|
||||
this.registration.addHandler(wsHandler, "/foo").addInterceptors(interceptor).withSockJS();
|
||||
@@ -112,7 +111,7 @@ public class AbstractWebSocketHandlerRegistrationTests {
|
||||
@Test
|
||||
public void handshakeHandler() {
|
||||
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandler();
|
||||
HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
|
||||
|
||||
this.registration.addHandler(wsHandler, "/foo").setHandshakeHandler(handshakeHandler);
|
||||
@@ -129,7 +128,7 @@ public class AbstractWebSocketHandlerRegistrationTests {
|
||||
@Test
|
||||
public void handshakeHandlerPassedToSockJsRegistration() {
|
||||
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler wsHandler = new TextWebSocketHandler();
|
||||
HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
|
||||
|
||||
this.registration.addHandler(wsHandler, "/foo").setHandshakeHandler(handshakeHandler).withSockJS();
|
||||
|
||||
@@ -31,12 +31,9 @@ import org.springframework.web.socket.AbstractWebSocketIntegrationTests;
|
||||
import org.springframework.web.socket.JettyWebSocketTestServer;
|
||||
import org.springframework.web.socket.TomcatWebSocketTestServer;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.client.endpoint.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
@@ -68,7 +65,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
public void registerWebSocketHandler() throws Exception {
|
||||
|
||||
WebSocketSession session = this.webSocketClient.doHandshake(
|
||||
new WebSocketHandlerAdapter(), getWsBaseUrl() + "/ws").get();
|
||||
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/ws").get();
|
||||
|
||||
TestWebSocketHandler serverHandler = this.wac.getBean(TestWebSocketHandler.class);
|
||||
assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
|
||||
@@ -80,7 +77,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
public void registerWebSocketHandlerWithSockJS() throws Exception {
|
||||
|
||||
WebSocketSession session = this.webSocketClient.doHandshake(
|
||||
new WebSocketHandlerAdapter(), getWsBaseUrl() + "/sockjs/websocket").get();
|
||||
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/sockjs/websocket").get();
|
||||
|
||||
TestWebSocketHandler serverHandler = this.wac.getBean(TestWebSocketHandler.class);
|
||||
assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
|
||||
@@ -113,7 +110,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestWebSocketHandler extends WebSocketHandlerAdapter {
|
||||
private static class TestWebSocketHandler extends AbstractWebSocketHandler {
|
||||
|
||||
private CountDownLatch connectLatch = new CountDownLatch(1);
|
||||
|
||||
|
||||
@@ -42,12 +42,9 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.messaging.StompTextMessageBuilder;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.socket.support.TestWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeanInstantiationException;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -14,14 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class PerConnectionWebSocketHandlerTests {
|
||||
}
|
||||
|
||||
|
||||
public static class EchoHandler extends WebSocketHandlerAdapter implements DisposableBean {
|
||||
public static class EchoHandler extends AbstractWebSocketHandler implements DisposableBean {
|
||||
|
||||
private static int initCount;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.adapter.WebSocketHandlerAdapter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -28,10 +27,10 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class WebSocketHandlerDecoratorTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void getLastHandler() {
|
||||
WebSocketHandlerAdapter h1 = new WebSocketHandlerAdapter();
|
||||
AbstractWebSocketHandler h1 = new AbstractWebSocketHandler() {
|
||||
};
|
||||
WebSocketHandlerDecorator h2 = new WebSocketHandlerDecorator(h1);
|
||||
WebSocketHandlerDecorator h3 = new WebSocketHandlerDecorator(h2);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.support;
|
||||
package org.springframework.web.socket.handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,6 +23,7 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -47,8 +47,8 @@ import org.springframework.web.socket.JettyWebSocketTestServer;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.TomcatWebSocketTestServer;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.client.endpoint.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
@@ -170,7 +170,7 @@ public class SimpAnnotationMethodIntegrationTests extends AbstractWebSocketInteg
|
||||
}
|
||||
|
||||
|
||||
private static class TestClientWebSocketHandler extends TextWebSocketHandlerAdapter {
|
||||
private static class TestClientWebSocketHandler extends TextWebSocketHandler {
|
||||
|
||||
private final TextMessage[] messagesToSend;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.messaging.simp.stomp.StompDecoder;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.support.TestWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.web.socket.support.TestWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.support.SubProtocolCapable;
|
||||
import org.springframework.web.socket.SubProtocolCapable;
|
||||
import org.springframework.web.socket.WebSocketExtension;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.adapter.TextWebSocketHandlerAdapter;
|
||||
import org.springframework.web.socket.support.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -72,7 +72,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||
headers.setSecWebSocketKey("82/ZS2YHjEnUN97HLL8tbw==");
|
||||
headers.setSecWebSocketProtocol("STOMP");
|
||||
|
||||
WebSocketHandler handler = new TextWebSocketHandlerAdapter();
|
||||
WebSocketHandler handler = new TextWebSocketHandler();
|
||||
Map<String, Object> attributes = Collections.<String, Object>emptyMap();
|
||||
this.handshakeHandler.doHandshake(this.request, this.response, handler, attributes);
|
||||
|
||||
@@ -125,7 +125,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
|
||||
}
|
||||
|
||||
|
||||
private static class SubProtocolCapableHandler extends TextWebSocketHandlerAdapter implements SubProtocolCapable {
|
||||
private static class SubProtocolCapableHandler extends TextWebSocketHandler implements SubProtocolCapable {
|
||||
|
||||
private final List<String> subProtocols;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.endpoint;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
@@ -28,13 +28,11 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.server.support.ServerEndpointExporter;
|
||||
import org.springframework.web.socket.server.support.ServerEndpointRegistration;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link org.springframework.web.socket.server.support.ServerEndpointExporter}.
|
||||
* Test fixture for {@link ServerEndpointExporter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.endpoint;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.EndpointConfig;
|
||||
@@ -26,12 +26,11 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.server.support.ServerEndpointRegistration;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link org.springframework.web.socket.server.support.ServerEndpointRegistration}.
|
||||
* Test fixture for {@link ServerEndpointRegistration}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.server.endpoint;
|
||||
package org.springframework.web.socket.server.standard;
|
||||
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.mock.web.test.MockServletContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.server.support.SpringConfigurator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsMessageDeliveryException;
|
||||
import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
|
||||
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSessionTests.TestWebSocketServerSockJsSession;
|
||||
import org.springframework.web.socket.support.TestWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
|
||||
Reference in New Issue
Block a user