Commit 8b306df1 by Dave Syer

Use @PropertySource instead of @Bean for http encoder properties

Protects us against changes in Spring Boot 1.4 where the naming convention changes.
parent 8a4fb82b
......@@ -42,26 +42,26 @@ public class CloudJacksonJson extends LegacyJacksonJson {
@Override
public <T> String encode(T object) throws IOException {
return codec.writeToString(object);
return this.codec.writeToString(object);
}
@Override
public <T> void encode(T object, OutputStream outputStream) throws IOException {
codec.writeTo(object, outputStream);
this.codec.writeTo(object, outputStream);
}
@Override
public <T> T decode(String textValue, Class<T> type) throws IOException {
return codec.readValue(type, textValue);
return this.codec.readValue(type, textValue);
}
@Override
public <T> T decode(InputStream inputStream, Class<T> type) throws IOException {
return codec.readValue(type, inputStream);
return this.codec.readValue(type, inputStream);
}
static class CloudJacksonCodec extends EurekaJacksonCodec {
private static final Version VERSION = new Version(1, 1, 0, null);
private static final Version VERSION = new Version(1, 1, 0, null, null, null);
@SuppressWarnings("deprecation")
public CloudJacksonCodec() {
......@@ -74,26 +74,37 @@ public class CloudJacksonJson extends LegacyJacksonJson {
module.addSerializer(DataCenterInfo.class, new DataCenterInfoSerializer());
module.addSerializer(InstanceInfo.class, new CloudInstanceInfoSerializer());
module.addSerializer(Application.class, new ApplicationSerializer());
module.addSerializer(Applications.class, new ApplicationsSerializer(this.getVersionDeltaKey(), this.getAppHashCodeKey()));
module.addSerializer(Applications.class, new ApplicationsSerializer(
this.getVersionDeltaKey(), this.getAppHashCodeKey()));
module.addDeserializer(DataCenterInfo.class, new DataCenterInfoDeserializer());
module.addDeserializer(DataCenterInfo.class,
new DataCenterInfoDeserializer());
module.addDeserializer(LeaseInfo.class, new LeaseInfoDeserializer());
module.addDeserializer(InstanceInfo.class, new CloudInstanceInfoDeserializer(mapper));
module.addDeserializer(Application.class, new ApplicationDeserializer(mapper));
module.addDeserializer(Applications.class, new ApplicationsDeserializer(mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));
module.addDeserializer(InstanceInfo.class,
new CloudInstanceInfoDeserializer(mapper));
module.addDeserializer(Application.class,
new ApplicationDeserializer(mapper));
module.addDeserializer(Applications.class, new ApplicationsDeserializer(
mapper, this.getVersionDeltaKey(), this.getAppHashCodeKey()));
mapper.registerModule(module);
HashMap<Class<?>, ObjectReader> readers = new HashMap<>();
readers.put(InstanceInfo.class, mapper.reader().withType(InstanceInfo.class).withRootName("instance"));
readers.put(Application.class, mapper.reader().withType(Application.class).withRootName("application"));
readers.put(Applications.class, mapper.reader().withType(Applications.class).withRootName("applications"));
readers.put(InstanceInfo.class, mapper.reader().withType(InstanceInfo.class)
.withRootName("instance"));
readers.put(Application.class, mapper.reader().withType(Application.class)
.withRootName("application"));
readers.put(Applications.class, mapper.reader().withType(Applications.class)
.withRootName("applications"));
setField("objectReaderByClass", readers);
HashMap<Class<?>, ObjectWriter> writers = new HashMap<>();
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class).withRootName("instance"));
writers.put(Application.class, mapper.writer().withType(Application.class).withRootName("application"));
writers.put(Applications.class, mapper.writer().withType(Applications.class).withRootName("applications"));
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class)
.withRootName("instance"));
writers.put(Application.class, mapper.writer().withType(Application.class)
.withRootName("application"));
writers.put(Applications.class, mapper.writer().withType(Applications.class)
.withRootName("applications"));
setField("objectWriterByClass", writers);
setField("mapper", mapper);
......@@ -108,7 +119,8 @@ public class CloudJacksonJson extends LegacyJacksonJson {
static class CloudInstanceInfoSerializer extends InstanceInfoSerializer {
@Override
public void serialize(InstanceInfo info, JsonGenerator jgen, SerializerProvider provider) throws IOException {
public void serialize(InstanceInfo info, JsonGenerator jgen,
SerializerProvider provider) throws IOException {
if (info.getInstanceId() == null && info.getMetadata() != null) {
String instanceId = info.getMetadata().get("instanceId");
......
......@@ -32,7 +32,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.HttpEncodingProperties;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.actuator.HasFeatures;
......@@ -42,6 +41,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
......@@ -71,6 +71,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
@Import(EurekaServerInitializerConfiguration.class)
@EnableDiscoveryClient
@EnableConfigurationProperties(EurekaDashboardProperties.class)
@PropertySource("classpath:/eureka/server.properties")
public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
/**
* List of packages containing Jersey resources required by the Eureka server
......@@ -121,14 +122,6 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
}
}
// TODO: is there a better way?
@Bean(name = "spring.http.encoding.CONFIGURATION_PROPERTIES")
public HttpEncodingProperties httpEncodingProperties() {
HttpEncodingProperties properties = new HttpEncodingProperties();
properties.setForce(false);
return properties;
}
@Bean
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
public EurekaController eurekaController() {
......@@ -148,7 +141,8 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
private static CodecWrapper getFullXml(EurekaServerConfig serverConfig) {
CodecWrapper codec = CodecWrappers.getCodec(serverConfig.getXmlCodecName());
return codec == null ? CodecWrappers.getCodec(CodecWrappers.XStreamXml.class) : codec;
return codec == null ? CodecWrappers.getCodec(CodecWrappers.XStreamXml.class)
: codec;
}
class CloudServerCodecs extends DefaultServerCodecs {
......
spring.http.encoding.force=false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment