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 { public void start() throws LifecycleException {
Config config = null; Config config = null;
try { try {
config = Config.fromJSON(new File(configPath)); config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
} catch (IOException e) { } catch (IOException e) {
// trying next format // trying next format
try { try {
config = Config.fromYAML(new File(configPath)); config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
} catch (IOException e1) { } catch (IOException e1) {
log.error("Can't parse json config " + configPath, e); log.error("Can't parse json config " + configPath, e);
throw new LifecycleException("Can't parse yaml config " + configPath, e1); throw new LifecycleException("Can't parse yaml config " + configPath, e1);

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

@ -146,11 +146,11 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
super.startInternal(); super.startInternal();
Config config = null; Config config = null;
try { try {
config = Config.fromJSON(new File(configPath)); config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
} catch (IOException e) { } catch (IOException e) {
// trying next format // trying next format
try { try {
config = Config.fromYAML(new File(configPath)); config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
} catch (IOException e1) { } catch (IOException e1) {
log.error("Can't parse json config " + configPath, e); log.error("Can't parse json config " + configPath, e);
throw new LifecycleException("Can't parse yaml config " + configPath, e1); 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> * Read config object stored in JSON format from <code>File</code>
* *
* @param file object * @param file object
* @param classLoader class loader
* @return config * @return config
* @throws IOException error * @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(); 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);
} }
/** /**
@ -634,6 +646,11 @@ public class Config {
ConfigSupport support = new ConfigSupport(); ConfigSupport support = new ConfigSupport();
return support.fromYAML(file, Config.class); 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> * 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.api.RedissonNodeInitializer;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.cluster.ClusterConnectionManager; import org.redisson.cluster.ClusterConnectionManager;
import org.redisson.codec.CodecProvider;
import org.redisson.connection.ConnectionManager; import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ElasticacheConnectionManager; import org.redisson.connection.ElasticacheConnectionManager;
import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.connection.MasterSlaveConnectionManager; import org.redisson.connection.MasterSlaveConnectionManager;
import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.connection.SentinelConnectionManager; import org.redisson.connection.SentinelConnectionManager;
import org.redisson.connection.SingleConnectionManager; import org.redisson.connection.SingleConnectionManager;
import org.redisson.connection.balancer.LoadBalancer; 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.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore; 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.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 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 ObjectMapper jsonMapper = createMapper(null, null);
private final ObjectMapper yamlMapper = createMapper(new YAMLFactory()); private ObjectMapper yamlMapper = createMapper(new YAMLFactory(), null);
public <T> T fromJSON(String content, Class<T> configType) throws IOException { public <T> T fromJSON(String content, Class<T> configType) throws IOException {
URLBuilder.replaceURLFactory(); URLBuilder.replaceURLFactory();
@ -131,8 +132,13 @@ public class ConfigSupport {
} }
public <T> T fromJSON(File file, Class<T> configType) throws IOException { 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(); URLBuilder.replaceURLFactory();
try { try {
jsonMapper = createMapper(null, classLoader);
return jsonMapper.readValue(file, configType); return jsonMapper.readValue(file, configType);
} finally { } finally {
URLBuilder.restoreURLFactory(); URLBuilder.restoreURLFactory();
@ -192,6 +198,17 @@ public class ConfigSupport {
URLBuilder.restoreURLFactory(); URLBuilder.restoreURLFactory();
} }
} }
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 { public <T> T fromYAML(URL url, Class<T> configType) throws IOException {
URLBuilder.replaceURLFactory(); URLBuilder.replaceURLFactory();
@ -271,7 +288,7 @@ public class ConfigSupport {
} }
} }
private ObjectMapper createMapper(JsonFactory mapping) { private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping); ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class); mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class); mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
@ -285,6 +302,13 @@ public class ConfigSupport {
.addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept()); .addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider); mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL); mapper.setSerializationInclusion(Include.NON_NULL);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance()
.withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper; return mapper;
} }

Loading…
Cancel
Save