Skip to content

Commit 11cb938

Browse files
committed
Polishing contribution
Closes gh-28000
1 parent f004bb1 commit 11cb938

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 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.
@@ -79,15 +79,7 @@ else if (sockJsSession.isClosed()) {
7979
if (logger.isDebugEnabled()) {
8080
logger.debug("Connection already closed (but not removed yet) for " + sockJsSession);
8181
}
82-
SockJsFrameFormat frameFormat = this.getFrameFormat(request);
83-
SockJsFrame frame = SockJsFrame.closeFrameGoAway();
84-
String formattedFrame = frameFormat.format(frame);
85-
try {
86-
response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
87-
}
88-
catch (IOException ex) {
89-
throw new SockJsException("Failed to send " + frame, sockJsSession.getId(), ex);
90-
}
82+
writeFrame(SockJsFrame.closeFrameGoAway(), request, response, sockJsSession);
9183
}
9284
else if (!sockJsSession.isActive()) {
9385
if (logger.isTraceEnabled()) {
@@ -99,13 +91,19 @@ else if (!sockJsSession.isActive()) {
9991
if (logger.isDebugEnabled()) {
10092
logger.debug("Another " + getTransportType() + " connection still open for " + sockJsSession);
10193
}
102-
String formattedFrame = getFrameFormat(request).format(SockJsFrame.closeFrameAnotherConnectionOpen());
103-
try {
104-
response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
105-
}
106-
catch (IOException ex) {
107-
throw new SockJsException("Failed to send " + formattedFrame, sockJsSession.getId(), ex);
108-
}
94+
writeFrame(SockJsFrame.closeFrameAnotherConnectionOpen(), request, response, sockJsSession);
95+
}
96+
}
97+
98+
private void writeFrame(SockJsFrame frame, ServerHttpRequest request, ServerHttpResponse response,
99+
AbstractHttpSockJsSession sockJsSession) {
100+
101+
String formattedFrame = getFrameFormat(request).format(frame);
102+
try {
103+
response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET));
104+
}
105+
catch (IOException ex) {
106+
throw new SockJsException("Failed to send " + formattedFrame, sockJsSession.getId(), ex);
109107
}
110108
}
111109

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java

Lines changed: 1 addition & 1 deletion
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.

0 commit comments

Comments
 (0)