Skip to content

Commit

Permalink
Rename class file names for Struts implementation without version number
Browse files Browse the repository at this point in the history
  • Loading branch information
jogep committed Aug 17, 2022
1 parent 5cd3ae5 commit 7bdf594
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 67 deletions.
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
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);
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* 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.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.model.HttpApiV2ProxyRequest;
import com.amazonaws.serverless.proxy.struts2.echoapp.EchoAction;
import com.amazonaws.serverless.proxy.struts.echoapp.EchoAction;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -33,7 +33,11 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -45,7 +49,7 @@
* Unit test class for the Struts2 AWS_PROXY default implementation
*/
@RunWith(Parameterized.class)
public class Struts2AwsProxyTest extends StrutsJUnit4TestCase<EchoAction> {
public class StrutsAwsProxyTest extends StrutsJUnit4TestCase<EchoAction> {
private static final String CUSTOM_HEADER_KEY = "x-custom-header";
private static final String CUSTOM_HEADER_VALUE = "my-custom-value";
private static final String AUTHORIZER_PRINCIPAL_ID = "test-principal-" + UUID.randomUUID().toString();
Expand All @@ -56,15 +60,15 @@ public class Struts2AwsProxyTest extends StrutsJUnit4TestCase<EchoAction> {


private static ObjectMapper objectMapper = new ObjectMapper();
private final Struts2LambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = Struts2LambdaContainerHandler
private final StrutsLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = StrutsLambdaContainerHandler
.getAwsProxyHandler();
private final Struts2LambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyResponse> httpApiHandler = Struts2LambdaContainerHandler
private final StrutsLambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyResponse> httpApiHandler = StrutsLambdaContainerHandler
.getHttpApiV2ProxyHandler();
private static Context lambdaContext = new MockLambdaContext();

private String type;

public Struts2AwsProxyTest(String reqType) {
public StrutsAwsProxyTest(String reqType) {
type = reqType;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.amazonaws.serverless.proxy.struts2.echoapp;
package com.amazonaws.serverless.proxy.struts.echoapp;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.io.IOUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.amazonaws.serverless.proxy.struts2.echoapp;
package com.amazonaws.serverless.proxy.struts.echoapp;

import com.amazonaws.serverless.proxy.RequestReader;
import com.amazonaws.serverless.proxy.model.AwsProxyRequestContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<constant name="struts.action.extension" value=","/>

<package name="test" extends="json-default" namespace="/">
<action name="echo" class="com.amazonaws.serverless.proxy.struts2.echoapp.EchoAction" method="execute">
<action name="echo" class="com.amazonaws.serverless.proxy.struts.echoapp.EchoAction" method="execute">
<result type="json">
<param name="root">
message
</param>
</result>
</action>

<action name="echo-request-info" class="com.amazonaws.serverless.proxy.struts2.echoapp.EchoRequestInfoAction"
<action name="echo-request-info" class="com.amazonaws.serverless.proxy.struts.echoapp.EchoRequestInfoAction"
method="execute">
<result type="json">
<param name="root">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ configurations {

dependencies {

implementation ('com.amazonaws.serverless:aws-serverless-java-container-struts2:[1.0,)') {
implementation ('com.amazonaws.serverless:aws-serverless-java-container-struts:[1.0,)') {
exclude group: 'org.apache.struts', module: 'struts2-core'
exclude group: 'org.apache.logging.log4j', module: 'log4j-api'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>\${version}</version>
<packaging>jar</packaging>

<name>Serverless Struts2 API</name>
<name>Serverless Struts API</name>
<url>https://github.com/awslabs/aws-serverless-java-container</url>

<properties>
Expand All @@ -24,7 +24,7 @@
<dependencies>
<dependency>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container-struts2</artifactId>
<artifactId>aws-serverless-java-container-struts</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down Expand Up @@ -101,12 +101,6 @@
<version>\${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>\${log4j.version}</version>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.services.lambda.runtime.Context;

import com.amazonaws.serverless.proxy.struts2.Struts2LambdaHandler;
import com.amazonaws.serverless.proxy.struts.StrutsLambdaHandler;

import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -26,12 +26,12 @@

public class StreamLambdaHandlerTest {

private static Struts2LambdaHandler handler;
private static StrutsLambdaHandler handler;
private static Context lambdaContext;

@BeforeClass
public static void setUp() {
handler = new Struts2LambdaHandler();
handler = new StrutsLambdaHandler();
lambdaContext = new MockLambdaContext();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#set($awsRegion = $awsRegion.replaceAll("\n", "").trim())
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Serverless Apache Struts2 API - ${groupId}::${artifactId}
Description: AWS Serverless Apache Struts API - ${groupId}::${artifactId}
Globals:
Api:
EndpointConfiguration: REGIONAL
Expand All @@ -31,7 +31,7 @@ Resources:
${resourceName}Function:
Type: AWS::Serverless::Function
Properties:
Handler: com.amazonaws.serverless.proxy.struts2.Struts2LambdaHandler::handleRequest
Handler: com.amazonaws.serverless.proxy.struts.StrutsLambdaHandler::handleRequest
Runtime: java11
CodeUri: .
MemorySize: 512
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
groupId=test.service
artifactId=struts2-archetype-test
artifactId=struts-archetype-test
version=1.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Serverless Struts2 example
A basic pet store written with the [Apache Struts framework](https://struts.apache.org). The `Struts2LambdaHandler` object provided by the `aws-serverless-java-container-struts2` is the main entry point for Lambda.
# Serverless Struts example
A basic pet store written with the [Apache Struts framework](https://struts.apache.org). The `StrutsLambdaHandler` object provided by the `aws-serverless-java-container-struts` is the main entry point for Lambda.

The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yml` file in the root folder contains the application definition

Expand Down Expand Up @@ -29,7 +29,7 @@ Once the deployment is completed, the SAM CLI will print out the stack's outputs
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key Struts2PetStoreApi
Key StrutsPetStoreApi
Description URL for application
Value https://n60c1ycwa2.execute-api.eu-central-1.amazonaws.com/pets
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.amazonaws.serverless.sample</groupId>
<artifactId>serverless-struts-example</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Struts2 example for the aws-serverless-java-container library</name>
<name>Struts example for the aws-serverless-java-container library</name>
<description>Simple pet store written with the Apache Struts framework</description>
<url>https://aws.amazon.com/lambda/</url>

Expand Down
Loading

0 comments on commit 7bdf594

Please sign in to comment.