001/*
002 * Copyright 2002-2018 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;
018
019import org.springframework.http.server.ServerHttpRequest;
020import org.springframework.http.server.ServerHttpResponse;
021import org.springframework.lang.Nullable;
022import org.springframework.web.socket.WebSocketHandler;
023import org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator;
024
025/**
026 * The main entry point for processing HTTP requests from SockJS clients.
027 *
028 * <p>In a Servlet 3+ container, {@link org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler}
029 * can be used to invoke this service. The processing servlet, as well as all filters involved,
030 * must have asynchronous support enabled through the ServletContext API or by adding an
031 * <code>&lt;async-support&gt;true&lt;/async-support&gt;</code> element to servlet and filter declarations
032 * in web.xml.
033 *
034 * @author Rossen Stoyanchev
035 * @since 4.0
036 * @see org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler
037 */
038public interface SockJsService {
039
040        /**
041         * Process a SockJS HTTP request.
042         * <p>See the "Base URL", "Static URLs", and "Session URLs" sections of the <a
043         * href="https://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html">SockJS
044         * protocol</a> for details on the types of URLs expected.
045         * @param request the current request
046         * @param response the current response
047         * @param sockJsPath the remainder of the path within the SockJS service prefix
048         * @param handler the handler that will exchange messages with the SockJS client
049         * @throws SockJsException raised when request processing fails; generally, failed
050         * attempts to send messages to clients automatically close the SockJS session
051         * and raise {@link SockJsTransportFailureException}; failed attempts to read
052         * messages from clients do not automatically close the session and may result
053         * in {@link SockJsMessageDeliveryException} or {@link SockJsException};
054         * exceptions from the WebSocketHandler can be handled internally or through
055         * {@link ExceptionWebSocketHandlerDecorator} or some alternative decorator.
056         * The former is automatically added when using
057         * {@link org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler}.
058         */
059        void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
060                        @Nullable String sockJsPath, WebSocketHandler handler) throws SockJsException;
061
062}