From c4122b8f8d77585c04be7c0edf7090340ffc8873 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 28 Oct 2015 12:14:31 +0000 Subject: [PATCH] Work around brittle annotation scanning in Mojarra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FacesListener in Mojarra 2.2.12 (used in Glassfish 4.1.1) is a ServletContainerInitializer that’s annotated to handle types annotated with javax.annotation.Resource. OAuth2RestOperationsConfiguration.SessionScopedConfiguration is one such class. This leads to com.sun.faces.config.DelegatingAnnotationProvider calling getAnnotations on SessionScopedConfiguration.class. This fails with a java.lang.ArrayStoreException due to SessionScopedConfiguration being annotated with @ConditionalOnBean(OAuth2ClientConfiguration) and OAuth2ClientConfiguration not being on the classpath. DelegatingAnnotationProvider currently catches NoClassDefFoundErrors thrown during its annotation processing. It needs to be made more robust so that it also copes with an ArrayStoreException, in a similar way to how org.glassfish.apf.impl.AnnotationProcessorImpl was updated to fix GLASSFISH-21265 [1]. I’ve opened an issue to this effect [2]. In the meantime, we can work around the brittleness in DelegatingAnnotationProvider by restructuring SessionScopedConfiguration. This commit moves the use of @Resource into a nested inner class, ClientContextConfiguration, while leaving the use of @ConditionalOnBean on SessionScopedConfiguration. This means that it is now ClientContextConfiguration that is passed to FacesListener and processed by DelegatingAnnotationProcessor, thereby avoiding exposing it to the @ConditionalOnBean annotation that it does not handle gracefully. A Glassfish-based deployment test has also been added to verify the fix. Closes gh-2079 Closes gh-4321 [1] https://java.net/jira/browse/GLASSFISH-21265 [2] https://java.net/jira/browse/JAVASERVERFACES-4076 --- .../OAuth2RestOperationsConfiguration.java | 25 +++-- spring-boot-deployment-tests/pom.xml | 3 +- .../pom.xml | 101 ++++++++++++++++++ .../main/java/sample/SampleController.java | 30 ++++++ .../SampleGlassfishDeployApplication.java | 25 +++++ .../SampleGlassfishDeployApplicationIT.java | 44 ++++++++ ...leDevToolsApplicationIntegrationTests.java | 26 +++++ 7 files changed, 243 insertions(+), 11 deletions(-) create mode 100644 spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml create mode 100644 spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleController.java create mode 100644 spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleGlassfishDeployApplication.java create mode 100644 spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/test/java/sample/SampleGlassfishDeployApplicationIT.java create mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java index 7c762498d1..a5c316972b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java @@ -114,16 +114,6 @@ public class OAuth2RestOperationsConfiguration { @ConditionalOnWebApplication protected static class SessionScopedConfiguration extends BaseConfiguration { - @Resource - @Qualifier("accessTokenRequest") - protected AccessTokenRequest accessTokenRequest; - - @Bean - @Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES) - public DefaultOAuth2ClientContext oauth2ClientContext() { - return new DefaultOAuth2ClientContext(this.accessTokenRequest); - } - @Bean public FilterRegistrationBean oauth2ClientFilterRegistration( OAuth2ClientContextFilter filter) { @@ -133,6 +123,21 @@ public class OAuth2RestOperationsConfiguration { return registration; } + @Configuration + protected static class ClientContextConfiguration { + + @Resource + @Qualifier("accessTokenRequest") + protected AccessTokenRequest accessTokenRequest; + + @Bean + @Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES) + public DefaultOAuth2ClientContext oauth2ClientContext() { + return new DefaultOAuth2ClientContext(this.accessTokenRequest); + } + + } + } /* diff --git a/spring-boot-deployment-tests/pom.xml b/spring-boot-deployment-tests/pom.xml index 4051933721..750ec818de 100644 --- a/spring-boot-deployment-tests/pom.xml +++ b/spring-boot-deployment-tests/pom.xml @@ -23,8 +23,9 @@ ${java.io.tmpdir}/cargo/installs - spring-boot-deployment-test-tomee + spring-boot-deployment-test-glassfish spring-boot-deployment-test-tomcat + spring-boot-deployment-test-tomee spring-boot-deployment-test-wildfly diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml new file mode 100644 index 0000000000..4097b4a99f --- /dev/null +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-deployment-tests + 1.3.0.BUILD-SNAPSHOT + + spring-boot-deployment-test-glassfish + war + Spring Boot Glassfish Deployment Test + Spring Boot Glassfish Deployment Test + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + 4.1.1 + glassfish4x + http://download.oracle.com/glassfish/${glassfish.version}/release/glassfish-${glassfish.version}.zip + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + javax.servlet + javax.servlet-api + provided + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + reserve-network-port + + reserve-network-port + + process-resources + + + appserver.port + appserver.admin.port + appserver.jms.port + appserver.iiop.port + appserver.https.port + appserver.iiops.port + appserver.iiopmutualauth.port + appserver.jmx.port + appserver.osgishell.port + appserver.debugger.port + + + + + + + org.codehaus.cargo + cargo-maven2-plugin + + + + ${appserver.port} + ${appserver.admin.port} + ${appserver.jmx.port} + ${appserver.https.port} + ${appserver.debugger.port} + ${appserver.jms.port} + ${appserver.iiop.port} + ${appserver.iiopmutualauth.port} + ${appserver.iiops.port} + ${appserver.osgishell.port} + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${appserver.port} + + + + + + diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleController.java b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleController.java new file mode 100644 index 0000000000..cef966424d --- /dev/null +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2015 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. + */ + +package sample; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @RequestMapping("/") + public String hello() { + return "Hello World"; + } + +} diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleGlassfishDeployApplication.java b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleGlassfishDeployApplication.java new file mode 100644 index 0000000000..d73fe8a162 --- /dev/null +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleGlassfishDeployApplication.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2015 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. + */ + +package sample; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleGlassfishDeployApplication extends SpringBootServletInitializer { + +} diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/test/java/sample/SampleGlassfishDeployApplicationIT.java b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/test/java/sample/SampleGlassfishDeployApplicationIT.java new file mode 100644 index 0000000000..ceb681fe08 --- /dev/null +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/test/java/sample/SampleGlassfishDeployApplicationIT.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2015 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. + */ + +package sample; + +import org.junit.Test; + +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; + +/** + * Integration Tests for {@link SampleGlassfishDeployApplication}. + */ +public class SampleGlassfishDeployApplicationIT { + + private int port = Integer.valueOf(System.getProperty("port")); + + @Test + public void testHome() throws Exception { + String url = "http://localhost:" + this.port + "/bootapp/"; + System.out.println(url); + ResponseEntity entity = new TestRestTemplate().getForEntity(url, + String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("Hello World", entity.getBody()); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java new file mode 100644 index 0000000000..41091ebf97 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2015 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. + */ + +package sample.devtools; + +/** + * Integration tests for {@link SampleDevToolsApplication}. + * + * @author Andy Wilkinson + */ +public class SampleDevToolsApplicationIntegrationTests { + +}