From 054c2b0e976546a3954a54b715ef80150161af08 Mon Sep 17 00:00:00 2001 From: mattcorey Date: Wed, 1 Mar 2017 16:15:34 -0500 Subject: [PATCH] Revert "Profile support" --- README.md | 5 +- .../servlet/AwsProxyServletContext.java | 7 -- .../LambdaSpringApplicationInitializer.java | 6 -- .../spring/SpringLambdaContainerHandler.java | 6 +- .../spring/echoapp/EchoSpringAppConfig.java | 4 +- .../spring/echoapp/ProfileOverrideConfig.java | 14 ---- .../profile/DefaultProfileConfiguration.java | 12 ---- .../profile/DefaultProfileResource.java | 32 --------- .../profile/OverrideProfileConfiguration.java | 14 ---- .../spring/profile/SpringProfileTest.java | 72 ------------------- .../resources/application-override.properties | 1 - .../src/test/resources/application.properties | 2 - 12 files changed, 7 insertions(+), 168 deletions(-) delete mode 100644 aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/ProfileOverrideConfig.java delete mode 100644 aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileConfiguration.java delete mode 100644 aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileResource.java delete mode 100644 aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/OverrideProfileConfiguration.java delete mode 100644 aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/profile/SpringProfileTest.java delete mode 100644 aws-serverless-java-container-spring/src/test/resources/application-override.properties delete mode 100644 aws-serverless-java-container-spring/src/test/resources/application.properties diff --git a/README.md b/README.md index 99b808a48..b35b31f96 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ public class LambdaHandler implements RequestHandler contextListeners; - private String lambdaStage; // Dynamically instantiated properties private ServletConfig dispatcherConfig; @@ -85,13 +84,8 @@ public void dispatch(HttpServletRequest request, HttpServletResponse response) dispatcherServlet.service(request, response); } - public void setLambdaStage(String lambdaStage) { - this.lambdaStage = lambdaStage; - } - @Override public void onStartup(ServletContext servletContext) throws ServletException { - applicationContext.getEnvironment().setActiveProfiles(lambdaStage); applicationContext.setServletContext(servletContext); dispatcherConfig = new DefaultDispatcherConfig(servletContext); diff --git a/aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/SpringLambdaContainerHandler.java b/aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/SpringLambdaContainerHandler.java index 1ca7b730c..ed3a1ba6e 100644 --- a/aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/SpringLambdaContainerHandler.java +++ b/aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/SpringLambdaContainerHandler.java @@ -16,7 +16,10 @@ import com.amazonaws.serverless.proxy.internal.*; import com.amazonaws.serverless.proxy.internal.model.AwsProxyRequest; import com.amazonaws.serverless.proxy.internal.model.AwsProxyResponse; -import com.amazonaws.serverless.proxy.internal.servlet.*; +import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletResponse; +import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest; +import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader; +import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletResponseWriter; import com.amazonaws.services.lambda.runtime.Context; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -109,7 +112,6 @@ protected void handleRequest(AwsProxyHttpServletRequest containerRequest, AwsHtt // wire up the application context on the first invocation if (!initialized) { - initializer.setLambdaStage(((AwsProxyServletContext) containerRequest.getServletContext()).getStage()); ServletContext context = containerRequest.getServletContext(); initializer.onStartup(context); initialized = true; diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/EchoSpringAppConfig.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/EchoSpringAppConfig.java index 5769096fd..53ace4766 100644 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/EchoSpringAppConfig.java +++ b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/EchoSpringAppConfig.java @@ -2,18 +2,18 @@ import com.amazonaws.serverless.exceptions.ContainerInitializationException; import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; +import com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer; import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; +import com.amazonaws.services.lambda.runtime.Context; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.web.context.ConfigurableWebApplicationContext; @Configuration @ComponentScan("com.amazonaws.serverless.proxy.spring.echoapp") -@PropertySource("classpath:application.properties") public class EchoSpringAppConfig { @Autowired diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/ProfileOverrideConfig.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/ProfileOverrideConfig.java deleted file mode 100644 index 464044490..000000000 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/ProfileOverrideConfig.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.amazonaws.serverless.proxy.spring.echoapp; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.context.annotation.PropertySource; - -/** - * Created by matthewcorey on 2/20/17. - */ -@Configuration -@Profile("override") -@PropertySource("classpath:/application-override.properties") -public class ProfileOverrideConfig { -} diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileConfiguration.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileConfiguration.java deleted file mode 100644 index 51bb480e1..000000000 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.amazonaws.serverless.proxy.spring.echoapp.profile; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class DefaultProfileConfiguration { - @Bean - public String beanInjectedValue() { - return "default-profile-from-bean"; - } -} diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileResource.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileResource.java deleted file mode 100644 index 5192de2aa..000000000 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/DefaultProfileResource.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.amazonaws.serverless.proxy.spring.echoapp.profile; - -import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/profile") -public class DefaultProfileResource { - @Value("${spring-proxy.profile-test}") - private String profileTest; - - @Value("${spring-proxy.not-overridden-test}") - private String noOverride; - - @Autowired - private String beanInjectedValue; - - @RequestMapping(path = "/spring-properties", method = RequestMethod.GET) - public MapResponseModel loadProperties() { - MapResponseModel model = new MapResponseModel(); - - model.addValue("profileTest", profileTest); - model.addValue("noOverride", noOverride); - model.addValue("beanInjectedValue", beanInjectedValue); - return model; - } -} - diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/OverrideProfileConfiguration.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/OverrideProfileConfiguration.java deleted file mode 100644 index eacc36293..000000000 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/profile/OverrideProfileConfiguration.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.amazonaws.serverless.proxy.spring.echoapp.profile; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; - -@Configuration -@Profile("override") -public class OverrideProfileConfiguration { - @Bean - public String beanInjectedValue() { - return "override-profile-from-bean"; - } -} diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/profile/SpringProfileTest.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/profile/SpringProfileTest.java deleted file mode 100644 index 4eb78988e..000000000 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/profile/SpringProfileTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.amazonaws.serverless.proxy.spring.profile; - -import com.amazonaws.serverless.proxy.internal.model.AwsProxyRequest; -import com.amazonaws.serverless.proxy.internal.model.AwsProxyResponse; -import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyServletContext; -import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder; -import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; -import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; -import com.amazonaws.serverless.proxy.spring.echoapp.EchoSpringAppConfig; -import com.amazonaws.serverless.proxy.spring.echoapp.model.MapResponseModel; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = EchoSpringAppConfig.class) -@WebAppConfiguration -@TestExecutionListeners(inheritListeners = false, listeners = {DependencyInjectionTestExecutionListener.class}) -public class SpringProfileTest { - @Autowired - private ObjectMapper objectMapper; - - @Autowired - private MockLambdaContext lambdaContext; - - @Before - public void clearServletContextCache() { - AwsProxyServletContext.clearServletContextCache(); - } - - @Test - public void profile_defaultProfile() throws Exception { - AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") - .build(); - - SpringLambdaContainerHandler handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class); - AwsProxyResponse output = handler.proxy(request, lambdaContext); - assertEquals(200, output.getStatusCode()); - - MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); - assertEquals(3, response.getValues().size()); - assertEquals("default-profile", response.getValues().get("profileTest")); - assertEquals("not-overridden", response.getValues().get("noOverride")); - assertEquals("default-profile-from-bean", response.getValues().get("beanInjectedValue")); - } - - @Test - public void profile_overrideProfile() throws Exception { - AwsProxyRequest request = new AwsProxyRequestBuilder("/profile/spring-properties", "GET") - .stage("override") - .build(); - - SpringLambdaContainerHandler handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class); - AwsProxyResponse output = handler.proxy(request, lambdaContext); - assertEquals(200, output.getStatusCode()); - - MapResponseModel response = objectMapper.readValue(output.getBody(), MapResponseModel.class); - assertEquals(3, response.getValues().size()); - assertEquals("override-profile", response.getValues().get("profileTest")); - assertEquals("not-overridden", response.getValues().get("noOverride")); - assertEquals("override-profile-from-bean", response.getValues().get("beanInjectedValue")); - } -} diff --git a/aws-serverless-java-container-spring/src/test/resources/application-override.properties b/aws-serverless-java-container-spring/src/test/resources/application-override.properties deleted file mode 100644 index c8769c382..000000000 --- a/aws-serverless-java-container-spring/src/test/resources/application-override.properties +++ /dev/null @@ -1 +0,0 @@ -spring-proxy.profile-test=override-profile \ No newline at end of file diff --git a/aws-serverless-java-container-spring/src/test/resources/application.properties b/aws-serverless-java-container-spring/src/test/resources/application.properties deleted file mode 100644 index 6c12ec0c8..000000000 --- a/aws-serverless-java-container-spring/src/test/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring-proxy.profile-test=default-profile -spring-proxy.not-overridden-test=not-overridden \ No newline at end of file