-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from 2012160085/main
Fix Asynchronous Dispatch Logic in AwsAsyncContext with Spring's DispatcherServlet
- Loading branch information
Showing
19 changed files
with
382 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...va-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/AsyncAppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.amazonaws.serverless.proxy.spring; | ||
|
||
import com.amazonaws.serverless.exceptions.ContainerInitializationException; | ||
import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder; | ||
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyRequest; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyResponse; | ||
import com.amazonaws.serverless.proxy.spring.springapp.LambdaHandler; | ||
import com.amazonaws.serverless.proxy.spring.springapp.MessageController; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class AsyncAppTest { | ||
|
||
private static LambdaHandler handler; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
try { | ||
handler = new LambdaHandler(); | ||
} catch (ContainerInitializationException e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
void springApp_helloRequest_returnsCorrect() { | ||
AwsProxyRequest req = new AwsProxyRequestBuilder("/hello", "GET").build(); | ||
AwsProxyResponse resp = handler.handleRequest(req, new MockLambdaContext()); | ||
assertEquals(200, resp.getStatusCode()); | ||
assertEquals(MessageController.HELLO_MESSAGE, resp.getBody()); | ||
} | ||
|
||
@Test | ||
void springApp_asyncRequest_returnsCorrect() { | ||
AwsProxyRequest req = new AwsProxyRequestBuilder("/async", "GET").build(); | ||
AwsProxyResponse resp = handler.handleRequest(req, new MockLambdaContext()); | ||
assertEquals(200, resp.getStatusCode()); | ||
assertEquals(MessageController.HELLO_MESSAGE, resp.getBody()); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ainer-spring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@Import({MessageController.class}) | ||
public class AppConfig { } |
26 changes: 26 additions & 0 deletions
26
...r-spring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/LambdaHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import com.amazonaws.serverless.exceptions.ContainerInitializationException; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyRequest; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyResponse; | ||
import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; | ||
import com.amazonaws.serverless.proxy.spring.SpringProxyHandlerBuilder; | ||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
|
||
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> { | ||
private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; | ||
|
||
public LambdaHandler() throws ContainerInitializationException { | ||
handler = new SpringProxyHandlerBuilder<AwsProxyRequest>() | ||
.defaultProxy() | ||
.asyncInit() | ||
.configurationClasses(AppConfig.class) | ||
.buildAndInitialize(); | ||
} | ||
|
||
@Override | ||
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) { | ||
return handler.proxy(awsProxyRequest, context); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/MessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.context.request.async.DeferredResult; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@RestController | ||
@EnableWebMvc | ||
public class MessageController { | ||
public static final String HELLO_MESSAGE = "Hello"; | ||
|
||
@RequestMapping(path="/hello", method= RequestMethod.GET) | ||
public String hello() { | ||
return HELLO_MESSAGE; | ||
} | ||
|
||
@RequestMapping(path="/async", method= RequestMethod.GET) | ||
public DeferredResult<String> asyncHello() { | ||
DeferredResult<String> result = new DeferredResult<>(); | ||
result.setResult(HELLO_MESSAGE); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.