Rename classes
This commit is contained in:
@@ -515,7 +515,6 @@ project("spring-websocket") {
|
||||
compile(project(":spring-core"))
|
||||
compile(project(":spring-context"))
|
||||
compile(project(":spring-web"))
|
||||
optional(project(":spring-webmvc"))
|
||||
|
||||
optional("org.apache.tomcat:tomcat-servlet-api:8.0-SNAPSHOT") // TODO: replace with "javax.servlet:javax.servlet-api"
|
||||
optional("org.apache.tomcat:tomcat-websocket-api:8.0-SNAPSHOT") // TODO: replace with "javax.websocket:javax.websocket-api"
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.springframework.websocket;
|
||||
*
|
||||
* <p> Implementations of this interface are encouraged to handle exceptions locally where
|
||||
* it makes sense or alternatively let the exception bubble up in which case the exception
|
||||
* is logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(101)} by default.
|
||||
* is logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)} by default.
|
||||
* The exception handling strategy is provided by
|
||||
* {@link org.springframework.websocket.support.ExceptionWebSocketHandlerDecorator ExceptionWebSocketHandlerDecorator},
|
||||
* which can be customized or replaced by decorating the {@link WebSocketHandler} with a
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractWebSocketConnectionManager implements SmartLifecycle {
|
||||
public abstract class ConnectionManagerSupport implements SmartLifecycle {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class AbstractWebSocketConnectionManager implements SmartLifecyc
|
||||
private final Object lifecycleMonitor = new Object();
|
||||
|
||||
|
||||
public AbstractWebSocketConnectionManager(String uriTemplate, Object... uriVariables) {
|
||||
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) {
|
||||
this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.websocket.support.LoggingWebSocketHandlerDecorator;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class WebSocketConnectionManager extends AbstractWebSocketConnectionManager {
|
||||
public class WebSocketConnectionManager extends ConnectionManagerSupport {
|
||||
|
||||
private final WebSocketClient client;
|
||||
|
||||
|
||||
@@ -16,23 +16,29 @@
|
||||
|
||||
package org.springframework.websocket.client.endpoint;
|
||||
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.websocket.client.ConnectionManagerSupport;
|
||||
import org.springframework.websocket.support.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class AnnotatedEndpointConnectionManager extends EndpointConnectionManagerSupport
|
||||
implements BeanFactoryAware {
|
||||
public class AnnotatedEndpointConnectionManager extends ConnectionManagerSupport implements BeanFactoryAware {
|
||||
|
||||
private final Object endpoint;
|
||||
|
||||
private final BeanCreatingHandlerProvider<Object> endpointProvider;
|
||||
|
||||
private final Object endpoint;
|
||||
private WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
private Session session;
|
||||
|
||||
|
||||
public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, Object... uriVariables) {
|
||||
@@ -48,6 +54,14 @@ public class AnnotatedEndpointConnectionManager extends EndpointConnectionManage
|
||||
}
|
||||
|
||||
|
||||
public void setWebSocketContainer(WebSocketContainer webSocketContainer) {
|
||||
this.webSocketContainer = webSocketContainer;
|
||||
}
|
||||
|
||||
public WebSocketContainer getWebSocketContainer() {
|
||||
return this.webSocketContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
if (this.endpointProvider != null) {
|
||||
@@ -58,8 +72,24 @@ public class AnnotatedEndpointConnectionManager extends EndpointConnectionManage
|
||||
@Override
|
||||
protected void openConnection() throws Exception {
|
||||
Object endpoint = (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
|
||||
Session session = getWebSocketContainer().connectToServer(endpoint, getUri());
|
||||
updateSession(session);
|
||||
this.session = this.webSocketContainer.connectToServer(endpoint, getUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeConnection() throws Exception {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
this.session.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.session = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConnected() {
|
||||
return ((this.session != null) && this.session.isOpen());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,29 +21,36 @@ import java.util.List;
|
||||
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
import javax.websocket.ClientEndpointConfig.Configurator;
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Decoder;
|
||||
import javax.websocket.Encoder;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.Extension;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
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.websocket.client.ConnectionManagerSupport;
|
||||
import org.springframework.websocket.support.BeanCreatingHandlerProvider;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class EndpointConnectionManager extends EndpointConnectionManagerSupport implements BeanFactoryAware {
|
||||
public class EndpointConnectionManager extends ConnectionManagerSupport implements BeanFactoryAware {
|
||||
|
||||
private final ClientEndpointConfig.Builder configBuilder = ClientEndpointConfig.Builder.create();
|
||||
private final Endpoint endpoint;
|
||||
|
||||
private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
|
||||
|
||||
private final Endpoint endpoint;
|
||||
private final ClientEndpointConfig.Builder configBuilder = ClientEndpointConfig.Builder.create();
|
||||
|
||||
private WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
private Session session;
|
||||
|
||||
|
||||
public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, Object... uriVariables) {
|
||||
@@ -81,6 +88,14 @@ public class EndpointConnectionManager extends EndpointConnectionManagerSupport
|
||||
this.configBuilder.configurator(configurator);
|
||||
}
|
||||
|
||||
public void setWebSocketContainer(WebSocketContainer webSocketContainer) {
|
||||
this.webSocketContainer = webSocketContainer;
|
||||
}
|
||||
|
||||
public WebSocketContainer getWebSocketContainer() {
|
||||
return this.webSocketContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
if (this.endpointProvider != null) {
|
||||
@@ -92,8 +107,24 @@ public class EndpointConnectionManager extends EndpointConnectionManagerSupport
|
||||
protected void openConnection() throws Exception {
|
||||
Endpoint endpoint = (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
|
||||
ClientEndpointConfig endpointConfig = this.configBuilder.build();
|
||||
Session session = getWebSocketContainer().connectToServer(endpoint, endpointConfig, getUri());
|
||||
updateSession(session);
|
||||
this.session = getWebSocketContainer().connectToServer(endpoint, endpointConfig, getUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeConnection() throws Exception {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
this.session.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.session = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConnected() {
|
||||
return ((this.session != null) && this.session.isOpen());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,70 +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.websocket.client.endpoint;
|
||||
|
||||
import javax.websocket.ContainerProvider;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.WebSocketContainer;
|
||||
|
||||
import org.springframework.websocket.client.AbstractWebSocketConnectionManager;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class EndpointConnectionManagerSupport extends AbstractWebSocketConnectionManager {
|
||||
|
||||
private WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
|
||||
|
||||
private Session session;
|
||||
|
||||
|
||||
public EndpointConnectionManagerSupport(String uriTemplate, Object... uriVariables) {
|
||||
super(uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
|
||||
public void setWebSocketContainer(WebSocketContainer webSocketContainer) {
|
||||
this.webSocketContainer = webSocketContainer;
|
||||
}
|
||||
|
||||
public WebSocketContainer getWebSocketContainer() {
|
||||
return this.webSocketContainer;
|
||||
}
|
||||
|
||||
protected void updateSession(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeConnection() throws Exception {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
this.session.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.session = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConnected() {
|
||||
return ((this.session != null) && this.session.isOpen());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ import org.springframework.websocket.WebSocketHandler;
|
||||
* <p>
|
||||
* A container-specific {@link RequestUpgradeStrategy} is required since standard Java
|
||||
* WebSocket currently does not provide a way to initiate a WebSocket handshake.
|
||||
* Currently available are implementations for Tomcat and Glassfish.
|
||||
* Currently available are implementations for Tomcat and GlassFish.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
@@ -218,7 +218,7 @@ public class DefaultHandshakeHandler implements HandshakeHandler {
|
||||
private static final boolean tomcatWebSocketPresent = ClassUtils.isPresent(
|
||||
"org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean glassfishWebSocketPresent = ClassUtils.isPresent(
|
||||
private static final boolean glassFishWebSocketPresent = ClassUtils.isPresent(
|
||||
"org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
|
||||
|
||||
private static final boolean jettyWebSocketPresent = ClassUtils.isPresent(
|
||||
@@ -229,8 +229,8 @@ public class DefaultHandshakeHandler implements HandshakeHandler {
|
||||
if (tomcatWebSocketPresent) {
|
||||
className = "org.springframework.websocket.server.support.TomcatRequestUpgradeStrategy";
|
||||
}
|
||||
else if (glassfishWebSocketPresent) {
|
||||
className = "org.springframework.websocket.server.support.GlassfishRequestUpgradeStrategy";
|
||||
else if (glassFishWebSocketPresent) {
|
||||
className = "org.springframework.websocket.server.support.GlassFishRequestUpgradeStrategy";
|
||||
}
|
||||
else if (jettyWebSocketPresent) {
|
||||
className = "org.springframework.websocket.server.support.JettyRequestUpgradeStrategy";
|
||||
|
||||
@@ -52,13 +52,13 @@ import org.springframework.websocket.server.HandshakeFailureException;
|
||||
import org.springframework.websocket.server.endpoint.EndpointRegistration;
|
||||
|
||||
/**
|
||||
* Glassfish support for upgrading an {@link HttpServletRequest} during a WebSocket
|
||||
* GlassFish support for upgrading an {@link HttpServletRequest} during a WebSocket
|
||||
* handshake.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class GlassfishRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
|
||||
public class GlassFishRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
|
||||
|
||||
private final static Random random = new Random();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class GlassfishRequestUpgradeStrategy extends AbstractEndpointUpgradeStra
|
||||
engine.register(tyrusEndpoint);
|
||||
}
|
||||
catch (DeploymentException ex) {
|
||||
throw new HandshakeFailureException("Failed to deploy endpoint in Glassfish", ex);
|
||||
throw new HandshakeFailureException("Failed to deploy endpoint in GlassFish", ex);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -140,13 +140,13 @@ public class GlassfishRequestUpgradeStrategy extends AbstractEndpointUpgradeStra
|
||||
private Connection createConnection(TyrusHttpUpgradeHandler handler, HttpServletResponse response) {
|
||||
try {
|
||||
String name = "org.glassfish.tyrus.servlet.ConnectionImpl";
|
||||
Class<?> clazz = ClassUtils.forName(name, GlassfishRequestUpgradeStrategy.class.getClassLoader());
|
||||
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);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Failed to instantiate Glassfish connection", ex);
|
||||
throw new IllegalStateException("Failed to instantiate GlassFish connection", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,23 +48,23 @@ import org.springframework.websocket.WebSocketSession;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler, BeanFactoryAware {
|
||||
public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFactoryAware {
|
||||
|
||||
private Log logger = LogFactory.getLog(PerConnectionWebSocketHandlerProxy.class);
|
||||
private static final Log logger = LogFactory.getLog(PerConnectionWebSocketHandler.class);
|
||||
|
||||
private final BeanCreatingHandlerProvider<WebSocketHandler> provider;
|
||||
|
||||
private Map<WebSocketSession, WebSocketHandler> handlers =
|
||||
private final Map<WebSocketSession, WebSocketHandler> handlers =
|
||||
new ConcurrentHashMap<WebSocketSession, WebSocketHandler>();
|
||||
|
||||
private boolean streaming;
|
||||
private final boolean streaming;
|
||||
|
||||
|
||||
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler> handlerType) {
|
||||
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType) {
|
||||
this(handlerType, false);
|
||||
}
|
||||
|
||||
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
|
||||
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
|
||||
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler>(handlerType);
|
||||
this.streaming = isStreaming;
|
||||
}
|
||||
Reference in New Issue
Block a user