Skip to content

Commit 305372a

Browse files
committed
Merge branch 'struts2' of https://github.com/jogep/aws-serverless-java-container into core
2 parents 8ba04ba + 7e0a5ab commit 305372a

File tree

28 files changed

+2029
-1
lines changed

28 files changed

+2029
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Serverless Java container [![Build Status](https://travis-ci.org/awslabs/aws-serverless-java-container.svg?branch=master)](https://travis-ci.org/awslabs/aws-serverless-java-container) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.amazonaws.serverless/aws-serverless-java-container/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.amazonaws.serverless/aws-serverless-java-container) [![Help](http://img.shields.io/badge/help-gitter-E91E63.svg?style=flat-square)](https://gitter.im/awslabs/aws-serverless-java-container)
2-
The `aws-serverless-java-container` makes it easy to run Java applications written with frameworks such as [Spring](https://spring.io/), [Spring Boot](https://projects.spring.io/spring-boot/), [Jersey](https://jersey.java.net/), or [Spark](http://sparkjava.com/) in [AWS Lambda](https://aws.amazon.com/lambda/).
2+
The `aws-serverless-java-container` makes it easy to run Java applications written with frameworks such as [Spring](https://spring.io/), [Spring Boot](https://projects.spring.io/spring-boot/), [Apache Struts](http://struts.apache.org/), [Jersey](https://jersey.java.net/), or [Spark](http://sparkjava.com/) in [AWS Lambda](https://aws.amazon.com/lambda/).
33

44
Serverless Java Container natively supports API Gateway's proxy integration models for requests and responses, you can create and inject custom models for methods that use custom mappings.
55

66
Follow the quick start guides in [our wiki](https://github.com/awslabs/aws-serverless-java-container/wiki) to integrate Serverless Java Container with your project:
77
* [Spring quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring)
88
* [Spring Boot quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot)
9+
* [Apache Struts quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start-Struts)
910
* [Jersey quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Jersey)
1011
* [Spark quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spark)
1112

archetypes/struts/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.amazonaws.serverless</groupId>
7+
<artifactId>aws-serverless-java-container</artifactId>
8+
<version>1.2-SNAPSHOT</version>
9+
</parent>
10+
11+
<groupId>com.amazonaws.serverless.archetypes</groupId>
12+
<artifactId>aws-serverless-struts-archetype</artifactId>
13+
<version>1.2-SNAPSHOT</version>
14+
<packaging>maven-archetype</packaging>
15+
16+
<scm>
17+
<url>https://github.com/awslabs/aws-serverless-java-container.git</url>
18+
</scm>
19+
20+
<licenses>
21+
<license>
22+
<name>The Apache Software License, Version 2.0</name>
23+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
24+
<distribution>repo</distribution>
25+
</license>
26+
</licenses>
27+
28+
<build>
29+
<extensions>
30+
<extension>
31+
<groupId>org.apache.maven.archetype</groupId>
32+
<artifactId>archetype-packaging</artifactId>
33+
<version>3.0.1</version>
34+
</extension>
35+
</extensions>
36+
37+
<pluginManagement>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-archetype-plugin</artifactId>
42+
<version>3.0.1</version>
43+
</plugin>
44+
</plugins>
45+
</pluginManagement>
46+
</build>
47+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<archetype-descriptor name="aws-serverless-springboot-archetype"
2+
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd">
5+
<fileSets>
6+
<fileSet filtered="true" packaged="true">
7+
<directory>src/main/java</directory>
8+
<includes>
9+
<include>**/*.java</include>
10+
</includes>
11+
</fileSet>
12+
<fileSet>
13+
<directory>src/main/resources</directory>
14+
<includes>
15+
<include>**/*.properties</include>
16+
<include>**/*.xml</include>
17+
</includes>
18+
</fileSet>
19+
<fileSet>
20+
<directory>src/main/assembly</directory>
21+
<includes>
22+
<include>**/*.xml</include>
23+
</includes>
24+
</fileSet>
25+
<fileSet filtered="true">
26+
<directory></directory>
27+
<includes>
28+
<include>sam.yaml</include>
29+
<include>README.md</include>
30+
</includes>
31+
</fileSet>
32+
</fileSets>
33+
</archetype-descriptor>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#set($resourceName = $artifactId)
2+
#macro(replaceChar $originalName, $char)
3+
#if($originalName.contains($char))
4+
#set($tokens = $originalName.split($char))
5+
#set($newResourceName = "")
6+
#foreach($token in $tokens)
7+
#set($newResourceName = $newResourceName + $token.substring(0,1).toUpperCase() + $token.substring(1).toLowerCase())
8+
#end
9+
${newResourceName}
10+
#else
11+
#set($newResourceName = $originalName.substring(0,1).toUpperCase() + $originalName.substring(1))
12+
${newResourceName}
13+
#end
14+
#end
15+
#set($resourceName = "#replaceChar($resourceName, '-')")
16+
#set($resourceName = "#replaceChar($resourceName, '.')")
17+
#set($resourceName = $resourceName.replaceAll("\n", "").trim())
18+
# ${artifactId} serverless API
19+
The ${artifactId} project, created with [`aws-serverless-java-container`](https://github.com/awslabs/aws-serverless-java-container).
20+
21+
The starter project defines a simple `/ping` resource that can accept `GET` requests with its tests.
22+
23+
The project folder also includes a `sam.yaml` file. You can use this [SAM](https://github.com/awslabs/serverless-application-model) file to deploy the project to AWS Lambda and Amazon API Gateway or test in local with [SAM Local](https://github.com/awslabs/aws-sam-local).
24+
25+
## Building the project
26+
Using [Maven](https://maven.apache.org/), you can create an AWS Lambda-compatible jar file simply by running the maven package command from the projct folder.
27+
28+
```bash
29+
$ mvn archetype:generate -DartifactId=my-spring-api -DarchetypeGroupId=com.amazonaws.serverless.archetypes -DarchetypeArtifactId=aws-serverless-spring-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.sapessi.spring -Dversion=0.1 -Dinteractive=false
30+
$ cd my-spring-api
31+
$ mvn clean package
32+
33+
[INFO] ------------------------------------------------------------------------
34+
[INFO] BUILD SUCCESS
35+
[INFO] ------------------------------------------------------------------------
36+
[INFO] Total time: 6.546 s
37+
[INFO] Finished at: 2018-02-15T08:39:33-08:00
38+
[INFO] Final Memory: XXM/XXXM
39+
[INFO] ------------------------------------------------------------------------
40+
```
41+
42+
## Testing locally with SAM local
43+
You can use [AWS SAM Local](https://github.com/awslabs/aws-sam-local) to start your project.
44+
45+
First, install SAM local:
46+
47+
```bash
48+
$ npm install -g aws-sam-local
49+
```
50+
51+
Next, from the project root folder - where the `sam.yaml` file is located - start the API with the SAM Local CLI.
52+
53+
```bash
54+
$ sam local start-api --template sam.yaml
55+
56+
...
57+
Mounting ${groupId}.StreamLambdaHandler::handleRequest (java8) at http://127.0.0.1:3000/{proxy+} [OPTIONS GET HEAD POST PUT DELETE PATCH]
58+
...
59+
```
60+
61+
Using a new shell, you can send a test ping request to your API:
62+
63+
```bash
64+
$ curl -s http://127.0.0.1:3000/ping | python -m json.tool
65+
66+
{
67+
"pong": "Hello, World!"
68+
}
69+
```
70+
71+
## Deploying to AWS
72+
You can use the [AWS CLI](https://aws.amazon.com/cli/) to quickly deploy your application to AWS Lambda and Amazon API Gateway with your SAM template.
73+
74+
You will need an S3 bucket to store the artifacts for deployment. Once you have created the S3 bucket, run the following command from the project's root folder - where the `sam.yaml` file is located:
75+
76+
```
77+
$ aws cloudformation package --template-file sam.yaml --output-template-file output-sam.yaml --s3-bucket <YOUR S3 BUCKET NAME>
78+
Uploading to xxxxxxxxxxxxxxxxxxxxxxxxxx 6464692 / 6464692.0 (100.00%)
79+
Successfully packaged artifacts and wrote output template to file output-sam.yaml.
80+
Execute the following command to deploy the packaged template
81+
aws cloudformation deploy --template-file /your/path/output-sam.yaml --stack-name <YOUR STACK NAME>
82+
```
83+
84+
As the command output suggests, you can now use the cli to deploy the application. Choose a stack name and run the `aws cloudformation deploy` command from the output of the package command.
85+
86+
```
87+
$ aws cloudformation deploy --template-file output-sam.yaml --stack-name ServerlessSpringApi --capabilities CAPABILITY_IAM
88+
```
89+
90+
Once the application is deployed, you can describe the stack to show the API endpoint that was created. The endpoint should be the `ServerlessSpringApi` key of the `Outputs` property:
91+
92+
```
93+
$ aws cloudformation describe-stacks --stack-name ServerlessSpringApi
94+
{
95+
"Stacks": [
96+
{
97+
"StackId": "arn:aws:cloudformation:us-west-2:xxxxxxxx:stack/ServerlessSpringApi/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
98+
"Description": "AWS Serverless Spring API - ${groupId}::${artifactId}",
99+
"Tags": [],
100+
"Outputs": [
101+
{
102+
"Description": "URL for application",
103+
"ExportName": "${resourceName}Api",
104+
"OutputKey": "${resourceName}Api",
105+
"OutputValue": "https://xxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/ping"
106+
}
107+
],
108+
"CreationTime": "2016-12-13T22:59:31.552Z",
109+
"Capabilities": [
110+
"CAPABILITY_IAM"
111+
],
112+
"StackName": "ServerlessSpringApi",
113+
"NotificationARNs": [],
114+
"StackStatus": "UPDATE_COMPLETE"
115+
}
116+
]
117+
}
118+
119+
```
120+
121+
Copy the `OutputValue` into a browser or use curl to test your first request:
122+
123+
```bash
124+
$ curl -s https://xxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/ping | python -m json.tool
125+
126+
{
127+
"pong": "Hello, World!"
128+
}
129+
```
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>${groupId}</groupId>
8+
<artifactId>${artifactId}</artifactId>
9+
<version>${version}</version>
10+
<packaging>jar</packaging>
11+
12+
<name>Serverless Spring Boot API</name>
13+
<url>https://github.com/awslabs/aws-serverless-java-container</url>
14+
15+
<parent>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
18+
<version>1.5.10.RELEASE</version>
19+
</parent>
20+
21+
<properties>
22+
<maven.compiler.source>1.8</maven.compiler.source>
23+
<maven.compiler.target>1.8</maven.compiler.target>
24+
<struts2.version>2.5.17</struts2.version>
25+
<jackson.version>2.9.5</jackson.version>
26+
<junit.version>4.12</junit.version>
27+
<log4j.version>2.8.2</log4j.version>
28+
</properties>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>com.amazonaws.serverless</groupId>
33+
<artifactId>aws-serverless-java-container-struts2</artifactId>
34+
<version>1.2.0</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.amazonaws</groupId>
39+
<artifactId>aws-lambda-java-core</artifactId>
40+
<version>1.2.0</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.apache.struts</groupId>
45+
<artifactId>struts2-convention-plugin</artifactId>
46+
<version>${struts2.version}</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.apache.struts</groupId>
51+
<artifactId>struts2-rest-plugin</artifactId>
52+
<version>${struts2.version}</version>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.apache.struts</groupId>
57+
<artifactId>struts2-bean-validation-plugin</artifactId>
58+
<version>${struts2.version}</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.apache.struts</groupId>
63+
<artifactId>struts2-junit-plugin</artifactId>
64+
<version>${struts2.version}</version>
65+
<scope>test</scope>
66+
</dependency>
67+
68+
<!-- some useful interceptors and helpers for lambda based applications -->
69+
<dependency>
70+
<groupId>com.jgeppert.struts2</groupId>
71+
<artifactId>struts2-aws-lambda-support-plugin</artifactId>
72+
<version>1.0.0</version>
73+
</dependency>
74+
75+
<!-- bean validation based on hibernate validators-->
76+
<dependency>
77+
<groupId>org.hibernate</groupId>
78+
<artifactId>hibernate-validator</artifactId>
79+
<version>4.3.2.Final</version>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>com.fasterxml.jackson.core</groupId>
84+
<artifactId>jackson-core</artifactId>
85+
<version>2.9.4</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-annotations</artifactId>
90+
<version>2.9.4</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>com.fasterxml.jackson.core</groupId>
94+
<artifactId>jackson-databind</artifactId>
95+
<version>2.9.4</version>
96+
</dependency>
97+
98+
<dependency>
99+
<groupId>org.apache.logging.log4j</groupId>
100+
<artifactId>log4j-core</artifactId>
101+
<version>${log4j.version}</version>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>org.apache.logging.log4j</groupId>
106+
<artifactId>log4j-api</artifactId>
107+
<version>${log4j.version}</version>
108+
</dependency>
109+
110+
<dependency>
111+
<groupId>org.apache.logging.log4j</groupId>
112+
<artifactId>log4j-slf4j-impl</artifactId>
113+
<version>${log4j.version}</version>
114+
</dependency>
115+
116+
<dependency>
117+
<groupId>com.amazonaws</groupId>
118+
<artifactId>aws-lambda-java-log4j2</artifactId>
119+
<version>1.1.0</version>
120+
</dependency>
121+
122+
<dependency>
123+
<groupId>junit</groupId>
124+
<artifactId>junit</artifactId>
125+
<version>${junit.version}</version>
126+
<scope>test</scope>
127+
</dependency>
128+
</dependencies>
129+
130+
<build>
131+
<plugins>
132+
<plugin>
133+
<groupId>org.apache.maven.plugins</groupId>
134+
<artifactId>maven-assembly-plugin</artifactId>
135+
<version>3.1.0</version>
136+
<configuration>
137+
<descriptors>
138+
<descriptor>src/main/assembly/dist.xml</descriptor>
139+
</descriptors>
140+
</configuration>
141+
<executions>
142+
<execution>
143+
<id>lambda</id>
144+
<phase>package</phase>
145+
<goals>
146+
<goal>single</goal>
147+
</goals>
148+
</execution>
149+
</executions>
150+
</plugin>
151+
</plugins>
152+
</build>
153+
</project>

0 commit comments

Comments
 (0)