Skip to content

Commit af1ec22

Browse files
committed
Added Spark sample
1 parent 612d582 commit af1ec22

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
3434
}
3535
```
3636

37+
### Spark support
38+
The library also supports applications written with the [Spark framework](http://sparkjava.com/). When using the library with Spark, it's important to initialize the `SparkLambdaContainerHandler` before defining routes.
39+
40+
```java
41+
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
42+
private SparkLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler =
43+
SparkLambdaContainerHandler.getAwsProxyHandler();
44+
private boolean initialized = false;
45+
46+
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
47+
if (!initialized) {
48+
defineRoutes();
49+
initialized = true;
50+
}
51+
return handler.proxy(awsProxyRequest, context);
52+
}
53+
54+
private void defineRoutes() {
55+
get("/hello", (req, res) -> "Hello World");
56+
}
57+
}
58+
```
59+
3760
## Security context
3861
The `aws-serverless-java-container-core` contains a default implementation of the `SecurityContextWriter` that supports API Gateway's proxy integration. The generated security context uses the API Gateway `$context` object to establish the request security context. The context looks for the following values in order and returns the first matched type:
3962

0 commit comments

Comments
 (0)