From 3267e5aa33ac933e693e03727b49d66c9fff3c16 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 26 Sep 2014 21:42:08 +0200 Subject: [PATCH] Update default SockJS CDN location This commit updates the default location of the SockJS' client library. The previous location is being retired by the project maintainers. The new default location is backed by several CDN providers: * https://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js See sockjs/sockjs-client#198 Issue: SPR-12254 (cherry picked from commit a6e1c53) --- .../annotation/SockJsServiceRegistration.java | 24 +++++++------ .../sockjs/support/AbstractSockJsService.java | 2 +- .../sockjs/support/SockJsServiceTests.java | 35 ++++++------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java index 28a29d8c6b..25add8db1d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,16 +73,20 @@ public class SockJsServiceRegistration { } /** - * Transports which don't support cross-domain communication natively (e.g. - * "eventsource", "htmlfile") rely on serving a simple page (using the - * "foreign" domain) from an invisible iframe. Code run from this iframe - * doesn't need to worry about cross-domain issues since it is running from - * a domain local to the SockJS server. The iframe does need to load the - * SockJS javascript client library and this option allows configuring its url. - * See the reference documentation for more details on this. - * + * Transports with no native cross-domain communication (e.g. "eventsource", + * "htmlfile") must get a simple page from the "foreign" domain in an invisible + * iframe so that code in the iframe can run from a domain local to the SockJS + * server. Since the iframe needs to load the SockJS javascript client library, + * this property allows specifying where to load it from. *

By default this is set to point to - * "https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.4.min.js". + * "https://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js". However it can + * also be set to point to a URL served by the application. + *

Note that it's possible to specify a relative URL in which case the URL + * must be relative to the iframe URL. For example assuming a SockJS endpoint + * mapped to "/sockjs", and resulting iframe URL "/sockjs/iframe.html", then the + * the relative URL must start with "../../" to traverse up to the location + * above the SockJS mapping. In case of a prefix-based Servlet mapping one more + * traversal may be needed. */ public SockJsServiceRegistration setClientLibraryUrl(String clientLibraryUrl) { this.clientLibraryUrl = clientLibraryUrl; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java index fd7e48c588..6ebfd52043 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java @@ -68,7 +68,7 @@ public abstract class AbstractSockJsService implements SockJsService { private String name = "SockJSService@" + ObjectUtils.getIdentityHexString(this); - private String clientLibraryUrl = "https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.4.min.js"; + private String clientLibraryUrl = "https://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"; private int streamBytesLimit = 128 * 1024; diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java index 36c8d64e2d..10cd2b92a6 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java @@ -17,9 +17,12 @@ package org.springframework.web.socket.sockjs.support; import java.io.IOException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; import org.junit.Before; import org.junit.Test; + import org.springframework.http.HttpStatus; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; @@ -33,9 +36,6 @@ import org.springframework.web.socket.sockjs.SockJsException; import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; - /** * Test fixture for {@link AbstractSockJsService}. * @@ -55,9 +55,9 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { this.service = new TestSockJsService(new ThreadPoolTaskScheduler()); } + @Test public void validateRequest() throws Exception { - this.service.setWebSocketEnabled(false); resetResponseAndHandleRequest("GET", "/echo/server/session/websocket", HttpStatus.NOT_FOUND); @@ -76,7 +76,6 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { @Test public void handleInfoGet() throws Exception { - resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK); assertEquals("application/json;charset=UTF-8", this.servletResponse.getContentType()); @@ -98,9 +97,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { body.substring(body.indexOf(','))); } - // SPR-11443 - - @Test + @Test // SPR-11443 public void handleInfoGetCorsFilter() throws Exception { // Simulate scenario where Filter would have already set CORS headers @@ -111,9 +108,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { assertEquals("foobar:123", this.servletResponse.getHeader("Access-Control-Allow-Origin")); } - // SPR-11919 - - @Test + @Test // SPR-11919 public void handleInfoGetWildflyNPE() throws Exception { HttpServletResponse mockResponse = mock(HttpServletResponse.class); ServletOutputStream ous = mock(ServletOutputStream.class); @@ -128,9 +123,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { @Test public void handleInfoOptions() throws Exception { - this.servletRequest.addHeader("Access-Control-Request-Headers", "Last-Modified"); - resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT); this.response.flush(); @@ -143,27 +136,23 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { @Test public void handleIframeRequest() throws Exception { - resetResponseAndHandleRequest("GET", "/echo/iframe.html", HttpStatus.OK); assertEquals("text/html;charset=UTF-8", this.servletResponse.getContentType()); assertTrue(this.servletResponse.getContentAsString().startsWith("\n")); - assertEquals(496, this.servletResponse.getContentLength()); + assertEquals(490, this.servletResponse.getContentLength()); assertEquals("public, max-age=31536000", this.response.getHeaders().getCacheControl()); - assertEquals("\"0da1ed070012f304e47b83c81c48ad620\"", this.response.getHeaders().getETag()); + assertEquals("\"06b486b3208b085d9e3220f456a6caca4\"", this.response.getHeaders().getETag()); } @Test public void handleIframeRequestNotModified() throws Exception { - - this.servletRequest.addHeader("If-None-Match", "\"0da1ed070012f304e47b83c81c48ad620\""); - + this.servletRequest.addHeader("If-None-Match", "\"06b486b3208b085d9e3220f456a6caca4\""); resetResponseAndHandleRequest("GET", "/echo/iframe.html", HttpStatus.NOT_MODIFIED); } @Test public void handleRawWebSocketRequest() throws Exception { - resetResponseAndHandleRequest("GET", "/echo", HttpStatus.OK); assertEquals("Welcome to SockJS!\n", this.servletResponse.getContentAsString()); @@ -174,13 +163,13 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { @Test public void handleEmptyContentType() throws Exception { - - servletRequest.setContentType(""); + this.servletRequest.setContentType(""); resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK); assertEquals("Invalid/empty content should have been ignored", 200, this.servletResponse.getStatus()); } + private void resetResponseAndHandleRequest(String httpMethod, String uri, HttpStatus httpStatus) throws IOException { resetResponse(); handleRequest(httpMethod, uri, httpStatus); @@ -211,14 +200,12 @@ public class SockJsServiceTests extends AbstractHttpRequestTests { @Override protected void handleRawWebSocketRequest(ServerHttpRequest req, ServerHttpResponse res, WebSocketHandler handler) throws IOException { - this.handler = handler; } @Override protected void handleTransportRequest(ServerHttpRequest req, ServerHttpResponse res, WebSocketHandler handler, String sessionId, String transport) throws SockJsException { - this.sessionId = sessionId; this.transport = transport; this.handler = handler;