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.util.Map; 020 021import org.springframework.http.server.ServerHttpRequest; 022import org.springframework.http.server.ServerHttpResponse; 023import org.springframework.web.socket.WebSocketHandler; 024import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; 025 026/** 027 * Contract for processing a WebSocket handshake request. 028 * 029 * @author Rossen Stoyanchev 030 * @since 4.0 031 * @see HandshakeInterceptor 032 * @see org.springframework.web.socket.server.support.WebSocketHttpRequestHandler 033 * @see org.springframework.web.socket.sockjs.SockJsService 034 */ 035public interface HandshakeHandler { 036 037 /** 038 * Initiate the handshake. 039 * @param request the current request 040 * @param response the current response 041 * @param wsHandler the handler to process WebSocket messages; see 042 * {@link PerConnectionWebSocketHandler} for providing a handler with 043 * per-connection lifecycle. 044 * @param attributes the attributes from the HTTP handshake to associate with the WebSocket 045 * session; the provided attributes are copied, the original map is not used. 046 * @return whether the handshake negotiation was successful or not. In either case the 047 * response status, headers, and body will have been updated to reflect the 048 * result of the negotiation 049 * @throws HandshakeFailureException thrown when handshake processing failed to 050 * complete due to an internal, unrecoverable error, i.e. a server error as 051 * opposed to a failure to successfully negotiate the handshake. 052 */ 053 boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, 054 Map<String, Object> attributes) throws HandshakeFailureException; 055 056}