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