Commit 37646517 authored by Phillip Webb's avatar Phillip Webb

Polish

parent d9029ef6
...@@ -115,10 +115,9 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -115,10 +115,9 @@ public class JerseyAutoConfiguration implements ServletContextAware {
private void resolveApplicationPath() { private void resolveApplicationPath() {
if (StringUtils.hasLength(this.jersey.getApplicationPath())) { if (StringUtils.hasLength(this.jersey.getApplicationPath())) {
this.path = parseApplicationPath(this.jersey.getApplicationPath()); this.path = parseApplicationPath(this.jersey.getApplicationPath());
} } else {
else { this.path = findApplicationPath(
this.path = findApplicationPath(AnnotationUtils.findAnnotation( AnnotationUtils.findAnnotation(this.config.getApplication().getClass(), ApplicationPath.class));
this.config.getApplication().getClass(), ApplicationPath.class));
} }
} }
...@@ -149,8 +148,7 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -149,8 +148,7 @@ public class JerseyAutoConfiguration implements ServletContextAware {
registration.setFilter(new ServletContainer(this.config)); registration.setFilter(new ServletContainer(this.config));
registration.setUrlPatterns(Arrays.asList(this.path)); registration.setUrlPatterns(Arrays.asList(this.path));
registration.setOrder(this.jersey.getFilter().getOrder()); registration.setOrder(this.jersey.getFilter().getOrder());
registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
stripPattern(this.path));
addInitParameters(registration); addInitParameters(registration);
registration.setName("jerseyFilter"); registration.setName("jerseyFilter");
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class)); registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
...@@ -168,8 +166,8 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -168,8 +166,8 @@ public class JerseyAutoConfiguration implements ServletContextAware {
@ConditionalOnMissingBean(name = "jerseyServletRegistration") @ConditionalOnMissingBean(name = "jerseyServletRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
public ServletRegistrationBean jerseyServletRegistration() { public ServletRegistrationBean jerseyServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean( ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(this.config),
new ServletContainer(this.config), this.path); this.path);
addInitParameters(registration); addInitParameters(registration);
registration.setName(getServletRegistrationName()); registration.setName(getServletRegistrationName());
registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup()); registration.setLoadOnStartup(this.jersey.getServlet().getLoadOnStartup());
...@@ -204,23 +202,18 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -204,23 +202,18 @@ public class JerseyAutoConfiguration implements ServletContextAware {
@Override @Override
public void setServletContext(ServletContext servletContext) { public void setServletContext(ServletContext servletContext) {
String servletRegistrationName = getServletRegistrationName(); String servletRegistrationName = getServletRegistrationName();
ServletRegistration registration = servletContext ServletRegistration registration = servletContext.getServletRegistration(servletRegistrationName);
.getServletRegistration(servletRegistrationName);
if (registration != null) { if (registration != null) {
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
logger.info("Configuring existing registration for Jersey servlet '" logger.info("Configuring existing registration for Jersey servlet '" + servletRegistrationName + "'");
+ servletRegistrationName + "'");
} }
registration.setInitParameters(this.jersey.getInit()); registration.setInitParameters(this.jersey.getInit());
registration.setInitParameter( registration.setInitParameter(CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE, Boolean.TRUE.toString());
CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE,
Boolean.TRUE.toString());
} }
} }
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
public static final class JerseyWebApplicationInitializer public static final class JerseyWebApplicationInitializer implements WebApplicationInitializer {
implements WebApplicationInitializer {
@Override @Override
public void onStartup(ServletContext servletContext) throws ServletException { public void onStartup(ServletContext servletContext) throws ServletException {
...@@ -239,22 +232,19 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -239,22 +232,19 @@ public class JerseyAutoConfiguration implements ServletContextAware {
private static final String JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME = "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector"; private static final String JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME = "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector";
@Bean @Bean
public ResourceConfigCustomizer resourceConfigCustomizer( public ResourceConfigCustomizer resourceConfigCustomizer(final ObjectMapper objectMapper) {
final ObjectMapper objectMapper) {
addJaxbAnnotationIntrospectorIfPresent(objectMapper); addJaxbAnnotationIntrospectorIfPresent(objectMapper);
return new ResourceConfigCustomizer() { return new ResourceConfigCustomizer() {
@Override @Override
public void customize(ResourceConfig config) { public void customize(ResourceConfig config) {
config.register(JacksonFeature.class); config.register(JacksonFeature.class);
config.register(new ObjectMapperContextResolver(objectMapper), config.register(new ObjectMapperContextResolver(objectMapper), ContextResolver.class);
ContextResolver.class);
} }
}; };
} }
private void addJaxbAnnotationIntrospectorIfPresent(ObjectMapper objectMapper) { private void addJaxbAnnotationIntrospectorIfPresent(ObjectMapper objectMapper) {
if (ClassUtils.isPresent(JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME, if (ClassUtils.isPresent(JAXB_ANNOTATION_INTROSPECTOR_CLASS_NAME, getClass().getClassLoader())) {
getClass().getClassLoader())) {
new ObjectMapperCustomizer().addJaxbAnnotationIntrospector(objectMapper); new ObjectMapperCustomizer().addJaxbAnnotationIntrospector(objectMapper);
} }
} }
...@@ -265,22 +255,18 @@ public class JerseyAutoConfiguration implements ServletContextAware { ...@@ -265,22 +255,18 @@ public class JerseyAutoConfiguration implements ServletContextAware {
JaxbAnnotationIntrospector jaxbAnnotationIntrospector = new JaxbAnnotationIntrospector( JaxbAnnotationIntrospector jaxbAnnotationIntrospector = new JaxbAnnotationIntrospector(
objectMapper.getTypeFactory()); objectMapper.getTypeFactory());
objectMapper.setAnnotationIntrospectors( objectMapper.setAnnotationIntrospectors(
createPair(objectMapper.getSerializationConfig(), createPair(objectMapper.getSerializationConfig(), jaxbAnnotationIntrospector),
jaxbAnnotationIntrospector), createPair(objectMapper.getDeserializationConfig(), jaxbAnnotationIntrospector));
createPair(objectMapper.getDeserializationConfig(),
jaxbAnnotationIntrospector));
} }
private AnnotationIntrospector createPair(MapperConfig<?> config, private AnnotationIntrospector createPair(MapperConfig<?> config,
JaxbAnnotationIntrospector jaxbAnnotationIntrospector) { JaxbAnnotationIntrospector jaxbAnnotationIntrospector) {
return AnnotationIntrospector.pair(config.getAnnotationIntrospector(), return AnnotationIntrospector.pair(config.getAnnotationIntrospector(), jaxbAnnotationIntrospector);
jaxbAnnotationIntrospector);
} }
} }
private static final class ObjectMapperContextResolver private static final class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
......
...@@ -43,7 +43,8 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -43,7 +43,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link JerseyAutoConfiguration} when using a custom {@link Application}. * Tests for {@link JerseyAutoConfiguration} when using a custom
* {@link Application}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
...@@ -52,14 +53,12 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -52,14 +53,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext @DirtiesContext
public class JerseyAutoConfigurationCustomApplicationTests { public class JerseyAutoConfigurationCustomApplicationTests {
@Autowired @Autowired
private TestRestTemplate restTemplate; private TestRestTemplate restTemplate;
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/test/hello", ResponseEntity<String> entity = this.restTemplate.getForEntity("/test/hello", String.class);
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
...@@ -79,9 +78,8 @@ public class JerseyAutoConfigurationCustomApplicationTests { ...@@ -79,9 +78,8 @@ public class JerseyAutoConfigurationCustomApplicationTests {
} }
@Configuration @Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class, @Import({ EmbeddedServletContainerAutoConfiguration.class, ServerPropertiesAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
PropertyPlaceholderAutoConfiguration.class })
static class TestConfiguration { static class TestConfiguration {
@Configuration @Configuration
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -338,7 +338,6 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -338,7 +338,6 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
return hasAnnotation(element, LOMBOK_DATA_ANNOTATION); return hasAnnotation(element, LOMBOK_DATA_ANNOTATION);
} }
private boolean isAccessLevelPublic(AnnotationMirror lombokAnnotation) { private boolean isAccessLevelPublic(AnnotationMirror lombokAnnotation) {
Map<String, Object> values = getAnnotationElementValues(lombokAnnotation); Map<String, Object> values = getAnnotationElementValues(lombokAnnotation);
Object value = values.get("value"); Object value = values.get("value");
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -31,6 +31,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties; ...@@ -31,6 +31,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
*/ */
@Data @Data
@ConfigurationProperties(prefix = "accesslevel.overwrite.data") @ConfigurationProperties(prefix = "accesslevel.overwrite.data")
@SuppressWarnings("unused")
public class LombokAccessLevelOverwriteDataProperties { public class LombokAccessLevelOverwriteDataProperties {
private String name0; private String name0;
......
...@@ -31,6 +31,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties; ...@@ -31,6 +31,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
@Getter(AccessLevel.PUBLIC) @Getter(AccessLevel.PUBLIC)
@Setter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC)
@ConfigurationProperties(prefix = "accesslevel.overwrite.explicit") @ConfigurationProperties(prefix = "accesslevel.overwrite.explicit")
@SuppressWarnings("unused")
public class LombokAccessLevelOverwriteExplicitProperties { public class LombokAccessLevelOverwriteExplicitProperties {
private String name0; private String name0;
......
/* /*
* Copyright 2012-2014 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
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