001/*
002 * Copyright 2002-2016 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.sockjs.transport;
018
019import org.springframework.http.server.ServerHttpRequest;
020import org.springframework.http.server.ServerHttpResponse;
021import org.springframework.web.socket.WebSocketHandler;
022import org.springframework.web.socket.sockjs.SockJsException;
023import org.springframework.web.socket.sockjs.SockJsService;
024
025/**
026 * Handle a SockJS session URL, i.e. transport-specific request.
027 *
028 * @author Rossen Stoyanchev
029 * @author Juergen Hoeller
030 * @since 4.0
031 */
032public interface TransportHandler {
033
034        /**
035         * Initialize this handler with the given configuration.
036         * @param serviceConfig the configuration as defined by the containing
037         * {@link org.springframework.web.socket.sockjs.SockJsService}
038         */
039        void initialize(SockJsServiceConfig serviceConfig);
040
041        /**
042         * Return the transport type supported by this handler.
043         */
044        TransportType getTransportType();
045
046        /**
047         * Check whether the type of the given session matches the transport type
048         * of this {@code TransportHandler} where session id and the transport type
049         * are extracted from the SockJS URL.
050         * @return {@code true} if the session matches (and would therefore get
051         * accepted by {@link #handleRequest}), or {@code false} otherwise
052         * @since 4.3.4
053         */
054        boolean checkSessionType(SockJsSession session);
055
056        /**
057         * Handle the given request and delegate messages to the provided
058         * {@link WebSocketHandler}.
059         * @param request the current request
060         * @param response the current response
061         * @param handler the target WebSocketHandler (never {@code null})
062         * @param session the SockJS session (never {@code null})
063         * @throws SockJsException raised when request processing fails as
064         * explained in {@link SockJsService}
065         */
066        void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
067                        WebSocketHandler handler, SockJsSession session) throws SockJsException;
068
069}