Polishing (collapsed if checks, consistent downcasts, refined javadoc)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -205,8 +205,9 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
|
||||
this.running = true;
|
||||
for (Transport transport : this.transports) {
|
||||
if (transport instanceof Lifecycle) {
|
||||
if (!((Lifecycle) transport).isRunning()) {
|
||||
((Lifecycle) transport).start();
|
||||
Lifecycle lifecycle = (Lifecycle) transport;
|
||||
if (!lifecycle.isRunning()) {
|
||||
lifecycle.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,8 +220,9 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
|
||||
this.running = false;
|
||||
for (Transport transport : this.transports) {
|
||||
if (transport instanceof Lifecycle) {
|
||||
if (((Lifecycle) transport).isRunning()) {
|
||||
((Lifecycle) transport).stop();
|
||||
Lifecycle lifecycle = (Lifecycle) transport;
|
||||
if (lifecycle.isRunning()) {
|
||||
lifecycle.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -288,12 +289,11 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (session.getPrincipal() != null) {
|
||||
if (!session.getPrincipal().equals(request.getPrincipal())) {
|
||||
logger.debug("The user for the session does not match the user for the request.");
|
||||
response.setStatusCode(HttpStatus.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
Principal principal = session.getPrincipal();
|
||||
if (principal != null && !principal.equals(request.getPrincipal())) {
|
||||
logger.debug("The user for the session does not match the user for the request.");
|
||||
response.setStatusCode(HttpStatus.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
if (!transportHandler.checkSessionType(session)) {
|
||||
logger.debug("Session type does not match the transport type for the request.");
|
||||
@@ -305,17 +305,11 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
|
||||
if (transportType.sendsNoCacheInstruction()) {
|
||||
addNoCacheHeaders(response);
|
||||
}
|
||||
|
||||
if (transportType.supportsCors()) {
|
||||
if (!checkOrigin(request, response)) {
|
||||
return;
|
||||
}
|
||||
if (transportType.supportsCors() && !checkOrigin(request, response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
transportHandler.handleRequest(request, response, handler, session);
|
||||
|
||||
|
||||
chain.applyAfterHandshake(request, response, null);
|
||||
}
|
||||
catch (SockJsException ex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -332,15 +332,13 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
this.readyToSend = false;
|
||||
this.response = null;
|
||||
updateLastActiveTime();
|
||||
if (control != null && !control.isCompleted()) {
|
||||
if (control.isStarted()) {
|
||||
try {
|
||||
control.complete();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// Could be part of normal workflow (e.g. browser tab closed)
|
||||
logger.debug("Failed to complete request: " + ex.getMessage());
|
||||
}
|
||||
if (control != null && !control.isCompleted() && control.isStarted()) {
|
||||
try {
|
||||
control.complete();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// Could be part of normal workflow (e.g. browser tab closed)
|
||||
logger.debug("Failed to complete request: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user