001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.socket.server; 018 019import java.security.Principal; 020import java.util.List; 021import java.util.Map; 022 023import org.springframework.http.server.ServerHttpRequest; 024import org.springframework.http.server.ServerHttpResponse; 025import org.springframework.web.socket.WebSocketExtension; 026import org.springframework.web.socket.WebSocketHandler; 027 028/** 029 * A server-specific strategy for performing the actual upgrade to a WebSocket exchange. 030 * 031 * @author Rossen Stoyanchev 032 * @since 4.0 033 */ 034public interface RequestUpgradeStrategy { 035 036 /** 037 * Return the supported WebSocket protocol versions. 038 */ 039 String[] getSupportedVersions(); 040 041 /** 042 * Return the WebSocket protocol extensions supported by the underlying WebSocket server. 043 */ 044 List<WebSocketExtension> getSupportedExtensions(ServerHttpRequest request); 045 046 /** 047 * Perform runtime specific steps to complete the upgrade. Invoked after successful 048 * negotiation of the handshake request. 049 * @param request the current request 050 * @param response the current response 051 * @param selectedProtocol the selected sub-protocol, if any 052 * @param selectedExtensions the selected WebSocket protocol extensions 053 * @param user the user to associate with the WebSocket session 054 * @param wsHandler the handler for WebSocket messages 055 * @param attributes handshake request specific attributes to be set on the WebSocket 056 * session via {@link org.springframework.web.socket.server.HandshakeInterceptor} and 057 * thus made available to the {@link org.springframework.web.socket.WebSocketHandler} 058 * @throws HandshakeFailureException thrown when handshake processing failed to 059 * complete due to an internal, unrecoverable error, i.e. a server error as 060 * opposed to a failure to successfully negotiate the requirements of the 061 * handshake request. 062 */ 063 void upgrade(ServerHttpRequest request, ServerHttpResponse response, 064 String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, 065 WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException; 066 067}