Skip to content

Commit 4faf0d2

Browse files
committed
Rename classes
1 parent 2a7935a commit 4faf0d2

10 files changed

+90
-100
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ project("spring-websocket") {
515515
compile(project(":spring-core"))
516516
compile(project(":spring-context"))
517517
compile(project(":spring-web"))
518-
optional(project(":spring-webmvc"))
519518

520519
optional("org.apache.tomcat:tomcat-servlet-api:8.0-SNAPSHOT") // TODO: replace with "javax.servlet:javax.servlet-api"
521520
optional("org.apache.tomcat:tomcat-websocket-api:8.0-SNAPSHOT") // TODO: replace with "javax.websocket:javax.websocket-api"

spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* <p> Implementations of this interface are encouraged to handle exceptions locally where
2323
* it makes sense or alternatively let the exception bubble up in which case the exception
24-
* is logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(101)} by default.
24+
* is logged and the session closed with {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)} by default.
2525
* The exception handling strategy is provided by
2626
* {@link org.springframework.websocket.support.ExceptionWebSocketHandlerDecorator ExceptionWebSocketHandlerDecorator},
2727
* which can be customized or replaced by decorating the {@link WebSocketHandler} with a
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Rossen Stoyanchev
3232
* @since 4.0
3333
*/
34-
public abstract class AbstractWebSocketConnectionManager implements SmartLifecycle {
34+
public abstract class ConnectionManagerSupport implements SmartLifecycle {
3535

3636
protected final Log logger = LogFactory.getLog(getClass());
3737

@@ -49,7 +49,7 @@ public abstract class AbstractWebSocketConnectionManager implements SmartLifecyc
4949
private final Object lifecycleMonitor = new Object();
5050

5151

52-
public AbstractWebSocketConnectionManager(String uriTemplate, Object... uriVariables) {
52+
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) {
5353
this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri();
5454
}
5555

spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Rossen Stoyanchev
3232
* @since 4.0
3333
*/
34-
public class WebSocketConnectionManager extends AbstractWebSocketConnectionManager {
34+
public class WebSocketConnectionManager extends ConnectionManagerSupport {
3535

3636
private final WebSocketClient client;
3737

spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/AnnotatedEndpointConnectionManager.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,29 @@
1616

1717
package org.springframework.websocket.client.endpoint;
1818

19+
import javax.websocket.ContainerProvider;
1920
import javax.websocket.Session;
21+
import javax.websocket.WebSocketContainer;
2022

2123
import org.springframework.beans.BeansException;
2224
import org.springframework.beans.factory.BeanFactory;
2325
import org.springframework.beans.factory.BeanFactoryAware;
26+
import org.springframework.websocket.client.ConnectionManagerSupport;
2427
import org.springframework.websocket.support.BeanCreatingHandlerProvider;
2528

2629
/**
2730
* @author Rossen Stoyanchev
2831
* @since 4.0
2932
*/
30-
public class AnnotatedEndpointConnectionManager extends EndpointConnectionManagerSupport
31-
implements BeanFactoryAware {
33+
public class AnnotatedEndpointConnectionManager extends ConnectionManagerSupport implements BeanFactoryAware {
34+
35+
private final Object endpoint;
3236

3337
private final BeanCreatingHandlerProvider<Object> endpointProvider;
3438

35-
private final Object endpoint;
39+
private WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
40+
41+
private Session session;
3642

3743

3844
public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, Object... uriVariables) {
@@ -48,6 +54,14 @@ public AnnotatedEndpointConnectionManager(Class<?> endpointClass, String uriTemp
4854
}
4955

5056

57+
public void setWebSocketContainer(WebSocketContainer webSocketContainer) {
58+
this.webSocketContainer = webSocketContainer;
59+
}
60+
61+
public WebSocketContainer getWebSocketContainer() {
62+
return this.webSocketContainer;
63+
}
64+
5165
@Override
5266
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
5367
if (this.endpointProvider != null) {
@@ -58,8 +72,24 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
5872
@Override
5973
protected void openConnection() throws Exception {
6074
Object endpoint = (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
61-
Session session = getWebSocketContainer().connectToServer(endpoint, getUri());
62-
updateSession(session);
75+
this.session = this.webSocketContainer.connectToServer(endpoint, getUri());
76+
}
77+
78+
@Override
79+
protected void closeConnection() throws Exception {
80+
try {
81+
if (isConnected()) {
82+
this.session.close();
83+
}
84+
}
85+
finally {
86+
this.session = null;
87+
}
88+
}
89+
90+
@Override
91+
protected boolean isConnected() {
92+
return ((this.session != null) && this.session.isOpen());
6393
}
6494

6595
}

spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/EndpointConnectionManager.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,36 @@
2121

2222
import javax.websocket.ClientEndpointConfig;
2323
import javax.websocket.ClientEndpointConfig.Configurator;
24+
import javax.websocket.ContainerProvider;
2425
import javax.websocket.Decoder;
2526
import javax.websocket.Encoder;
2627
import javax.websocket.Endpoint;
2728
import javax.websocket.Extension;
2829
import javax.websocket.Session;
30+
import javax.websocket.WebSocketContainer;
2931

3032
import org.springframework.beans.BeansException;
3133
import org.springframework.beans.factory.BeanFactory;
3234
import org.springframework.beans.factory.BeanFactoryAware;
3335
import org.springframework.util.Assert;
36+
import org.springframework.websocket.client.ConnectionManagerSupport;
3437
import org.springframework.websocket.support.BeanCreatingHandlerProvider;
3538

3639
/**
3740
* @author Rossen Stoyanchev
3841
* @since 4.0
3942
*/
40-
public class EndpointConnectionManager extends EndpointConnectionManagerSupport implements BeanFactoryAware {
43+
public class EndpointConnectionManager extends ConnectionManagerSupport implements BeanFactoryAware {
4144

42-
private final ClientEndpointConfig.Builder configBuilder = ClientEndpointConfig.Builder.create();
45+
private final Endpoint endpoint;
4346

4447
private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
4548

46-
private final Endpoint endpoint;
49+
private final ClientEndpointConfig.Builder configBuilder = ClientEndpointConfig.Builder.create();
50+
51+
private WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
52+
53+
private Session session;
4754

4855

4956
public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, Object... uriVariables) {
@@ -81,6 +88,14 @@ public void setConfigurator(Configurator configurator) {
8188
this.configBuilder.configurator(configurator);
8289
}
8390

91+
public void setWebSocketContainer(WebSocketContainer webSocketContainer) {
92+
this.webSocketContainer = webSocketContainer;
93+
}
94+
95+
public WebSocketContainer getWebSocketContainer() {
96+
return this.webSocketContainer;
97+
}
98+
8499
@Override
85100
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
86101
if (this.endpointProvider != null) {
@@ -92,8 +107,24 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
92107
protected void openConnection() throws Exception {
93108
Endpoint endpoint = (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
94109
ClientEndpointConfig endpointConfig = this.configBuilder.build();
95-
Session session = getWebSocketContainer().connectToServer(endpoint, endpointConfig, getUri());
96-
updateSession(session);
110+
this.session = getWebSocketContainer().connectToServer(endpoint, endpointConfig, getUri());
111+
}
112+
113+
@Override
114+
protected void closeConnection() throws Exception {
115+
try {
116+
if (isConnected()) {
117+
this.session.close();
118+
}
119+
}
120+
finally {
121+
this.session = null;
122+
}
123+
}
124+
125+
@Override
126+
protected boolean isConnected() {
127+
return ((this.session != null) && this.session.isOpen());
97128
}
98129

99130
}

spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/EndpointConnectionManagerSupport.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* <p>
4545
* A container-specific {@link RequestUpgradeStrategy} is required since standard Java
4646
* WebSocket currently does not provide a way to initiate a WebSocket handshake.
47-
* Currently available are implementations for Tomcat and Glassfish.
47+
* Currently available are implementations for Tomcat and GlassFish.
4848
*
4949
* @author Rossen Stoyanchev
5050
* @since 4.0
@@ -218,7 +218,7 @@ private static class RequestUpgradeStrategyFactory {
218218
private static final boolean tomcatWebSocketPresent = ClassUtils.isPresent(
219219
"org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
220220

221-
private static final boolean glassfishWebSocketPresent = ClassUtils.isPresent(
221+
private static final boolean glassFishWebSocketPresent = ClassUtils.isPresent(
222222
"org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler", DefaultHandshakeHandler.class.getClassLoader());
223223

224224
private static final boolean jettyWebSocketPresent = ClassUtils.isPresent(
@@ -229,8 +229,8 @@ private RequestUpgradeStrategy create() {
229229
if (tomcatWebSocketPresent) {
230230
className = "org.springframework.websocket.server.support.TomcatRequestUpgradeStrategy";
231231
}
232-
else if (glassfishWebSocketPresent) {
233-
className = "org.springframework.websocket.server.support.GlassfishRequestUpgradeStrategy";
232+
else if (glassFishWebSocketPresent) {
233+
className = "org.springframework.websocket.server.support.GlassFishRequestUpgradeStrategy";
234234
}
235235
else if (jettyWebSocketPresent) {
236236
className = "org.springframework.websocket.server.support.JettyRequestUpgradeStrategy";
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
import org.springframework.websocket.server.endpoint.EndpointRegistration;
5353

5454
/**
55-
* Glassfish support for upgrading an {@link HttpServletRequest} during a WebSocket
55+
* GlassFish support for upgrading an {@link HttpServletRequest} during a WebSocket
5656
* handshake.
5757
*
5858
* @author Rossen Stoyanchev
5959
* @since 4.0
6060
*/
61-
public class GlassfishRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
61+
public class GlassFishRequestUpgradeStrategy extends AbstractEndpointUpgradeStrategy {
6262

6363
private final static Random random = new Random();
6464

@@ -86,7 +86,7 @@ public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse respon
8686
engine.register(tyrusEndpoint);
8787
}
8888
catch (DeploymentException ex) {
89-
throw new HandshakeFailureException("Failed to deploy endpoint in Glassfish", ex);
89+
throw new HandshakeFailureException("Failed to deploy endpoint in GlassFish", ex);
9090
}
9191

9292
try {
@@ -140,13 +140,13 @@ private TyrusEndpoint createTyrusEndpoint(HttpServletRequest request, Endpoint e
140140
private Connection createConnection(TyrusHttpUpgradeHandler handler, HttpServletResponse response) {
141141
try {
142142
String name = "org.glassfish.tyrus.servlet.ConnectionImpl";
143-
Class<?> clazz = ClassUtils.forName(name, GlassfishRequestUpgradeStrategy.class.getClassLoader());
143+
Class<?> clazz = ClassUtils.forName(name, GlassFishRequestUpgradeStrategy.class.getClassLoader());
144144
Constructor<?> constructor = clazz.getDeclaredConstructor(TyrusHttpUpgradeHandler.class, HttpServletResponse.class);
145145
ReflectionUtils.makeAccessible(constructor);
146146
return (Connection) constructor.newInstance(handler, response);
147147
}
148148
catch (Exception ex) {
149-
throw new IllegalStateException("Failed to instantiate Glassfish connection", ex);
149+
throw new IllegalStateException("Failed to instantiate GlassFish connection", ex);
150150
}
151151
}
152152

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@
4848
* @author Rossen Stoyanchev
4949
* @since 4.0
5050
*/
51-
public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler, BeanFactoryAware {
51+
public class PerConnectionWebSocketHandler implements WebSocketHandler, BeanFactoryAware {
5252

53-
private Log logger = LogFactory.getLog(PerConnectionWebSocketHandlerProxy.class);
53+
private static final Log logger = LogFactory.getLog(PerConnectionWebSocketHandler.class);
5454

5555
private final BeanCreatingHandlerProvider<WebSocketHandler> provider;
5656

57-
private Map<WebSocketSession, WebSocketHandler> handlers =
57+
private final Map<WebSocketSession, WebSocketHandler> handlers =
5858
new ConcurrentHashMap<WebSocketSession, WebSocketHandler>();
5959

60-
private boolean streaming;
60+
private final boolean streaming;
6161

6262

63-
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler> handlerType) {
63+
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType) {
6464
this(handlerType, false);
6565
}
6666

67-
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
67+
public PerConnectionWebSocketHandler(Class<? extends WebSocketHandler> handlerType, boolean isStreaming) {
6868
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler>(handlerType);
6969
this.streaming = isStreaming;
7070
}

0 commit comments

Comments
 (0)