View Javadoc
1   /*
2    * Copyright 2002-2014 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.server;
18  
19  import java.security.Principal;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.springframework.http.server.ServerHttpRequest;
24  import org.springframework.http.server.ServerHttpResponse;
25  import org.springframework.web.socket.WebSocketExtension;
26  import org.springframework.web.socket.WebSocketHandler;
27  
28  /**
29   * A server-specific strategy for performing the actual upgrade to a WebSocket exchange.
30   *
31   * @author Rossen Stoyanchev
32   * @since 4.0
33   */
34  public interface RequestUpgradeStrategy {
35  
36  	/**
37  	 * Return the supported WebSocket protocol versions.
38  	 */
39  	String[] getSupportedVersions();
40  
41  	/**
42  	 * Return the WebSocket protocol extensions supported by the underlying WebSocket server.
43  	 */
44  	List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request);
45  
46  	/**
47  	 * Perform runtime specific steps to complete the upgrade. Invoked after successful
48  	 * negotiation of the handshake request.
49  	 * @param request the current request
50  	 * @param response the current response
51  	 * @param selectedProtocol the selected sub-protocol, if any
52  	 * @param selectedExtensions the selected WebSocket protocol extensions
53  	 * @param user the user to associate with the WebSocket session
54  	 * @param wsHandler the handler for WebSocket messages
55  	 * @param attributes handshake request specific attributes to be set on the WebSocket
56  	 * session via {@link org.springframework.web.socket.server.HandshakeInterceptor} and
57  	 * thus made available to the {@link org.springframework.web.socket.WebSocketHandler}
58  	 * @throws HandshakeFailureException thrown when handshake processing failed to
59  	 * complete due to an internal, unrecoverable error, i.e. a server error as
60  	 * opposed to a failure to successfully negotiate the requirements of the
61  	 * handshake request.
62  	 */
63  	void upgrade(ServerHttpRequest request, ServerHttpResponse response,
64  			String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user,
65  			WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException;
66  
67  }