Remove UpdateValve from pipeline in RedissonSessionManager stopInternal method - resolves #2046

Execute UpdateValve's store session within application classloader - resolves #2047
pull/2053/head
Zhelyazko Chobantonov 6 years ago
parent 1d22aa65c9
commit 263871f3a5

@ -28,6 +28,7 @@ import org.apache.catalina.Context;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Session;
import org.apache.catalina.SessionEvent;
import org.apache.catalina.SessionListener;
@ -69,6 +70,8 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
private final String nodeId = UUID.randomUUID().toString();
private UpdateValve updateValve;
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
@ -231,7 +234,9 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
if (getContainer().getLoader().getClassLoader() != null) {
applicationClassLoader = getContainer().getLoader().getClassLoader();
} else if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
@ -248,7 +253,12 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
Pipeline pipeline = getEngine().getPipeline();
if (updateValve != null) { // in case startInternal is called without stopInternal cleaning the updateValve
pipeline.removeValve(updateValve);
}
updateValve = new UpdateValve(this);
pipeline.addValve(updateValve);
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
@ -330,6 +340,11 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
@Override
public void stop() throws LifecycleException {
if (updateValve != null) {
getEngine().getPipeline().removeValve(updateValve);
updateValve = null;
}
try {
shutdownRedisson();
} catch (Exception e) {

@ -43,7 +43,14 @@ public class UpdateValve extends ValveBase {
try {
getNext().invoke(request, response);
} finally {
manager.store(request.getSession(false));
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader applicationClassLoader = request.getContext().getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(applicationClassLoader);
manager.store(request.getSession(false));
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
}

@ -27,6 +27,7 @@ import javax.servlet.http.HttpSession;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Session;
import org.apache.catalina.SessionEvent;
import org.apache.catalina.SessionListener;
@ -67,6 +68,8 @@ public class RedissonSessionManager extends ManagerBase {
private final String nodeId = UUID.randomUUID().toString();
private UpdateValve updateValve;
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
@ -211,7 +214,9 @@ public class RedissonSessionManager extends ManagerBase {
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
if (getContainer().getLoader().getClassLoader() != null) {
applicationClassLoader = getContainer().getLoader().getClassLoader();
} else if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
@ -228,7 +233,12 @@ public class RedissonSessionManager extends ManagerBase {
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
Pipeline pipeline = getEngine().getPipeline();
if (updateValve != null) { // in case startInternal is called without stopInternal cleaning the updateValve
pipeline.removeValve(updateValve);
}
updateValve = new UpdateValve(this);
pipeline.addValve(updateValve);
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
@ -314,6 +324,11 @@ public class RedissonSessionManager extends ManagerBase {
setState(LifecycleState.STOPPING);
if (updateValve != null) {
getEngine().getPipeline().removeValve(updateValve);
updateValve = null;
}
try {
shutdownRedisson();
} catch (Exception e) {

@ -43,7 +43,14 @@ public class UpdateValve extends ValveBase {
try {
getNext().invoke(request, response);
} finally {
manager.store(request.getSession(false));
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader applicationClassLoader = request.getContext().getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(applicationClassLoader);
manager.store(request.getSession(false));
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
}

@ -26,6 +26,7 @@ import javax.servlet.http.HttpSession;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Session;
import org.apache.catalina.SessionEvent;
import org.apache.catalina.SessionListener;
@ -66,6 +67,8 @@ public class RedissonSessionManager extends ManagerBase {
private final String nodeId = UUID.randomUUID().toString();
private UpdateValve updateValve;
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
@ -210,7 +213,9 @@ public class RedissonSessionManager extends ManagerBase {
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
if (getContext().getLoader().getClassLoader() != null) {
applicationClassLoader = getContext().getLoader().getClassLoader();
} else if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
@ -227,7 +232,12 @@ public class RedissonSessionManager extends ManagerBase {
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
Pipeline pipeline = getEngine().getPipeline();
if (updateValve != null) { // in case startInternal is called without stopInternal cleaning the updateValve
pipeline.removeValve(updateValve);
}
updateValve = new UpdateValve(this);
pipeline.addValve(updateValve);
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
@ -313,6 +323,11 @@ public class RedissonSessionManager extends ManagerBase {
setState(LifecycleState.STOPPING);
if (updateValve != null) {
getEngine().getPipeline().removeValve(updateValve);
updateValve = null;
}
try {
shutdownRedisson();
} catch (Exception e) {

@ -43,7 +43,14 @@ public class UpdateValve extends ValveBase {
try {
getNext().invoke(request, response);
} finally {
manager.store(request.getSession(false));
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader applicationClassLoader = request.getContext().getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(applicationClassLoader);
manager.store(request.getSession(false));
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
}

@ -26,6 +26,7 @@ import javax.servlet.http.HttpSession;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Session;
import org.apache.catalina.SessionEvent;
import org.apache.catalina.SessionListener;
@ -66,6 +67,8 @@ public class RedissonSessionManager extends ManagerBase {
private final String nodeId = UUID.randomUUID().toString();
private UpdateValve updateValve;
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
@ -210,7 +213,9 @@ public class RedissonSessionManager extends ManagerBase {
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
if (getContext().getLoader().getClassLoader() != null) {
applicationClassLoader = getContext().getLoader().getClassLoader();
} else if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
@ -227,7 +232,12 @@ public class RedissonSessionManager extends ManagerBase {
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
Pipeline pipeline = getEngine().getPipeline();
if (updateValve != null) { // in case startInternal is called without stopInternal cleaning the updateValve
pipeline.removeValve(updateValve);
}
updateValve = new UpdateValve(this);
pipeline.addValve(updateValve);
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
@ -313,6 +323,11 @@ public class RedissonSessionManager extends ManagerBase {
setState(LifecycleState.STOPPING);
if (updateValve != null) {
getEngine().getPipeline().removeValve(updateValve);
updateValve = null;
}
try {
shutdownRedisson();
} catch (Exception e) {

@ -43,7 +43,14 @@ public class UpdateValve extends ValveBase {
try {
getNext().invoke(request, response);
} finally {
manager.store(request.getSession(false));
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader applicationClassLoader = request.getContext().getLoader().getClassLoader();
Thread.currentThread().setContextClassLoader(applicationClassLoader);
manager.store(request.getSession(false));
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
}

Loading…
Cancel
Save