Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/struts6 #476

Merged
merged 5 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ jobs:
run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.5.14 -Dspring.version=5.3.20 -Dspringsecurity.version=5.5.8 -Ddependency-check.skip=true

build_struts2:
name: Build and test Struts 2
name: Build and test Struts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build latest
run: ./gha_build.sh struts2 true true
run: ./gha_build.sh struts true true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ Follow the quick start guides in [our wiki](https://github.com/awslabs/aws-serve
* [Apache Struts quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Struts)
* [Jersey quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Jersey)
* [Spark quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spark)
* [Struts quick start](https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Struts)

* Micronaut [documentation](https://guides.micronaut.io/micronaut-function-aws-lambda/guide/index.html) and [demo](https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/micronaut/pet-store) (outdated! - needs to be updated to latest Micronaut version)

Below is the most basic AWS Lambda handler example that launches a Spring application. You can also take a look at the [samples](https://github.com/awslabs/aws-serverless-java-container/tree/master/samples) in this repository, our main wiki page includes a [step-by-step guide](https://github.com/awslabs/aws-serverless-java-container/wiki#deploying-the-sample-applications) on how to deploy the various sample applications using Maven and [SAM](https://github.com/awslabs/serverless-application-model).
Below is the most basic AWS Lambda handler example that launches a Spring application. You can also take a look at the [samples](https://github.com/awslabs/aws-serverless-java-container/tree/master/samples) in this repository, our main wiki page includes a [step-by-step guide](https://github.com/awslabs/aws-serverless-java-container/wiki#deploying-the-sample-applications) on how to deploy the various sample applications using Maven and [SAM](https://github.com/awslabs/serverless-application-model).

```java
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
private static final SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;

static {
try {
handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>aws-serverless-java-container-struts2</artifactId>
<name>AWS Serverless Java container support - Struts2 implementation</name>
<description>Allows Java applications written for the Struts2 framework to run in AWS Lambda</description>
<artifactId>aws-serverless-java-container-struts</artifactId>
<name>AWS Serverless Java container support - Struts implementation</name>
<description>Allows Java applications written for the Struts framework to run in AWS Lambda</description>
<url>https://aws.amazon.com/lambda</url>
<version>1.9-SNAPSHOT</version>

Expand All @@ -15,7 +15,7 @@
</parent>

<properties>
<struts2.version>2.5.30</struts2.version>
<struts.version>6.0.3</struts.version>
</properties>

<dependencies>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
<version>${struts.version}</version>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
Expand All @@ -40,14 +40,14 @@
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${struts2.version}</version>
<version>${struts.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<version>${struts2.version}</version>
<version>${struts.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.serverless.proxy.struts2;
package com.amazonaws.serverless.proxy.struts;

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.*;
import com.amazonaws.serverless.proxy.internal.servlet.*;
import com.amazonaws.serverless.proxy.AwsHttpApiV2SecurityContextWriter;
import com.amazonaws.serverless.proxy.AwsProxyExceptionHandler;
import com.amazonaws.serverless.proxy.AwsProxySecurityContextWriter;
import com.amazonaws.serverless.proxy.ExceptionHandler;
import com.amazonaws.serverless.proxy.RequestReader;
import com.amazonaws.serverless.proxy.ResponseWriter;
import com.amazonaws.serverless.proxy.SecurityContextWriter;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpApiV2HttpServletRequestReader;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletResponse;
import com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader;
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletResponseWriter;
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
Expand All @@ -32,26 +43,26 @@
import java.util.concurrent.CountDownLatch;

/**
* A Lambda handler to initialize the Struts2 filter and proxy the requests.
* A Lambda handler to initialize the Struts filter and proxy the requests.
*
* @param <RequestType> request type
* @param <ResponseType> response type
*/
public class Struts2LambdaContainerHandler<RequestType, ResponseType> extends AwsLambdaServletContainerHandler<RequestType, ResponseType, HttpServletRequest, AwsHttpServletResponse> {
public class StrutsLambdaContainerHandler<RequestType, ResponseType> extends AwsLambdaServletContainerHandler<RequestType, ResponseType, HttpServletRequest, AwsHttpServletResponse> {

private static final Logger log = LoggerFactory.getLogger(Struts2LambdaContainerHandler.class);
private static final Logger log = LoggerFactory.getLogger(StrutsLambdaContainerHandler.class);

public static final String HEADER_STRUTS_STATUS_CODE = "X-Struts-StatusCode";

private static final String TIMER_STRUTS_2_CONTAINER_CONSTRUCTOR = "STRUTS2_CONTAINER_CONSTRUCTOR";
private static final String TIMER_STRUTS_2_HANDLE_REQUEST = "STRUTS2_HANDLE_REQUEST";
private static final String TIMER_STRUTS_2_COLD_START_INIT = "STRUTS2_COLD_START_INIT";
private static final String STRUTS_FILTER_NAME = "Struts2Filter";
private static final String TIMER_STRUTS_CONTAINER_CONSTRUCTOR = "STRUTS_CONTAINER_CONSTRUCTOR";
private static final String TIMER_STRUTS_HANDLE_REQUEST = "STRUTS_HANDLE_REQUEST";
private static final String TIMER_STRUTS_COLD_START_INIT = "STRUTS_COLD_START_INIT";
private static final String STRUTS_FILTER_NAME = "StrutsFilter";

private boolean initialized;

public static Struts2LambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> getAwsProxyHandler() {
return new Struts2LambdaContainerHandler(
public static StrutsLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> getAwsProxyHandler() {
return new StrutsLambdaContainerHandler(
AwsProxyRequest.class,
AwsProxyResponse.class,
new AwsProxyHttpServletRequestReader(),
Expand All @@ -60,8 +71,8 @@ public static Struts2LambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> g
new AwsProxyExceptionHandler());
}

public static Struts2LambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyResponse> getHttpApiV2ProxyHandler() {
return new Struts2LambdaContainerHandler(
public static StrutsLambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyResponse> getHttpApiV2ProxyHandler() {
return new StrutsLambdaContainerHandler(
HttpApiV2ProxyRequest.class,
AwsProxyResponse.class,
new AwsHttpApiV2HttpServletRequestReader(),
Expand All @@ -70,17 +81,17 @@ public static Struts2LambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyRespo
new AwsProxyExceptionHandler());
}

public Struts2LambdaContainerHandler(Class<RequestType> requestTypeClass,
Class<ResponseType> responseTypeClass,
RequestReader<RequestType, HttpServletRequest> requestReader,
ResponseWriter<AwsHttpServletResponse, ResponseType> responseWriter,
SecurityContextWriter<RequestType> securityContextWriter,
ExceptionHandler<ResponseType> exceptionHandler) {
public StrutsLambdaContainerHandler(Class<RequestType> requestTypeClass,
Class<ResponseType> responseTypeClass,
RequestReader<RequestType, HttpServletRequest> requestReader,
ResponseWriter<AwsHttpServletResponse, ResponseType> responseWriter,
SecurityContextWriter<RequestType> securityContextWriter,
ExceptionHandler<ResponseType> exceptionHandler) {

super(requestTypeClass, responseTypeClass, requestReader, responseWriter, securityContextWriter, exceptionHandler);
Timer.start(TIMER_STRUTS_2_CONTAINER_CONSTRUCTOR);
Timer.start(TIMER_STRUTS_CONTAINER_CONSTRUCTOR);
this.initialized = false;
Timer.stop(TIMER_STRUTS_2_CONTAINER_CONSTRUCTOR);
Timer.stop(TIMER_STRUTS_CONTAINER_CONSTRUCTOR);
}

@Override
Expand All @@ -92,7 +103,7 @@ protected AwsHttpServletResponse getContainerResponse(HttpServletRequest request
protected void handleRequest(HttpServletRequest httpServletRequest,
AwsHttpServletResponse httpServletResponse,
Context lambdaContext) throws Exception {
Timer.start(TIMER_STRUTS_2_HANDLE_REQUEST);
Timer.start(TIMER_STRUTS_HANDLE_REQUEST);
if (!this.initialized) {
initialize();
}
Expand All @@ -105,13 +116,13 @@ protected void handleRequest(HttpServletRequest httpServletRequest,
if (responseStatusCode != null) {
httpServletResponse.setStatus(Integer.parseInt(responseStatusCode));
}
Timer.stop(TIMER_STRUTS_2_HANDLE_REQUEST);
Timer.stop(TIMER_STRUTS_HANDLE_REQUEST);
}

@Override
public void initialize() throws ContainerInitializationException {
log.info("Initialize Struts2 Lambda Application ...");
Timer.start(TIMER_STRUTS_2_COLD_START_INIT);
log.info("Initialize Struts Lambda Application ...");
Timer.start(TIMER_STRUTS_COLD_START_INIT);
try {
if (this.startupHandler != null) {
this.startupHandler.onStartup(this.getServletContext());
Expand All @@ -123,12 +134,12 @@ public void initialize() throws ContainerInitializationException {
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.INCLUDE, DispatcherType.FORWARD),
true, "/*");
} catch (Exception e) {
throw new ContainerInitializationException("Could not initialize Struts2", e);
throw new ContainerInitializationException("Could not initialize Struts container", e);
}

this.initialized = true;
Timer.stop(TIMER_STRUTS_2_COLD_START_INIT);
log.info("... initialize of Struts2 Lambda Application completed!");
Timer.stop(TIMER_STRUTS_COLD_START_INIT);
log.info("... initialize of Struts Lambda Application completed!");
}

public Servlet getServlet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.serverless.proxy.struts2;
package com.amazonaws.serverless.proxy.struts;

import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
Expand All @@ -25,12 +25,12 @@
* The lambda handler to handle the requests.
* <p>
* <code>
* com.amazonaws.serverless.proxy.struts2.Struts2LambdaHandler::handleRequest
* com.amazonaws.serverless.proxy.struts.StrutsLambdaHandler::handleRequest
* </code>
*/
public class Struts2LambdaHandler implements RequestStreamHandler {
public class StrutsLambdaHandler implements RequestStreamHandler {

private final Struts2LambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = Struts2LambdaContainerHandler
private final StrutsLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = StrutsLambdaContainerHandler
.getAwsProxyHandler();

@Override
Expand Down
Loading