1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
43
43
*/
44
44
public abstract class AbstractWebSocketClient implements WebSocketClient {
45
45
46
- protected final Log logger = LogFactory .getLog (getClass ());
47
-
48
46
private static final Set <String > specialHeaders = new HashSet <String >();
49
47
50
48
static {
@@ -60,11 +58,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
60
58
}
61
59
62
60
61
+ protected final Log logger = LogFactory .getLog (getClass ());
62
+
63
+
63
64
@ Override
64
65
public ListenableFuture <WebSocketSession > doHandshake (WebSocketHandler webSocketHandler ,
65
66
String uriTemplate , Object ... uriVars ) {
66
67
67
- Assert .notNull (uriTemplate , "uriTemplate must not be null" );
68
+ Assert .notNull (uriTemplate , "' uriTemplate' must not be null" );
68
69
URI uri = UriComponentsBuilder .fromUriString (uriTemplate ).buildAndExpand (uriVars ).encode ().toUri ();
69
70
return doHandshake (webSocketHandler , null , uri );
70
71
}
@@ -73,7 +74,7 @@ public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocket
73
74
public final ListenableFuture <WebSocketSession > doHandshake (WebSocketHandler webSocketHandler ,
74
75
WebSocketHttpHeaders headers , URI uri ) {
75
76
76
- Assert .notNull (webSocketHandler , "webSocketHandler must not be null" );
77
+ Assert .notNull (webSocketHandler , "WebSocketHandler must not be null" );
77
78
assertUri (uri );
78
79
79
80
if (logger .isDebugEnabled ()) {
@@ -89,25 +90,26 @@ public final ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler web
89
90
}
90
91
}
91
92
92
- List <String > subProtocols = (( headers != null ) && ( headers .getSecWebSocketProtocol () != null )) ?
93
- headers .getSecWebSocketProtocol () : Collections .<String >emptyList ();
93
+ List <String > subProtocols = (headers != null && headers .getSecWebSocketProtocol () != null ?
94
+ headers .getSecWebSocketProtocol () : Collections .<String >emptyList ()) ;
94
95
95
- List <WebSocketExtension > extensions = (( headers != null ) && ( headers .getSecWebSocketExtensions () != null )) ?
96
- headers .getSecWebSocketExtensions () : Collections .<WebSocketExtension >emptyList ();
96
+ List <WebSocketExtension > extensions = (headers != null && headers .getSecWebSocketExtensions () != null ?
97
+ headers .getSecWebSocketExtensions () : Collections .<WebSocketExtension >emptyList ()) ;
97
98
98
99
return doHandshakeInternal (webSocketHandler , headersToUse , uri , subProtocols , extensions ,
99
100
Collections .<String , Object >emptyMap ());
100
101
}
101
102
102
103
protected void assertUri (URI uri ) {
103
- Assert .notNull (uri , "uri must not be null" );
104
+ Assert .notNull (uri , "URI must not be null" );
104
105
String scheme = uri .getScheme ();
105
- Assert .isTrue (scheme != null && ("ws" .equals (scheme ) || "wss" .equals (scheme )), "Invalid scheme: " + scheme );
106
+ if (!"ws" .equals (scheme ) && !"wss" .equals (scheme )) {
107
+ throw new IllegalArgumentException ("Invalid scheme: " + scheme );
108
+ }
106
109
}
107
110
108
111
/**
109
112
* Perform the actual handshake to establish a connection to the server.
110
- *
111
113
* @param webSocketHandler the client-side handler for WebSocket messages
112
114
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
113
115
* headers filtered out, never {@code null}
@@ -116,7 +118,6 @@ protected void assertUri(URI uri) {
116
118
* @param extensions requested WebSocket extensions, or an empty list
117
119
* @param attributes attributes to associate with the WebSocketSession, i.e. via
118
120
* {@link WebSocketSession#getAttributes()}; currently always an empty map.
119
- *
120
121
* @return the established WebSocket session wrapped in a ListenableFuture.
121
122
*/
122
123
protected abstract ListenableFuture <WebSocketSession > doHandshakeInternal (WebSocketHandler webSocketHandler ,
0 commit comments