Fix for NoSuchMethodError: tomcat.request.session.redis.SessionManager.getContext()
parent
c8f8aba55c
commit
e35c8fdbf3
|
@ -130,4 +130,10 @@ public class Session extends StandardSession {
|
|||
super.readObjectData(in);
|
||||
this.setCreationTime(in.readLong());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
}
|
||||
}
|
|
@ -8,38 +8,38 @@ package tomcat.request.session.data.cache.impl;
|
|||
* @author Ranjith Manickam
|
||||
* @since 2.0
|
||||
*/
|
||||
public class RedisConstants {
|
||||
interface RedisConstants {
|
||||
|
||||
// redis properties file name
|
||||
public static final String PROPERTIES_FILE = "redis-data-cache.properties";
|
||||
final String PROPERTIES_FILE = "redis-data-cache.properties";
|
||||
|
||||
// redis properties
|
||||
public static final String HOSTS = "redis.hosts";
|
||||
public static final String CLUSTER_ENABLED = "redis.cluster.enabled";
|
||||
final String HOSTS = "redis.hosts";
|
||||
final String CLUSTER_ENABLED = "redis.cluster.enabled";
|
||||
|
||||
public static final String MAX_ACTIVE = "redis.max.active";
|
||||
public static final String TEST_ONBORROW = "redis.test.onBorrow";
|
||||
public static final String TEST_ONRETURN = "redis.test.onReturn";
|
||||
public static final String MAX_IDLE = "redis.max.idle";
|
||||
public static final String MIN_IDLE = "redis.min.idle";
|
||||
public static final String TEST_WHILEIDLE = "redis.test.whileIdle";
|
||||
public static final String TEST_NUMPEREVICTION = "redis.test.numPerEviction";
|
||||
public static final String TIME_BETWEENEVICTION = "redis.time.betweenEviction";
|
||||
final String MAX_ACTIVE = "redis.max.active";
|
||||
final String TEST_ONBORROW = "redis.test.onBorrow";
|
||||
final String TEST_ONRETURN = "redis.test.onReturn";
|
||||
final String MAX_IDLE = "redis.max.idle";
|
||||
final String MIN_IDLE = "redis.min.idle";
|
||||
final String TEST_WHILEIDLE = "redis.test.whileIdle";
|
||||
final String TEST_NUMPEREVICTION = "redis.test.numPerEviction";
|
||||
final String TIME_BETWEENEVICTION = "redis.time.betweenEviction";
|
||||
|
||||
public static final String PASSWORD = "redis.password";
|
||||
public static final String DATABASE = "redis.database";
|
||||
public static final String TIMEOUT = "redis.timeout";
|
||||
final String PASSWORD = "redis.password";
|
||||
final String DATABASE = "redis.database";
|
||||
final String TIMEOUT = "redis.timeout";
|
||||
|
||||
// redis property default values
|
||||
public static final String DEFAULT_MAX_ACTIVE_VALUE = "10";
|
||||
public static final String DEFAULT_TEST_ONBORROW_VALUE = "true";
|
||||
public static final String DEFAULT_TEST_ONRETURN_VALUE = "true";
|
||||
public static final String DEFAULT_MAX_IDLE_VALUE = "5";
|
||||
public static final String DEFAULT_MIN_IDLE_VALUE = "1";
|
||||
public static final String DEFAULT_TEST_WHILEIDLE_VALUE = "true";
|
||||
public static final String DEFAULT_TEST_NUMPEREVICTION_VALUE = "10";
|
||||
public static final String DEFAULT_TIME_BETWEENEVICTION_VALUE = "60000";
|
||||
public static final String DEFAULT_CLUSTER_ENABLED = "false";
|
||||
final String DEFAULT_MAX_ACTIVE_VALUE = "10";
|
||||
final String DEFAULT_TEST_ONBORROW_VALUE = "true";
|
||||
final String DEFAULT_TEST_ONRETURN_VALUE = "true";
|
||||
final String DEFAULT_MAX_IDLE_VALUE = "5";
|
||||
final String DEFAULT_MIN_IDLE_VALUE = "1";
|
||||
final String DEFAULT_TEST_WHILEIDLE_VALUE = "true";
|
||||
final String DEFAULT_TEST_NUMPEREVICTION_VALUE = "10";
|
||||
final String DEFAULT_TIME_BETWEENEVICTION_VALUE = "60000";
|
||||
final String DEFAULT_CLUSTER_ENABLED = "false";
|
||||
|
||||
public static final String CONN_FAILED_RETRY_MSG = "Jedis connection failed, retrying...";
|
||||
final String CONN_FAILED_RETRY_MSG = "Jedis connection failed, retrying...";
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package tomcat.request.session.redis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.Lifecycle;
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.LifecycleListener;
|
||||
|
@ -126,7 +128,8 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
|||
super.setState(LifecycleState.STARTING);
|
||||
|
||||
boolean initializedValve = false;
|
||||
for (Valve valve : getContext().getPipeline().getValves()) {
|
||||
Context context = getContextIns();
|
||||
for (Valve valve : context.getPipeline().getValves()) {
|
||||
if (valve instanceof SessionHandlerValve) {
|
||||
this.handlerValve = (SessionHandlerValve) valve;
|
||||
this.handlerValve.setSessionManager(this);
|
||||
|
@ -141,7 +144,7 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
|||
initialize();
|
||||
|
||||
log.info("The sessions will expire after " + (getSessionTimeout()) + " seconds.");
|
||||
getContext().setDistributable(true);
|
||||
context.setDistributable(true);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -273,9 +276,8 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
|||
this.dataCache = new RedisDataCache();
|
||||
|
||||
this.serializer = new SerializationUtil();
|
||||
ClassLoader loader = (getContext() != null && getContext().getLoader() != null)
|
||||
? getContext().getLoader().getClassLoader()
|
||||
: null;
|
||||
Context context = getContextIns();
|
||||
ClassLoader loader = (context != null && context.getLoader() != null) ? context.getLoader().getClassLoader() : null;
|
||||
this.serializer.setClassLoader(loader);
|
||||
} catch (Exception ex) {
|
||||
log.error("Error occured while initializing the session manager..", ex);
|
||||
|
@ -348,7 +350,7 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
|||
* @return
|
||||
*/
|
||||
private int getSessionTimeout() {
|
||||
int timeout = getContext().getSessionTimeout() * 60;
|
||||
int timeout = getContextIns().getSessionTimeout() * 60;
|
||||
return (timeout < 1800) ? 1800 : timeout;
|
||||
}
|
||||
|
||||
|
@ -386,4 +388,22 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
|||
setValues(sessionId, session);
|
||||
setValues(isPersisted, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private Context getContextIns() {
|
||||
try {
|
||||
Method method = this.getClass().getSuperclass().getDeclaredMethod("getContext");
|
||||
return (Context) method.invoke(this);
|
||||
} catch (Exception ex) {
|
||||
try {
|
||||
Method method = this.getClass().getSuperclass().getDeclaredMethod("getContainer");
|
||||
return (Context) method.invoke(this);
|
||||
} catch (Exception ex2) {
|
||||
log.error("Error in getContext", ex2);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue