@@ -143,12 +143,14 @@ public List<SubProtocolHandler> getProtocolHandlers() {
143
143
public void addProtocolHandler (SubProtocolHandler handler ) {
144
144
List <String > protocols = handler .getSupportedProtocols ();
145
145
if (CollectionUtils .isEmpty (protocols )) {
146
- logger .error ("No sub-protocols for " + handler + "." );
146
+ if (logger .isErrorEnabled ()) {
147
+ logger .error ("No sub-protocols for " + handler );
148
+ }
147
149
return ;
148
150
}
149
- for (String protocol : protocols ) {
151
+ for (String protocol : protocols ) {
150
152
SubProtocolHandler replaced = this .protocolHandlerLookup .put (protocol , handler );
151
- if (( replaced != null ) && ( replaced != handler ) ) {
153
+ if (replaced != null && replaced != handler ) {
152
154
throw new IllegalStateException ("Can't map " + handler +
153
155
" to protocol '" + protocol + "'. Already mapped to " + replaced + "." );
154
156
}
@@ -316,9 +318,12 @@ public void handleMessage(WebSocketSession session, WebSocketMessage<?> message)
316
318
public void handleMessage (Message <?> message ) throws MessagingException {
317
319
String sessionId = resolveSessionId (message );
318
320
if (sessionId == null ) {
319
- logger .error ("Couldn't find sessionId in " + message );
321
+ if (logger .isErrorEnabled ()) {
322
+ logger .error ("Couldn't find session id in " + message );
323
+ }
320
324
return ;
321
325
}
326
+
322
327
WebSocketSessionHolder holder = this .sessions .get (sessionId );
323
328
if (holder == null ) {
324
329
if (logger .isDebugEnabled ()) {
@@ -327,6 +332,7 @@ public void handleMessage(Message<?> message) throws MessagingException {
327
332
}
328
333
return ;
329
334
}
335
+
330
336
WebSocketSession session = holder .getSession ();
331
337
try {
332
338
findProtocolHandler (session ).handleMessageToClient (session , message );
@@ -344,9 +350,11 @@ public void handleMessage(Message<?> message) throws MessagingException {
344
350
logger .debug ("Failure while closing session " + sessionId + "." , secondException );
345
351
}
346
352
}
347
- catch (Exception e ) {
353
+ catch (Exception ex ) {
348
354
// Could be part of normal workflow (e.g. browser tab closed)
349
- logger .debug ("Failed to send message to client in " + session + ": " + message , e );
355
+ if (logger .isDebugEnabled ()) {
356
+ logger .debug ("Failed to send message to client in " + session + ": " + message , ex );
357
+ }
350
358
}
351
359
}
352
360
0 commit comments