From 468728a2c06a482621e7a9295b2d839cc4fc6b95 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 3 Mar 2014 16:24:02 -0800 Subject: [PATCH] Polish --- .../MetricFilterAutoConfiguration.java | 2 +- .../TraceWebFilterAutoConfiguration.java | 2 +- .../actuate/trace/WebRequestTraceFilter.java | 2 +- .../actuate/web/BasicErrorController.java | 2 +- .../SpringApplicationHierarchyTests.java | 3 +- .../AuthenticationManagerConfiguration.java | 2 +- .../security/SecurityAutoConfiguration.java | 4 +- .../web/WebMvcAutoConfiguration.java | 2 +- spring-boot-dependencies/pom.xml | 24 ++-- .../spring-boot-sample-data-rest/pom.xml | 3 +- .../data/jpa/SampleDataRestApplication.java | 2 +- .../java/sample/data/jpa/domain/City.java | 2 +- .../java/sample/data/jpa/domain/Hotel.java | 2 +- .../data/jpa/service/CityRepository.java | 2 +- .../data/jpa/service/CitySearchCriteria.java | 2 +- .../data/jpa/service/HotelRepository.java | 4 +- .../jpa/SampleDataRestApplicationTests.java | 26 +++- .../CityRepositoryIntegrationTests.java | 3 +- .../secure/SampleSecureApplicationTests.java | 24 ++-- .../pom.xml | 3 +- .../SampleMethodSecurityApplication.java | 22 ++- .../src/main/resources/logback.xml | 2 +- .../SampleMethodSecurityApplicationTests.java | 6 +- spring-boot-starters/README.md | 4 +- spring-boot-starters/pom.xml | 3 +- .../spring-boot-starter-data-rest/pom.xml | 16 +-- .../main/resources/META-INF/spring.provides | 1 + .../spring-boot-starter-parent/pom.xml | 18 ++- .../spring-boot-starter-thymeleaf/pom.xml | 3 +- .../boot/context/embedded/ErrorPage.java | 33 ++--- ...rapperEmbeddedServletContainerFactory.java | 127 +++++++++++------- .../web/SpringBootServletInitializer.java | 4 +- ...rEmbeddedServletContainerFactoryTests.java | 49 ++++--- .../logging/java/JavaLoggerSystemTests.java | 4 +- 34 files changed, 244 insertions(+), 164 deletions(-) create mode 100644 spring-boot-starters/spring-boot-starter-data-rest/src/main/resources/META-INF/spring.provides diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java index aa6b9818191..c9f69542da1 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java index d174162fca3..e875c600ae5 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java index 7ed773ce750..2a46202e797 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/WebRequestTraceFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/BasicErrorController.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/BasicErrorController.java index aee6e96d529..add4a26105b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/BasicErrorController.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/BasicErrorController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/SpringApplicationHierarchyTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/SpringApplicationHierarchyTests.java index 128e24940ca..b9aac8b8c15 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/SpringApplicationHierarchyTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/SpringApplicationHierarchyTests.java @@ -24,8 +24,9 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; /** - * @author Dave Syer + * Test for application hierarchies created using {@link SpringApplicationBuilder}. * + * @author Dave Syer */ public class SpringApplicationHierarchyTests { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java index 2e6a5d45e59..b91e0a5473d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.java @@ -116,4 +116,4 @@ public class AuthenticationManagerConfiguration extends auth.parentAuthenticationManager(parent); } } -} \ No newline at end of file +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java index 446f620ece2..288627d3d39 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java @@ -45,9 +45,11 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @Import({ SpringBootWebSecurityConfiguration.class, AuthenticationManagerConfiguration.class }) public class SecurityAutoConfiguration { + @Bean @ConditionalOnMissingBean public SecurityProperties securityProperties() { return new SecurityProperties(); } -} \ No newline at end of file + +} diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 1cd3391334b..729f2e1a940 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -124,8 +124,8 @@ public class WebMvcAutoConfiguration { // Defined as a nested config to ensure WebMvcConfigurerAdapter it not read when not // on the classpath - @EnableWebMvc @Configuration + @EnableWebMvc public static class WebMvcAutoConfigurationAdapter extends WebMvcConfigurerAdapter { private static Log logger = LogFactory.getLog(WebMvcConfigurerAdapter.class); diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index ca5cc8bcfcc..face2acd005 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -49,8 +49,8 @@ 1.5.0.RELEASE 1.4.0.RELEASE 1.1.1.RELEASE - 2.0.0.RELEASE - 0.9.0.RELEASE + 2.0.0.RELEASE + 0.9.0.RELEASE 1.2.1.RELEASE 1.1.1.RELEASE 3.2.1.RELEASE @@ -494,16 +494,16 @@ spring-data-redis ${spring-data-redis.version} - - org.springframework.hateoas - spring-hateoas - ${spring-hateoas.version} - - - org.springframework.data - spring-data-rest-webmvc - ${spring-data-rest.version} - + + org.springframework.hateoas + spring-hateoas + ${spring-hateoas.version} + + + org.springframework.data + spring-data-rest-webmvc + ${spring-data-rest.version} + org.springframework.integration spring-integration-core diff --git a/spring-boot-samples/spring-boot-sample-data-rest/pom.xml b/spring-boot-samples/spring-boot-sample-data-rest/pom.xml index bfad96617d5..4cbf7f15132 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/pom.xml +++ b/spring-boot-samples/spring-boot-sample-data-rest/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java index 49b0d5dcfc1..2037c2518e7 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/SampleDataRestApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java index 55ebea85823..f1a57deda1c 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/City.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java index bb904a10d7e..920142b0e46 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/domain/Hotel.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java index e6ee6ecf789..281e75977e8 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CityRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java index cd74f536cd9..852e445c379 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/CitySearchCriteria.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java index 91737222d5e..87f76df22ba 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/jpa/service/HotelRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import sample.data.jpa.domain.Hotel; @RepositoryRestResource(collectionResourceRel = "hotels", path = "hotels") interface HotelRepository extends PagingAndSortingRepository { - + Hotel findByCityAndName(City city, String name); } diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java index 567d554a31c..bd3a167215a 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/SampleDataRestApplicationTests.java @@ -1,9 +1,20 @@ -package sample.data.jpa; +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import static org.hamcrest.Matchers.containsString; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +package sample.data.jpa; import org.junit.Before; import org.junit.Test; @@ -17,6 +28,11 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + /** * Integration test to run the application. * diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java index 7a8608fb9a1..09fac2a9992 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package sample.data.jpa.service; import org.junit.Test; diff --git a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java index 78d902eecfa..82264d2c7d2 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java @@ -16,8 +16,6 @@ package sample.secure; -import static org.junit.Assert.assertEquals; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -38,6 +36,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import sample.secure.SampleSecureApplicationTests.TestConfiguration; +import static org.junit.Assert.assertEquals; + /** * Basic integration tests for demo application. * @@ -58,9 +58,9 @@ public class SampleSecureApplicationTests { @Before public void init() { - AuthenticationManager authenticationManager = context - .getBean(AuthenticationManagerBuilder.class).getOrBuild(); - authentication = authenticationManager + AuthenticationManager authenticationManager = this.context.getBean( + AuthenticationManagerBuilder.class).getOrBuild(); + this.authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken("user", "password")); } @@ -71,25 +71,25 @@ public class SampleSecureApplicationTests { @Test(expected = AuthenticationException.class) public void secure() throws Exception { - assertEquals(service.secure(), "Hello Security"); + assertEquals(this.service.secure(), "Hello Security"); } @Test public void authenticated() throws Exception { - SecurityContextHolder.getContext().setAuthentication(authentication); - assertEquals(service.secure(), "Hello Security"); + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertEquals(this.service.secure(), "Hello Security"); } @Test public void preauth() throws Exception { - SecurityContextHolder.getContext().setAuthentication(authentication); - assertEquals(service.authorized(), "Hello World"); + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertEquals(this.service.authorized(), "Hello World"); } @Test(expected = AccessDeniedException.class) public void denied() throws Exception { - SecurityContextHolder.getContext().setAuthentication(authentication); - assertEquals(service.denied(), "Goodbye World"); + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertEquals(this.service.denied(), "Goodbye World"); } @PropertySource("classpath:test.properties") diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml b/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml index 6f8ccce0db7..fd2d2b8d38f 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml +++ b/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/ui/method/SampleMethodSecurityApplication.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/ui/method/SampleMethodSecurityApplication.java index cd61e3eb9d9..f329564b4cb 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/ui/method/SampleMethodSecurityApplication.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/ui/method/SampleMethodSecurityApplication.java @@ -76,26 +76,20 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { // @formatter:off - auth.inMemoryAuthentication() - .withUser("admin").password("admin").roles("ADMIN", "USER") - .and() - .withUser("user").password("user").roles("USER"); + auth.inMemoryAuthentication().withUser("admin").password("admin") + .roles("ADMIN", "USER").and().withUser("user").password("user") + .roles("USER"); // @formatter:on } @Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off - http - .authorizeRequests() - .antMatchers("/login").permitAll() - .anyRequest().fullyAuthenticated() - .and() - .formLogin().loginPage("/login").failureUrl("/login?error") - .and() - .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .and() - .exceptionHandling().accessDeniedPage("/access?error"); + http.authorizeRequests().antMatchers("/login").permitAll().anyRequest() + .fullyAuthenticated().and().formLogin().loginPage("/login") + .failureUrl("/login?error").and().logout() + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).and() + .exceptionHandling().accessDeniedPage("/access?error"); // @formatter:on } diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/logback.xml b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/logback.xml index 6173a50684c..92ea748a3e2 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/logback.xml +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/logback.xml @@ -1,6 +1,6 @@ - + diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java index d9dbf7dd8e8..2ae169ffc1a 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/ui/method/SampleMethodSecurityApplicationTests.java @@ -16,9 +16,6 @@ package sample.ui.method; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.util.Arrays; import java.util.concurrent.Callable; @@ -45,6 +42,9 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.RestTemplate; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Basic integration tests for demo application. * diff --git a/spring-boot-starters/README.md b/spring-boot-starters/README.md index 4e172f276b6..70d823f0b45 100644 --- a/spring-boot-starters/README.md +++ b/spring-boot-starters/README.md @@ -30,12 +30,12 @@ The parent pom adds two main fetaures to your project: * dependency management configuration, so you don't have to specify versions or excludes with your own dependencies, as long as they are part of the Spring Boot stack - + * plugin configuration, so you don't have to configure some common settings in the main Maven plugins used to get a project off the ground (e.g. the [Spring Boot Maven plugin](../spring-boot-tools/spring-boot-maven-plugin/README.md)) - + As an example, if you want to build a simple RESTful web service with embedded Tomcat, you only need one dependency: diff --git a/spring-boot-starters/pom.xml b/spring-boot-starters/pom.xml index 79e3adf0dec..def49d3298b 100644 --- a/spring-boot-starters/pom.xml +++ b/spring-boot-starters/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.springframework.boot diff --git a/spring-boot-starters/spring-boot-starter-data-rest/pom.xml b/spring-boot-starters/spring-boot-starter-data-rest/pom.xml index b28800efaa4..9a9720c1427 100644 --- a/spring-boot-starters/spring-boot-starter-data-rest/pom.xml +++ b/spring-boot-starters/spring-boot-starter-data-rest/pom.xml @@ -18,13 +18,13 @@ spring-boot-starter-web ${project.version} - - org.springframework.hateoas - spring-hateoas - - - org.springframework.data - spring-data-rest-webmvc - + + org.springframework.hateoas + spring-hateoas + + + org.springframework.data + spring-data-rest-webmvc + diff --git a/spring-boot-starters/spring-boot-starter-data-rest/src/main/resources/META-INF/spring.provides b/spring-boot-starters/spring-boot-starter-data-rest/src/main/resources/META-INF/spring.provides new file mode 100644 index 00000000000..1d64b0573c5 --- /dev/null +++ b/spring-boot-starters/spring-boot-starter-data-rest/src/main/resources/META-INF/spring.provides @@ -0,0 +1 @@ +provides: spring-hateoas,spring-data-rest-webmvc diff --git a/spring-boot-starters/spring-boot-starter-parent/pom.xml b/spring-boot-starters/spring-boot-starter-parent/pom.xml index cb95ac16f6a..a22f0070ee7 100644 --- a/spring-boot-starters/spring-boot-starter-parent/pom.xml +++ b/spring-boot-starters/spring-boot-starter-parent/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.springframework.boot @@ -308,17 +309,22 @@ - + META-INF/spring.handlers - + META-INF/spring.factories - + META-INF/spring.schemas - - + + ${start-class} diff --git a/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml b/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml index f16c5f47203..fd00cacc98c 100644 --- a/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml +++ b/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.springframework.boot diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ErrorPage.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ErrorPage.java index 642a811d300..b7dca8f1f1d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ErrorPage.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ErrorPage.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,25 +27,26 @@ import org.springframework.util.ObjectUtils; */ public class ErrorPage { + private final HttpStatus status; + + private final Class exception; + private final String path; - private Class exception = null; - - private HttpStatus status = null; - public ErrorPage(String path) { - super(); + this.status = null; + this.exception = null; this.path = path; } public ErrorPage(HttpStatus status, String path) { - super(); this.status = status; + this.exception = null; this.path = path; } public ErrorPage(Class exception, String path) { - super(); + this.status = null; this.exception = exception; this.path = path; } @@ -61,15 +62,17 @@ public class ErrorPage { } /** - * @return the exception type (or null for a page that matches by status) + * Returns the exception type (or {@code null} for a page that matches by status) + * @return the exception type or {@code null} */ public Class getException() { return this.exception; } /** - * The HTTP status value that this error page matches. - * @return the status + * The HTTP status value that this error page matches (or {@code null} for a page that + * matches by exception). + * @return the status or {@code null} */ public HttpStatus getStatus() { return this.status; @@ -80,7 +83,7 @@ public class ErrorPage { * @return the status value (or 0 for a page that matches any status) */ public int getStatusCode() { - return this.status == null ? 0 : this.status.value(); + return (this.status == null ? 0 : this.status.value()); } /** @@ -88,15 +91,15 @@ public class ErrorPage { * @return the exception type name (or {@code null} if there is none) */ public String getExceptionName() { - return this.exception == null ? null : this.exception.getName(); + return (this.exception == null ? null : this.exception.getName()); } /** * @return is this error page a global one (matches all unmatched status and exception - * types)? + * types) */ public boolean isGlobal() { - return this.status == null && this.exception == null; + return (this.status == null && this.exception == null); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java index dc94846abe9..291b39a1a70 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,18 +51,28 @@ import org.springframework.stereotype.Component; * of that type in the context will be applied to this container). * * @author Dave Syer - * + * @author Phillip Webb */ @Component @Order(Ordered.HIGHEST_PRECEDENCE) public class ErrorWrapperEmbeddedServletContainerFactory extends AbstractEmbeddedServletContainerFactory implements Filter { + // From RequestDispatcher but not referenced to remain compatible with Servlet 2.5 + + private static final String ERROR_EXCEPTION = "javax.servlet.error.exception"; + + private static final String ERROR_EXCEPTION_TYPE = "javax.servlet.error.exception_type"; + + private static final String ERROR_MESSAGE = "javax.servlet.error.message"; + + private static final String ERROR_STATUS_CODE = "javax.servlet.error.status_code"; + private String global; - private Map statuses = new HashMap(); + private final Map statuses = new HashMap(); - private Map, String> exceptions = new HashMap, String>(); + private final Map, String> exceptions = new HashMap, String>(); @Override public void init(FilterConfig filterConfig) throws ServletException { @@ -71,65 +81,90 @@ public class ErrorWrapperEmbeddedServletContainerFactory extends @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - String errorPath; - ErrorWrapperResponse wrapped = new ErrorWrapperResponse( - (HttpServletResponse) response); + if (request instanceof HttpServletRequest + && response instanceof HttpServletResponse) { + doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain); + } + else { + chain.doFilter(request, response); + } + } + + private void doFilter(HttpServletRequest request, HttpServletResponse response, + FilterChain chain) throws IOException, ServletException { + ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response); try { chain.doFilter(request, wrapped); int status = wrapped.getStatus(); if (status >= 400) { - errorPath = this.statuses.containsKey(status) ? this.statuses.get(status) - : this.global; - if (errorPath != null) { - request.setAttribute("javax.servlet.error.status_code", status); - request.setAttribute("javax.servlet.error.message", - wrapped.getMessage()); - ((HttpServletRequest) request).getRequestDispatcher(errorPath) - .forward(request, response); - } - else { - ((HttpServletResponse) response).sendError(status, - wrapped.getMessage()); - } + handleErrorStatus(request, response, status, wrapped.getMessage()); } } - catch (Throwable e) { - Class cls = e.getClass(); - errorPath = this.exceptions.containsKey(cls) ? this.exceptions.get(cls) - : this.global; - if (errorPath != null) { - request.setAttribute("javax.servlet.error.status_code", 500); - request.setAttribute("javax.servlet.error.exception", e); - request.setAttribute("javax.servlet.error.message", e.getMessage()); - wrapped.sendError(500, e.getMessage()); - ((HttpServletRequest) request).getRequestDispatcher(errorPath).forward( - request, response); - } - else { - rethrow(e); - } + catch (Throwable ex) { + handleException(request, response, wrapped, ex); } + } - private void rethrow(Throwable e) throws IOException, ServletException { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; + private void handleErrorStatus(HttpServletRequest request, + HttpServletResponse response, int status, String message) + throws ServletException, IOException { + String errorPath = getErrorPath(this.statuses, status); + if (errorPath == null) { + response.sendError(status, message); + return; } - if (e instanceof Error) { - throw (Error) e; + setErrorAttributes(request, status, message); + request.getRequestDispatcher(errorPath).forward(request, response); + } + + private void handleException(HttpServletRequest request, + HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex) + throws IOException, ServletException { + String errorPath = getErrorPath(this.exceptions, ex.getClass()); + if (errorPath == null) { + rethrow(ex); + return; } - if (e instanceof IOException) { - throw (IOException) e; + setErrorAttributes(request, 500, ex.getMessage()); + request.setAttribute(ERROR_EXCEPTION, ex); + request.setAttribute(ERROR_EXCEPTION_TYPE, ex.getClass().getName()); + wrapped.sendError(500, ex.getMessage()); + request.getRequestDispatcher(errorPath).forward(request, response); + } + + private String getErrorPath(Map map, Object key) { + if (map.containsKey(key)) { + return map.get(key); } - if (e instanceof ServletException) { - throw (ServletException) e; + return this.global; + } + + private void setErrorAttributes(ServletRequest request, int status, String message) { + request.setAttribute(ERROR_STATUS_CODE, status); + request.setAttribute(ERROR_MESSAGE, message); + } + + private void rethrow(Throwable ex) throws IOException, ServletException { + if (ex instanceof RuntimeException) { + throw (RuntimeException) ex; } - throw new IllegalStateException("Unidentified Exception", e); + if (ex instanceof Error) { + throw (Error) ex; + } + if (ex instanceof IOException) { + throw (IOException) ex; + } + if (ex instanceof ServletException) { + throw (ServletException) ex; + } + throw new IllegalStateException(ex); } @Override public EmbeddedServletContainer getEmbeddedServletContainer( ServletContextInitializer... initializers) { + return new EmbeddedServletContainer() { @Override @@ -145,6 +180,7 @@ public class ErrorWrapperEmbeddedServletContainerFactory extends return -1; } }; + } @Override @@ -169,6 +205,7 @@ public class ErrorWrapperEmbeddedServletContainerFactory extends private static class ErrorWrapperResponse extends HttpServletResponseWrapper { private int status; + private String message; public ErrorWrapperResponse(HttpServletResponse response) { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java b/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java index 12fbcd94c6f..fef93f465cc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/SpringBootServletInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit servletContext)); application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); application = configure(application); - // Ensure error pages ar registered + // Ensure error pages are registered application.sources(ErrorWrapperEmbeddedServletContainerFactory.class); return (WebApplicationContext) application.run(); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java index 9be037c5d19..6f74b87e349 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorWrapperEmbeddedServletContainerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.context.web; import java.io.IOException; +import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; @@ -31,24 +32,30 @@ import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; /** + * Tests for {@link ErrorWrapperEmbeddedServletContainerFactory}. + * * @author Dave Syer */ public class ErrorWrapperEmbeddedServletContainerFactoryTests { private ErrorWrapperEmbeddedServletContainerFactory filter = new ErrorWrapperEmbeddedServletContainerFactory(); + private MockHttpServletRequest request = new MockHttpServletRequest(); + private MockHttpServletResponse response = new MockHttpServletResponse(); + private MockFilterChain chain = new MockFilterChain(); @Test public void notAnError() throws Exception { this.filter.doFilter(this.request, this.response, this.chain); - assertEquals(this.request, this.chain.getRequest()); - assertEquals(this.response, - ((HttpServletResponseWrapper) this.chain.getResponse()).getResponse()); + assertThat(this.chain.getRequest(), equalTo((ServletRequest) this.request)); + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse(), + equalTo((ServletResponse) this.response)); } @Test @@ -63,10 +70,12 @@ public class ErrorWrapperEmbeddedServletContainerFactoryTests { } }; this.filter.doFilter(this.request, this.response, this.chain); - assertEquals(400, - ((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()); - assertEquals(400, this.request.getAttribute("javax.servlet.error.status_code")); - assertEquals("BAD", this.request.getAttribute("javax.servlet.error.message")); + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus(), + equalTo(400)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE), + equalTo((Object) 400)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE), + equalTo((Object) "BAD")); } @Test @@ -81,10 +90,12 @@ public class ErrorWrapperEmbeddedServletContainerFactoryTests { } }; this.filter.doFilter(this.request, this.response, this.chain); - assertEquals(400, - ((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()); - assertEquals(400, this.request.getAttribute("javax.servlet.error.status_code")); - assertEquals("BAD", this.request.getAttribute("javax.servlet.error.message")); + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus(), + equalTo(400)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE), + equalTo((Object) 400)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE), + equalTo((Object) "BAD")); } @Test @@ -99,9 +110,13 @@ public class ErrorWrapperEmbeddedServletContainerFactoryTests { } }; this.filter.doFilter(this.request, this.response, this.chain); - assertEquals(500, - ((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()); - assertEquals(500, this.request.getAttribute("javax.servlet.error.status_code")); - assertEquals("BAD", this.request.getAttribute("javax.servlet.error.message")); + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus(), + equalTo(500)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE), + equalTo((Object) 500)); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE), + equalTo((Object) "BAD")); + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE), + equalTo((Object) RuntimeException.class.getName())); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggerSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggerSystemTests.java index 290801cd516..01599a47378 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggerSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggerSystemTests.java @@ -52,7 +52,7 @@ public class JavaLoggerSystemTests { @Before public void init() throws SecurityException, IOException { - defaultLocale = Locale.getDefault(); + this.defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); this.logger = new Jdk14Logger(getClass().getName()); } @@ -62,7 +62,7 @@ public class JavaLoggerSystemTests { System.clearProperty("LOG_FILE"); System.clearProperty("LOG_PATH"); System.clearProperty("PID"); - Locale.setDefault(defaultLocale); + Locale.setDefault(this.defaultLocale); } @Test