Skip to content

Commit 1dff45c

Browse files
committed
Consistent ".jetty" and ".standard" subpackages; consolidated GlassFishRequestUpgradeStrategy implementation; renamed Text/BinaryWebSocketHandler and moved them to web.socket.support
1 parent 7713a55 commit 1dff45c

File tree

85 files changed

+544
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+544
-413
lines changed
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.web.socket.server.support;
17+
package org.springframework.web.socket;
1818

19-
import org.glassfish.tyrus.core.EndpointWrapper;
20-
import org.glassfish.tyrus.core.TyrusEndpoint;
21-
import org.glassfish.tyrus.websockets.WebSocketApplication;
19+
import java.util.List;
2220

2321
/**
24-
* Extension of the {@link AbstractGlassFishRequestUpgradeStrategy} that provides support
25-
* for GlassFish 4.0.1 and beyond.
22+
* An interface for WebSocket handlers that support sub-protocols as defined in RFC 6455.
2623
*
2724
* @author Rossen Stoyanchev
28-
* @author Michael Irwin
2925
* @since 4.0
26+
* @see WebSocketHandler
27+
* @see <a href="http://tools.ietf.org/html/rfc6455#section-1.9">RFC-6455 section 1.9</a>
3028
*/
31-
public class GlassFishRequestUpgradeStrategy extends AbstractGlassFishRequestUpgradeStrategy {
29+
public interface SubProtocolCapable {
3230

33-
@Override
34-
protected WebSocketApplication createTyrusEndpoint(EndpointWrapper endpoint) {
35-
return new TyrusEndpoint(endpoint);
36-
}
31+
/**
32+
* Return the list of supported sub-protocols.
33+
*/
34+
List<String> getSubProtocols();
3735

3836
}

spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import java.util.Locale;
2424
import java.util.Map;
2525

26-
import javax.websocket.Extension;
27-
28-
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
2926
import org.springframework.util.Assert;
3027
import org.springframework.util.CollectionUtils;
3128
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -177,64 +174,4 @@ public String toString() {
177174
return str.toString();
178175
}
179176

180-
181-
// Standard WebSocketExtension adapters
182-
183-
public static class StandardToWebSocketExtensionAdapter extends WebSocketExtension {
184-
185-
public StandardToWebSocketExtensionAdapter(Extension ext) {
186-
super(ext.getName());
187-
for (Extension.Parameter p : ext.getParameters()) {
188-
super.getParameters().put(p.getName(), p.getValue());
189-
}
190-
}
191-
}
192-
193-
public static class WebSocketToStandardExtensionAdapter implements Extension {
194-
195-
private final String name;
196-
197-
private final List<Parameter> parameters = new ArrayList<Parameter>();
198-
199-
public WebSocketToStandardExtensionAdapter(final WebSocketExtension ext) {
200-
this.name = ext.getName();
201-
for (final String paramName : ext.getParameters().keySet()) {
202-
this.parameters.add(new Parameter() {
203-
@Override
204-
public String getName() {
205-
return paramName;
206-
}
207-
@Override
208-
public String getValue() {
209-
return ext.getParameters().get(paramName);
210-
}
211-
});
212-
}
213-
}
214-
215-
@Override
216-
public String getName() {
217-
return name;
218-
}
219-
220-
@Override
221-
public List<Parameter> getParameters() {
222-
return this.parameters;
223-
}
224-
}
225-
226-
// Jetty WebSocketExtension adapters
227-
228-
public static class WebSocketToJettyExtensionConfigAdapter extends ExtensionConfig {
229-
230-
public WebSocketToJettyExtensionConfigAdapter(WebSocketExtension extension) {
231-
super(extension.getName());
232-
for (Map.Entry<String,String> p : extension.getParameters().entrySet()) {
233-
super.setParameter(p.getKey(), p.getValue());
234-
}
235-
}
236-
}
237-
238-
239-
240177
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* the exception is logged and the session closed with
2525
* {@link CloseStatus#SERVER_ERROR SERVER_ERROR(1011)}. The exception handling
2626
* strategy is provided by
27-
* {@link org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator
27+
* {@link org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator
2828
* ExceptionWebSocketHandlerDecorator} and it can be customized or replaced by decorating
2929
* the {@link WebSocketHandler} with a different decorator.
3030
*
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.web.socket.support;
17+
package org.springframework.web.socket;
1818

1919
import java.util.ArrayList;
2020
import java.util.Collection;
@@ -25,7 +25,6 @@
2525

2626
import org.springframework.http.HttpHeaders;
2727
import org.springframework.util.CollectionUtils;
28-
import org.springframework.web.socket.WebSocketExtension;
2928

3029
/**
3130
* An {@link org.springframework.http.HttpHeaders} variant that adds support for
@@ -36,8 +35,6 @@
3635
*/
3736
public class WebSocketHttpHeaders extends HttpHeaders {
3837

39-
private static final long serialVersionUID = -6644521016187828916L;
40-
4138
public static final String SEC_WEBSOCKET_ACCEPT = "Sec-WebSocket-Accept";
4239

4340
public static final String SEC_WEBSOCKET_EXTENSIONS = "Sec-WebSocket-Extensions";
@@ -48,6 +45,9 @@ public class WebSocketHttpHeaders extends HttpHeaders {
4845

4946
public static final String SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
5047

48+
private static final long serialVersionUID = -6644521016187828916L;
49+
50+
5151
private final HttpHeaders headers;
5252

5353

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2002-2013 the original author or authors.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
2021

2122
import org.apache.commons.logging.Log;
2223
import org.apache.commons.logging.LogFactory;
24+
2325
import org.springframework.util.Assert;
2426
import org.springframework.web.socket.BinaryMessage;
2527
import org.springframework.web.socket.CloseStatus;
@@ -35,7 +37,7 @@
3537
* @author Rossen Stoyanchev
3638
* @since 4.0
3739
*/
38-
public abstract class AbstractWebSocketSesssion<T> implements WebSocketSession, NativeWebSocketSession {
40+
public abstract class AbstractWebSocketSession<T> implements NativeWebSocketSession {
3941

4042
protected final Log logger = LogFactory.getLog(getClass());
4143

@@ -49,7 +51,7 @@ public abstract class AbstractWebSocketSesssion<T> implements WebSocketSession,
4951
* @param handshakeAttributes attributes from the HTTP handshake to make available
5052
* through the WebSocket session
5153
*/
52-
public AbstractWebSocketSesssion(Map<String, Object> handshakeAttributes) {
54+
public AbstractWebSocketSession(Map<String, Object> handshakeAttributes) {
5355
this.handshakeAttributes = handshakeAttributes;
5456
}
5557

spring-websocket/src/main/java/org/springframework/web/socket/adapter/JettyWebSocketHandlerAdapter.java renamed to spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.web.socket.adapter;
17+
package org.springframework.web.socket.adapter.jetty;
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
@@ -33,7 +33,7 @@
3333
import org.springframework.web.socket.PongMessage;
3434
import org.springframework.web.socket.TextMessage;
3535
import org.springframework.web.socket.WebSocketHandler;
36-
import org.springframework.web.socket.support.ExceptionWebSocketHandlerDecorator;
36+
import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
3737

3838
/**
3939
* Adapts {@link WebSocketHandler} to the Jetty 9 WebSocket API.
@@ -52,10 +52,8 @@ public class JettyWebSocketHandlerAdapter {
5252

5353

5454
public JettyWebSocketHandlerAdapter(WebSocketHandler webSocketHandler, JettyWebSocketSession wsSession) {
55-
5655
Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
5756
Assert.notNull(wsSession, "wsSession must not be null");
58-
5957
this.webSocketHandler = webSocketHandler;
6058
this.wsSession = wsSession;
6159
}

spring-websocket/src/main/java/org/springframework/web/socket/adapter/JettyWebSocketSession.java renamed to spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.web.socket.adapter;
17+
package org.springframework.web.socket.adapter.jetty;
1818

1919
import java.io.IOException;
2020
import java.net.InetSocketAddress;
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.eclipse.jetty.websocket.api.Session;
2728
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
2829
import org.springframework.http.HttpHeaders;
2930
import org.springframework.util.ObjectUtils;
@@ -34,6 +35,7 @@
3435
import org.springframework.web.socket.TextMessage;
3536
import org.springframework.web.socket.WebSocketExtension;
3637
import org.springframework.web.socket.WebSocketSession;
38+
import org.springframework.web.socket.adapter.AbstractWebSocketSession;
3739

3840
/**
3941
* A {@link WebSocketSession} for use with the Jetty 9 WebSocket API.
@@ -42,7 +44,7 @@
4244
* @author Rossen Stoyanchev
4345
* @since 4.0
4446
*/
45-
public class JettyWebSocketSession extends AbstractWebSocketSesssion<org.eclipse.jetty.websocket.api.Session> {
47+
public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
4648

4749
private HttpHeaders headers;
4850

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.socket.adapter.jetty;
18+
19+
import java.util.Map;
20+
21+
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
22+
23+
import org.springframework.web.socket.WebSocketExtension;
24+
25+
/**
26+
* @author Rossen Stoyanchev
27+
* @since 4.0
28+
*/
29+
public class WebSocketToJettyExtensionConfigAdapter extends ExtensionConfig {
30+
31+
public WebSocketToJettyExtensionConfigAdapter(WebSocketExtension extension) {
32+
super(extension.getName());
33+
for (Map.Entry<String,String> p : extension.getParameters().entrySet()) {
34+
super.setParameter(p.getKey(), p.getValue());
35+
}
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Adapter classes for the Jetty WebSocket API.
19+
*/
20+
package org.springframework.web.socket.adapter.jetty;
21+

spring-websocket/src/main/java/org/springframework/web/socket/adapter/package-info.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616

1717
/**
18-
* Classes adapting Spring's WebSocket API classes to and from WebSocket
19-
* implementations. Also contains convenient base classes for
20-
* {@link org.springframework.web.socket.WebSocketHandler} implementations.
18+
* Classes adapting Spring's WebSocket API to and from WebSocket providers.
2119
*/
2220
package org.springframework.web.socket.adapter;
2321

0 commit comments

Comments
 (0)