Skip to content

Commit 723e09c

Browse files
committed
Polishing
See gh-29408
1 parent 5245327 commit 723e09c

File tree

14 files changed

+248
-313
lines changed

14 files changed

+248
-313
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,19 @@ public SockJsServiceRegistration setTaskScheduler(TaskScheduler scheduler) {
9898
/**
9999
* Transports with no native cross-domain communication (e.g. "eventsource",
100100
* "htmlfile") must get a simple page from the "foreign" domain in an invisible
101-
* iframe so that code in the iframe can run from a domain local to the SockJS
102-
* server. Since the iframe needs to load the SockJS javascript client library,
103-
* this property allows specifying where to load it from.
101+
* {@code iframe} so that code in the {@code iframe} can run from a domain
102+
* local to the SockJS server. Since the {@code iframe} needs to load the
103+
* SockJS JavaScript client library, this property allows specifying where to
104+
* load it from.
104105
* <p>By default this is set to point to
105-
* "<a href="https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js">sockjs.min.js</a>". However, it can
106-
* also be set to point to a URL served by the application.
106+
* <a href="https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js">"https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js"</a>.
107+
* However, it can also be set to point to a URL served by the application.
107108
* <p>Note that it's possible to specify a relative URL in which case the URL
108-
* must be relative to the iframe URL. For example assuming a SockJS endpoint
109-
* mapped to "/sockjs", and resulting iframe URL "/sockjs/iframe.html", then
109+
* must be relative to the {@code iframe} URL. For example assuming a SockJS endpoint
110+
* mapped to "/sockjs", and resulting {@code iframe} URL "/sockjs/iframe.html", then
110111
* the relative URL must start with "../../" to traverse up to the location
111112
* above the SockJS mapping. In case of a prefix-based Servlet mapping one more
112-
* traversal may be needed.
113+
* traversals may be needed.
113114
*/
114115
public SockJsServiceRegistration setClientLibraryUrl(String clientLibraryUrl) {
115116
this.clientLibraryUrl = clientLibraryUrl;

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -145,18 +145,19 @@ public String getName() {
145145
/**
146146
* Transports with no native cross-domain communication (e.g. "eventsource",
147147
* "htmlfile") must get a simple page from the "foreign" domain in an invisible
148-
* iframe so that code in the iframe can run from a domain local to the SockJS
149-
* server. Since the iframe needs to load the SockJS javascript client library,
150-
* this property allows specifying where to load it from.
148+
* {@code iframe} so that code in the {@code iframe} can run from a domain
149+
* local to the SockJS server. Since the {@code iframe} needs to load the
150+
* SockJS JavaScript client library, this property allows specifying where to
151+
* load it from.
151152
* <p>By default this is set to point to
152-
* "<a href="https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js">sockjs.min.js</a>".
153+
* <a href="https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js">"https://cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js"</a>.
153154
* However, it can also be set to point to a URL served by the application.
154155
* <p>Note that it's possible to specify a relative URL in which case the URL
155-
* must be relative to the iframe URL. For example assuming a SockJS endpoint
156-
* mapped to "/sockjs", and resulting iframe URL "/sockjs/iframe.html", then
156+
* must be relative to the {@code iframe} URL. For example assuming a SockJS endpoint
157+
* mapped to "/sockjs", and resulting {@code iframe} URL "/sockjs/iframe.html", then
157158
* the relative URL must start with "../../" to traverse up to the location
158159
* above the SockJS mapping. In case of a prefix-based Servlet mapping one more
159-
* traversal may be needed.
160+
* traversals may be needed.
160161
*/
161162
public void setSockJsClientLibraryUrl(String clientLibraryUrl) {
162163
this.clientLibraryUrl = clientLibraryUrl;
@@ -613,24 +614,23 @@ else if (request.getMethod() == HttpMethod.OPTIONS) {
613614

614615
private class IframeHandler implements SockJsRequestHandler {
615616

616-
private static final String IFRAME_CONTENT =
617-
"""
618-
<!DOCTYPE html>
619-
<html>
620-
<head>
621-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
622-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
623-
<script>
624-
document.domain = document.domain;
625-
_sockjs_onload = function(){SockJS.bootstrap_iframe();};
626-
</script>
627-
<script src="%s"></script>
628-
</head>
629-
<body>
630-
<h2>Don't panic!</h2>
631-
<p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>
632-
</body>
633-
</html>""";
617+
private static final String IFRAME_CONTENT = """
618+
<!DOCTYPE html>
619+
<html>
620+
<head>
621+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
622+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
623+
<script>
624+
document.domain = document.domain;
625+
_sockjs_onload = function(){SockJS.bootstrap_iframe();};
626+
</script>
627+
<script src="%s"></script>
628+
</head>
629+
<body>
630+
<h2>Don't panic!</h2>
631+
<p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>
632+
</body>
633+
</html>""";
634634

635635
@Override
636636
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,26 +59,22 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle
5959

6060

6161
static {
62-
StringBuilder sb = new StringBuilder(
63-
"""
64-
<!DOCTYPE html>
65-
<html><head>
66-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
67-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
68-
</head><body><h2>Don't panic!</h2>
69-
<script>
70-
document.domain = document.domain;
71-
var c = parent.%s;
72-
c.start();
73-
function p(d) {c.message(d);};
74-
window.onload = function() {c.stop();};
75-
</script>"""
76-
);
77-
78-
while (sb.length() < MINIMUM_PARTIAL_HTML_CONTENT_LENGTH) {
79-
sb.append(' ');
80-
}
81-
PARTIAL_HTML_CONTENT = sb.toString();
62+
StringBuilder sb = new StringBuilder("""
63+
<!DOCTYPE html>
64+
<html><head>
65+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
67+
</head><body><h2>Don't panic!</h2>
68+
<script>
69+
document.domain = document.domain;
70+
var c = parent.%s;
71+
c.start();
72+
function p(d) {c.message(d);};
73+
window.onload = function() {c.stop();};
74+
</script>""");
75+
76+
sb.append(" ".repeat(MINIMUM_PARTIAL_HTML_CONTENT_LENGTH - sb.length()));
77+
PARTIAL_HTML_CONTENT = sb.append('\n').toString();
8278
}
8379

8480

spring-websocket/src/test/java/org/springframework/web/socket/AbstractHttpRequestTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public abstract class AbstractHttpRequestTests {
4545

4646

4747
@BeforeEach
48-
public void setup() {
48+
protected void setup() {
4949
resetRequestAndResponse();
5050
}
5151

0 commit comments

Comments
 (0)