TomcatSessionManager can't be used in Tomcat if it already has been deployed in Application. #784

pull/787/head
Nikita 8 years ago
parent da960060b0
commit 204a594725

@ -143,11 +143,11 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public void start() throws LifecycleException {
Config config = null;
try {
config = Config.fromJSON(new File(configPath));
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
} catch (IOException e) {
// trying next format
try {
config = Config.fromYAML(new File(configPath));
config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
} catch (IOException e1) {
log.error("Can't parse json config " + configPath, e);
throw new LifecycleException("Can't parse yaml config " + configPath, e1);

@ -146,11 +146,11 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
super.startInternal();
Config config = null;
try {
config = Config.fromJSON(new File(configPath));
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
} catch (IOException e) {
// trying next format
try {
config = Config.fromYAML(new File(configPath));
config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
} catch (IOException e1) {
log.error("Can't parse json config " + configPath, e);
throw new LifecycleException("Can't parse yaml config " + configPath, e1);

@ -146,11 +146,11 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
super.startInternal();
Config config = null;
try {
config = Config.fromJSON(new File(configPath));
config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
} catch (IOException e) {
// trying next format
try {
config = Config.fromYAML(new File(configPath));
config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
} catch (IOException e1) {
log.error("Can't parse json config " + configPath, e);
throw new LifecycleException("Can't parse yaml config " + configPath, e1);

@ -556,12 +556,24 @@ public class Config {
* Read config object stored in JSON format from <code>File</code>
*
* @param file object
* @param classLoader class loader
* @return config
* @throws IOException error
*/
public static Config fromJSON(File file) throws IOException {
public static Config fromJSON(File file, ClassLoader classLoader) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromJSON(file, Config.class);
return support.fromJSON(file, Config.class, classLoader);
}
/**
* Read config object stored in JSON format from <code>File</code>
*
* @param file object
* @return config
* @throws IOException error
*/
public static Config fromJSON(File file) throws IOException {
return fromJSON(file);
}
/**
@ -635,6 +647,11 @@ public class Config {
return support.fromYAML(file, Config.class);
}
public static Config fromYAML(File file, ClassLoader classLoader) throws IOException {
ConfigSupport support = new ConfigSupport();
return support.fromYAML(file, Config.class, classLoader);
}
/**
* Read config object stored in YAML format from <code>URL</code>
*

@ -26,13 +26,16 @@ import java.util.List;
import org.redisson.api.RedissonNodeInitializer;
import org.redisson.client.codec.Codec;
import org.redisson.cluster.ClusterConnectionManager;
import org.redisson.codec.CodecProvider;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ElasticacheConnectionManager;
import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.connection.MasterSlaveConnectionManager;
import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.connection.SentinelConnectionManager;
import org.redisson.connection.SingleConnectionManager;
import org.redisson.connection.balancer.LoadBalancer;
import org.redisson.liveobject.provider.ResolverProvider;
import org.redisson.misc.URLBuilder;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore;
@ -45,10 +48,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.redisson.codec.CodecProvider;
import org.redisson.liveobject.provider.ResolverProvider;
import org.redisson.misc.URLBuilder;
/**
*
@ -118,8 +119,8 @@ public class ConfigSupport {
}
private final ObjectMapper jsonMapper = createMapper(null);
private final ObjectMapper yamlMapper = createMapper(new YAMLFactory());
private ObjectMapper jsonMapper = createMapper(null, null);
private ObjectMapper yamlMapper = createMapper(new YAMLFactory(), null);
public <T> T fromJSON(String content, Class<T> configType) throws IOException {
URLBuilder.replaceURLFactory();
@ -131,8 +132,13 @@ public class ConfigSupport {
}
public <T> T fromJSON(File file, Class<T> configType) throws IOException {
return fromJSON(file, configType, null);
}
public <T> T fromJSON(File file, Class<T> configType, ClassLoader classLoader) throws IOException {
URLBuilder.replaceURLFactory();
try {
jsonMapper = createMapper(null, classLoader);
return jsonMapper.readValue(file, configType);
} finally {
URLBuilder.restoreURLFactory();
@ -193,6 +199,17 @@ public class ConfigSupport {
}
}
public <T> T fromYAML(File file, Class<T> configType, ClassLoader classLoader) throws IOException {
URLBuilder.replaceURLFactory();
try {
yamlMapper = createMapper(new YAMLFactory(), classLoader);
return yamlMapper.readValue(file, configType);
} finally {
URLBuilder.restoreURLFactory();
}
}
public <T> T fromYAML(URL url, Class<T> configType) throws IOException {
URLBuilder.replaceURLFactory();
try {
@ -271,7 +288,7 @@ public class ConfigSupport {
}
}
private ObjectMapper createMapper(JsonFactory mapping) {
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
@ -285,6 +302,13 @@ public class ConfigSupport {
.addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance()
.withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper;
}

Loading…
Cancel
Save