org.springframework.web.socket.sockjs.transport.TransportType Java Examples
The following examples show how to use
org.springframework.web.socket.sockjs.transport.TransportType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSockJsServiceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Before public void setup() { super.setUp(); MockitoAnnotations.initMocks(this); Map<String, Object> attributes = Collections.emptyMap(); this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes); given(this.xhrHandler.getTransportType()).willReturn(TransportType.XHR); given(this.xhrHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session); given(this.xhrSendHandler.getTransportType()).willReturn(TransportType.XHR_SEND); given(this.jsonpHandler.getTransportType()).willReturn(TransportType.JSONP); given(this.jsonpHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session); given(this.jsonpSendHandler.getTransportType()).willReturn(TransportType.JSONP_SEND); given(this.wsTransportHandler.getTransportType()).willReturn(TransportType.WEBSOCKET); this.service = new TransportHandlingSockJsService(this.taskScheduler, this.xhrHandler, this.xhrSendHandler); }
Example #2
Source File: WebSocketHandlerRegistrationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void handshakeHandlerPassedToSockJsRegistration() { WebSocketHandler handler = new TextWebSocketHandler(); HandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler).withSockJS(); List<Mapping> mappings = this.registration.getMappings(); assertEquals(1, mappings.size()); Mapping mapping = mappings.get(0); assertEquals(handler, mapping.webSocketHandler); assertEquals("/foo/**", mapping.path); assertNotNull(mapping.sockJsService); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); }
Example #3
Source File: DefaultTransportRequestTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void fallbackAfterTimeout() throws Exception { TaskScheduler scheduler = mock(TaskScheduler.class); Runnable sessionCleanupTask = mock(Runnable.class); DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.setTimeoutScheduler(scheduler); request1.addTimeoutTask(sessionCleanupTask); request1.connect(null, this.connectFuture); assertTrue(this.webSocketTransport.invoked()); assertFalse(this.xhrTransport.invoked()); // Get and invoke the scheduled timeout task ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(scheduler).schedule(taskCaptor.capture(), any(Date.class)); verifyNoMoreInteractions(scheduler); taskCaptor.getValue().run(); assertTrue(this.xhrTransport.invoked()); verify(sessionCleanupTask).run(); }
Example #4
Source File: WebSocketHandlerRegistrationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void handshakeHandlerPassedToSockJsRegistration() { WebSocketHandler handler = new TextWebSocketHandler(); HandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler).withSockJS(); this.registration.getSockJsServiceRegistration().setTaskScheduler(this.taskScheduler); List<Mapping> mappings = this.registration.getMappings(); assertEquals(1, mappings.size()); Mapping mapping = mappings.get(0); assertEquals(handler, mapping.webSocketHandler); assertEquals("/foo/**", mapping.path); assertNotNull(mapping.sockJsService); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); }
Example #5
Source File: SockJsClient.java From spring4-understanding with Apache License 2.0 | 6 votes |
private DefaultTransportRequest createRequest(SockJsUrlInfo urlInfo, HttpHeaders headers, ServerInfo serverInfo) { List<DefaultTransportRequest> requests = new ArrayList<DefaultTransportRequest>(this.transports.size()); for (Transport transport : this.transports) { for (TransportType type : transport.getTransportTypes()) { if (serverInfo.isWebSocketEnabled() || !TransportType.WEBSOCKET.equals(type)) { requests.add(new DefaultTransportRequest(urlInfo, headers, getHttpRequestHeaders(headers), transport, type, getMessageCodec())); } } } if (CollectionUtils.isEmpty(requests)) { throw new IllegalStateException( "No transports: " + urlInfo + ", webSocketEnabled=" + serverInfo.isWebSocketEnabled()); } for (int i = 0; i < requests.size() - 1; i++) { DefaultTransportRequest request = requests.get(i); request.setUser(getUser()); if (this.connectTimeoutScheduler != null) { request.setTimeoutValue(serverInfo.getRetransmissionTimeout()); request.setTimeoutScheduler(this.connectTimeoutScheduler); } request.setFallbackRequest(requests.get(i + 1)); } return requests.get(0); }
Example #6
Source File: DefaultTransportRequestTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void fallbackAfterTransportError() throws Exception { DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.connect(null, this.connectFuture); // Transport error => fallback this.webSocketTransport.getConnectCallback().onFailure(new IOException("Fake exception 1")); assertFalse(this.connectFuture.isDone()); assertTrue(this.xhrTransport.invoked()); // Transport error => no more fallback this.xhrTransport.getConnectCallback().onFailure(new IOException("Fake exception 2")); assertTrue(this.connectFuture.isDone()); assertThatExceptionOfType(ExecutionException.class).isThrownBy( this.connectFuture::get) .withMessageContaining("Fake exception 2"); }
Example #7
Source File: DefaultTransportRequestTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void fallbackAfterTimeout() throws Exception { TaskScheduler scheduler = mock(TaskScheduler.class); Runnable sessionCleanupTask = mock(Runnable.class); DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.setTimeoutScheduler(scheduler); request1.addTimeoutTask(sessionCleanupTask); request1.connect(null, this.connectFuture); assertTrue(this.webSocketTransport.invoked()); assertFalse(this.xhrTransport.invoked()); // Get and invoke the scheduled timeout task ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(scheduler).schedule(taskCaptor.capture(), any(Date.class)); verifyNoMoreInteractions(scheduler); taskCaptor.getValue().run(); assertTrue(this.xhrTransport.invoked()); verify(sessionCleanupTask).run(); }
Example #8
Source File: DefaultTransportRequestTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void fallbackAfterTransportError() throws Exception { DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.connect(null, this.connectFuture); // Transport error => fallback this.webSocketTransport.getConnectCallback().onFailure(new IOException("Fake exception 1")); assertFalse(this.connectFuture.isDone()); assertTrue(this.xhrTransport.invoked()); // Transport error => no more fallback this.xhrTransport.getConnectCallback().onFailure(new IOException("Fake exception 2")); assertTrue(this.connectFuture.isDone()); this.thrown.expect(ExecutionException.class); this.thrown.expectMessage("Fake exception 2"); this.connectFuture.get(); }
Example #9
Source File: WebSocketHandlerRegistrationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void handshakeHandlerPassedToSockJsRegistration() { WebSocketHandler handler = new TextWebSocketHandler(); HandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler).withSockJS(); this.registration.getSockJsServiceRegistration().setTaskScheduler(this.taskScheduler); List<Mapping> mappings = this.registration.getMappings(); assertEquals(1, mappings.size()); Mapping mapping = mappings.get(0); assertEquals(handler, mapping.webSocketHandler); assertEquals("/foo/**", mapping.path); assertNotNull(mapping.sockJsService); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); }
Example #10
Source File: DefaultTransportRequestTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void fallbackAfterTransportError() throws Exception { DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.connect(null, this.connectFuture); // Transport error => fallback this.webSocketTransport.getConnectCallback().onFailure(new IOException("Fake exception 1")); assertFalse(this.connectFuture.isDone()); assertTrue(this.xhrTransport.invoked()); // Transport error => no more fallback this.xhrTransport.getConnectCallback().onFailure(new IOException("Fake exception 2")); assertTrue(this.connectFuture.isDone()); this.thrown.expect(ExecutionException.class); this.thrown.expectMessage("Fake exception 2"); this.connectFuture.get(); }
Example #11
Source File: DefaultTransportRequestTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void fallbackAfterTimeout() throws Exception { TaskScheduler scheduler = mock(TaskScheduler.class); Runnable sessionCleanupTask = mock(Runnable.class); DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); request1.setTimeoutScheduler(scheduler); request1.addTimeoutTask(sessionCleanupTask); request1.connect(null, this.connectFuture); assertTrue(this.webSocketTransport.invoked()); assertFalse(this.xhrTransport.invoked()); // Get and invoke the scheduled timeout task ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(scheduler).schedule(taskCaptor.capture(), any(Date.class)); verifyNoMoreInteractions(scheduler); taskCaptor.getValue().run(); assertTrue(this.xhrTransport.invoked()); verify(sessionCleanupTask).run(); }
Example #12
Source File: SockJsUrlInfoTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void transportUrl() throws Exception { testTransportUrl("http", "http", TransportType.XHR_STREAMING); testTransportUrl("http", "ws", TransportType.WEBSOCKET); testTransportUrl("https", "https", TransportType.XHR_STREAMING); testTransportUrl("https", "wss", TransportType.WEBSOCKET); testTransportUrl("ws", "http", TransportType.XHR_STREAMING); testTransportUrl("ws", "ws", TransportType.WEBSOCKET); testTransportUrl("wss", "https", TransportType.XHR_STREAMING); testTransportUrl("wss", "wss", TransportType.WEBSOCKET); }
Example #13
Source File: DefaultTransportRequestTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void connect() throws Exception { DefaultTransportRequest request = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); request.connect(null, this.connectFuture); WebSocketSession session = mock(WebSocketSession.class); this.webSocketTransport.getConnectCallback().onSuccess(session); assertSame(session, this.connectFuture.get()); }
Example #14
Source File: DefaultTransportRequest.java From spring4-understanding with Apache License 2.0 | 5 votes |
public DefaultTransportRequest(SockJsUrlInfo sockJsUrlInfo, HttpHeaders handshakeHeaders, HttpHeaders httpRequestHeaders, Transport transport, TransportType serverTransportType, SockJsMessageCodec codec) { Assert.notNull(sockJsUrlInfo, "SockJsUrlInfo is required"); Assert.notNull(transport, "Transport is required"); Assert.notNull(serverTransportType, "TransportType is required"); Assert.notNull(codec, "SockJsMessageCodec is required"); this.sockJsUrlInfo = sockJsUrlInfo; this.handshakeHeaders = (handshakeHeaders != null ? handshakeHeaders : new HttpHeaders()); this.httpRequestHeaders = (httpRequestHeaders != null ? httpRequestHeaders : new HttpHeaders()); this.transport = transport; this.serverTransportType = serverTransportType; this.codec = codec; }
Example #15
Source File: SockJsUrlInfoTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); String serverId = info.getServerId(); String sessionId = info.getSessionId(); String transport = transportType.toString().toLowerCase(); URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); assertThat(info.getTransportUrl(transportType), equalTo(expected)); }
Example #16
Source File: XhrClientSockJsSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
public XhrClientSockJsSession(TransportRequest request, WebSocketHandler handler, XhrTransport transport, SettableListenableFuture<WebSocketSession> connectFuture) { super(request, handler, connectFuture); Assert.notNull(transport, "'restTemplate' is required"); this.transport = transport; this.headers = request.getHttpRequestHeaders(); this.sendHeaders = new HttpHeaders(); if (this.headers != null) { this.sendHeaders.putAll(this.headers); } this.sendHeaders.setContentType(MediaType.APPLICATION_JSON); this.sendUrl = request.getSockJsUrlInfo().getTransportUrl(TransportType.XHR_SEND); }
Example #17
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler) .addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #18
Source File: RestTemplateXhrTransportTests.java From java-technology-stack with MIT License | 5 votes |
private ListenableFuture<WebSocketSession> connect(RestOperations restTemplate, ClientHttpResponse... responses) throws Exception { RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate); transport.setTaskExecutor(new SyncTaskExecutor()); SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("http://example.com")); HttpHeaders headers = new HttpHeaders(); headers.add("h-foo", "h-bar"); TransportRequest request = new DefaultTransportRequest(urlInfo, headers, headers, transport, TransportType.XHR, CODEC); return transport.connect(request, this.webSocketHandler); }
Example #19
Source File: SockJsUrlInfoTests.java From java-technology-stack with MIT License | 5 votes |
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); String serverId = info.getServerId(); String sessionId = info.getSessionId(); String transport = transportType.toString().toLowerCase(); URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); assertThat(info.getTransportUrl(transportType), equalTo(expected)); }
Example #20
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler(); HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(); String origin = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #21
Source File: SockJsUrlInfoTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void transportUrl() throws Exception { testTransportUrl("http", "http", TransportType.XHR_STREAMING); testTransportUrl("http", "ws", TransportType.WEBSOCKET); testTransportUrl("https", "https", TransportType.XHR_STREAMING); testTransportUrl("https", "wss", TransportType.WEBSOCKET); testTransportUrl("ws", "http", TransportType.XHR_STREAMING); testTransportUrl("ws", "ws", TransportType.WEBSOCKET); testTransportUrl("wss", "https", TransportType.XHR_STREAMING); testTransportUrl("wss", "wss", TransportType.WEBSOCKET); }
Example #22
Source File: DefaultSockJsServiceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customizedTransportHandlerList() { TransportHandlingSockJsService service = new TransportHandlingSockJsService( mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler()); Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers(); assertEquals(2, actualHandlers.size()); }
Example #23
Source File: ClientSockJsSessionTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() throws Exception { SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("http://example.com")); Transport transport = mock(Transport.class); TransportRequest request = new DefaultTransportRequest(urlInfo, null, null, transport, TransportType.XHR, CODEC); this.handler = mock(WebSocketHandler.class); this.connectFuture = new SettableListenableFuture<>(); this.session = new TestClientSockJsSession(request, this.handler, this.connectFuture); }
Example #24
Source File: DefaultSockJsServiceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void defaultTransportHandlersWithOverride() { XhrReceivingTransportHandler xhrHandler = new XhrReceivingTransportHandler(); DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), xhrHandler); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(8, handlers.size()); assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType())); }
Example #25
Source File: DefaultTransportRequestTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void connect() throws Exception { DefaultTransportRequest request = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); request.connect(null, this.connectFuture); WebSocketSession session = mock(WebSocketSession.class); this.webSocketTransport.getConnectCallback().onSuccess(session); assertSame(session, this.connectFuture.get()); }
Example #26
Source File: SockJsUrlInfo.java From java-technology-stack with MIT License | 5 votes |
private String getScheme(TransportType transportType) { String scheme = this.sockJsUrl.getScheme(); if (TransportType.WEBSOCKET.equals(transportType)) { if (!scheme.startsWith("ws")) { scheme = ("https".equals(scheme) ? "wss" : "ws"); } } else { if (!scheme.startsWith("http")) { scheme = ("wss".equals(scheme) ? "https" : "http"); } } return scheme; }
Example #27
Source File: SockJsUrlInfo.java From java-technology-stack with MIT License | 5 votes |
public URI getTransportUrl(TransportType transportType) { return UriComponentsBuilder.fromUri(this.sockJsUrl) .scheme(getScheme(transportType)) .pathSegment(getServerId()) .pathSegment(getSessionId()) .pathSegment(transportType.toString()) .build(true).toUri(); }
Example #28
Source File: DefaultTransportRequest.java From java-technology-stack with MIT License | 5 votes |
public DefaultTransportRequest(SockJsUrlInfo sockJsUrlInfo, @Nullable HttpHeaders handshakeHeaders, @Nullable HttpHeaders httpRequestHeaders, Transport transport, TransportType serverTransportType, SockJsMessageCodec codec) { Assert.notNull(sockJsUrlInfo, "SockJsUrlInfo is required"); Assert.notNull(transport, "Transport is required"); Assert.notNull(serverTransportType, "TransportType is required"); Assert.notNull(codec, "SockJsMessageCodec is required"); this.sockJsUrlInfo = sockJsUrlInfo; this.handshakeHeaders = (handshakeHeaders != null ? handshakeHeaders : new HttpHeaders()); this.httpRequestHeaders = (httpRequestHeaders != null ? httpRequestHeaders : new HttpHeaders()); this.transport = transport; this.serverTransportType = serverTransportType; this.codec = codec; }
Example #29
Source File: SockJsClient.java From java-technology-stack with MIT License | 5 votes |
private DefaultTransportRequest createRequest( SockJsUrlInfo urlInfo, @Nullable HttpHeaders headers, ServerInfo serverInfo) { List<DefaultTransportRequest> requests = new ArrayList<>(this.transports.size()); for (Transport transport : this.transports) { for (TransportType type : transport.getTransportTypes()) { if (serverInfo.isWebSocketEnabled() || !TransportType.WEBSOCKET.equals(type)) { requests.add(new DefaultTransportRequest(urlInfo, headers, getHttpRequestHeaders(headers), transport, type, getMessageCodec())); } } } if (CollectionUtils.isEmpty(requests)) { throw new IllegalStateException( "No transports: " + urlInfo + ", webSocketEnabled=" + serverInfo.isWebSocketEnabled()); } for (int i = 0; i < requests.size() - 1; i++) { DefaultTransportRequest request = requests.get(i); Principal user = getUser(); if (user != null) { request.setUser(user); } if (this.connectTimeoutScheduler != null) { request.setTimeoutValue(serverInfo.getRetransmissionTimeout()); request.setTimeoutScheduler(this.connectTimeoutScheduler); } request.setFallbackRequest(requests.get(i + 1)); } return requests.get(0); }
Example #30
Source File: XhrClientSockJsSession.java From java-technology-stack with MIT License | 5 votes |
public XhrClientSockJsSession(TransportRequest request, WebSocketHandler handler, XhrTransport transport, SettableListenableFuture<WebSocketSession> connectFuture) { super(request, handler, connectFuture); Assert.notNull(transport, "XhrTransport is required"); this.transport = transport; this.headers = request.getHttpRequestHeaders(); this.sendHeaders = new HttpHeaders(); this.sendHeaders.putAll(this.headers); this.sendHeaders.setContentType(MediaType.APPLICATION_JSON); this.sendUrl = request.getSockJsUrlInfo().getTransportUrl(TransportType.XHR_SEND); }