001/* 002 * Copyright 2002-2015 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.client; 018 019import java.net.URI; 020import java.security.Principal; 021 022import org.springframework.http.HttpHeaders; 023import org.springframework.lang.Nullable; 024import org.springframework.web.socket.sockjs.frame.SockJsMessageCodec; 025 026/** 027 * Exposes information, typically to {@link Transport} and 028 * {@link AbstractClientSockJsSession session} implementations, about a request 029 * to connect to a SockJS server endpoint over a given transport. 030 * 031 * <p>Note that a single request to connect via {@link SockJsClient} may result 032 * in multiple instances of {@link TransportRequest}, one for each transport 033 * before a connection is successfully established. 034 * 035 * @author Rossen Stoyanchev 036 * @since 4.1 037 */ 038public interface TransportRequest { 039 040 /** 041 * Return information about the SockJS URL including server and session ID. 042 */ 043 SockJsUrlInfo getSockJsUrlInfo(); 044 045 /** 046 * Return the headers to send with the connect request. 047 */ 048 HttpHeaders getHandshakeHeaders(); 049 050 /** 051 * Return the headers to add to all other HTTP requests besides the handshake 052 * request such as XHR receive and send requests. 053 * @since 4.2 054 */ 055 HttpHeaders getHttpRequestHeaders(); 056 057 /** 058 * Return the transport URL for the given transport. 059 * <p>For an {@link XhrTransport} this is the URL for receiving messages. 060 */ 061 URI getTransportUrl(); 062 063 /** 064 * Return the user associated with the request, if any. 065 */ 066 @Nullable 067 Principal getUser(); 068 069 /** 070 * Return the message codec to use for encoding SockJS messages. 071 */ 072 SockJsMessageCodec getMessageCodec(); 073 074 /** 075 * Register a timeout cleanup task to invoke if the SockJS session is not 076 * fully established within the calculated retransmission timeout period. 077 */ 078 void addTimeoutTask(Runnable runnable); 079 080}