Skip to content

Commit ef2f145

Browse files
committed
Do not require refreshContext variable in constructor of LambdaSpringApplicationInitializer and SpringLambdacontainerHandler. Added setter for refreshContext. Added Spring test dependencies to test scope
1 parent 709ad2d commit ef2f145

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

aws-serverless-java-container-spring/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
<version>${spring.version}</version>
4646
</dependency>
4747

48-
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
48+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
4949
<dependency>
5050
<groupId>org.springframework</groupId>
5151
<artifactId>spring-test</artifactId>
5252
<version>${spring.version}</version>
53+
<scope>test</scope>
5354
</dependency>
5455

5556
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->

aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/LambdaSpringApplicationInitializer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class LambdaSpringApplicationInitializer implements WebApplicationInitial
4545

4646
// Configuration variables that can be passed in
4747
private ConfigurableWebApplicationContext applicationContext;
48-
private boolean refreshContext;
48+
private boolean refreshContext = true;
4949
private List<ServletContextListener> contextListeners;
5050

5151
// Dynamically instantiated properties
@@ -58,12 +58,10 @@ public class LambdaSpringApplicationInitializer implements WebApplicationInitial
5858
/**
5959
* Creates a new instance of the WebApplicationInitializer
6060
* @param applicationContext A custom ConfigurableWebApplicationContext to be used
61-
* @param applicationContext Whether or not to refresh the applicationContext
6261
*/
63-
public LambdaSpringApplicationInitializer(ConfigurableWebApplicationContext applicationContext, boolean refreshContext) {
62+
public LambdaSpringApplicationInitializer(ConfigurableWebApplicationContext applicationContext) {
6463
this.contextListeners = new ArrayList<>();
6564
this.applicationContext = applicationContext;
66-
this.refreshContext = refreshContext;
6765
}
6866

6967
/**
@@ -76,6 +74,10 @@ public void addListener(ServletContextListener listener) {
7674
contextListeners.add(listener);
7775
}
7876

77+
public void setRefreshContext(boolean refreshContext) {
78+
this.refreshContext = refreshContext;
79+
}
80+
7981
public void dispatch(HttpServletRequest request, HttpServletResponse response)
8082
throws ServletException, IOException {
8183
currentResponse = response;

aws-serverless-java-container-spring/src/main/java/com/amazonaws/serverless/proxy/spring/SpringLambdacontainerHandler.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> ge
5555
new AwsProxyHttpServletResponseWriter(),
5656
new AwsProxySecurityContextWriter(),
5757
new AwsProxyExceptionHandler(),
58-
applicationContext,
59-
true
58+
applicationContext
6059
);
6160
}
6261

@@ -66,15 +65,14 @@ public static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> ge
6665
* @return An initialized instance of the `SpringLambdaContainerHandler`
6766
* @throws ContainerInitializationException
6867
*/
69-
public static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> getAwsProxyHandler(ConfigurableWebApplicationContext applicationContext, boolean refresh)
68+
public static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> getAwsProxyHandler(ConfigurableWebApplicationContext applicationContext)
7069
throws ContainerInitializationException {
7170
return new SpringLambdaContainerHandler<>(
7271
new AwsProxyHttpServletRequestReader(),
7372
new AwsProxyHttpServletResponseWriter(),
7473
new AwsProxySecurityContextWriter(),
7574
new AwsProxyExceptionHandler(),
76-
applicationContext,
77-
refresh
75+
applicationContext
7876
);
7977
}
8078

@@ -94,29 +92,11 @@ public SpringLambdaContainerHandler(RequestReader<RequestType, AwsProxyHttpServl
9492
ConfigurableWebApplicationContext applicationContext)
9593
throws ContainerInitializationException {
9694
super(requestReader, responseWriter, securityContextWriter, exceptionHandler);
97-
initializer = new LambdaSpringApplicationInitializer(applicationContext, false);
95+
initializer = new LambdaSpringApplicationInitializer(applicationContext);
9896
}
9997

100-
/**
101-
* Creates a new container handler with the given reader and writer objects
102-
*
103-
* @param requestReader An implementation of `RequestReader`
104-
* @param responseWriter An implementation of `ResponseWriter`
105-
* @param securityContextWriter An implementation of `SecurityContextWriter`
106-
* @param exceptionHandler An implementation of `ExceptionHandler`
107-
* @param applicationContext An implementation of `ConfigurableWebApplicationContext`
108-
* @param refreshContext Whether or not applicationContext needs to be refreshed
109-
* @throws ContainerInitializationException
110-
*/
111-
public SpringLambdaContainerHandler(RequestReader<RequestType, AwsProxyHttpServletRequest> requestReader,
112-
ResponseWriter<AwsHttpServletResponse, ResponseType> responseWriter,
113-
SecurityContextWriter<RequestType> securityContextWriter,
114-
ExceptionHandler<ResponseType> exceptionHandler,
115-
ConfigurableWebApplicationContext applicationContext,
116-
boolean refreshContext)
117-
throws ContainerInitializationException {
118-
super(requestReader, responseWriter, securityContextWriter, exceptionHandler);
119-
initializer = new LambdaSpringApplicationInitializer(applicationContext, refreshContext);
98+
public void setRefreshContext(boolean refreshContext) {
99+
this.initializer.setRefreshContext(refreshContext);
120100
}
121101

122102
@Override

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/echoapp/EchoSpringAppConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public class EchoSpringAppConfig {
2121

2222
@Bean
2323
public SpringLambdaContainerHandler springLambdaContainerHandler() throws ContainerInitializationException {
24-
return SpringLambdaContainerHandler.getAwsProxyHandler(applicationContext, false);
24+
SpringLambdaContainerHandler handler = SpringLambdaContainerHandler.getAwsProxyHandler(applicationContext);
25+
handler.setRefreshContext(false);
26+
return handler;
2527
}
2628

2729
@Bean

0 commit comments

Comments
 (0)