diff --git a/aws-serverless-java-container-struts/pom.xml b/aws-serverless-java-container-struts/pom.xml index a30571ca2..c39bf516d 100644 --- a/aws-serverless-java-container-struts/pom.xml +++ b/aws-serverless-java-container-struts/pom.xml @@ -15,7 +15,7 @@ - 2.5.30 + 6.0.3 diff --git a/aws-serverless-java-container-struts/src/main/java/com/amazonaws/serverless/proxy/struts/StrutsLambdaContainerHandler.java b/aws-serverless-java-container-struts/src/main/java/com/amazonaws/serverless/proxy/struts/StrutsLambdaContainerHandler.java index 42ff0aee8..09c460cfa 100644 --- a/aws-serverless-java-container-struts/src/main/java/com/amazonaws/serverless/proxy/struts/StrutsLambdaContainerHandler.java +++ b/aws-serverless-java-container-struts/src/main/java/com/amazonaws/serverless/proxy/struts/StrutsLambdaContainerHandler.java @@ -121,7 +121,7 @@ protected void handleRequest(HttpServletRequest httpServletRequest, @Override public void initialize() throws ContainerInitializationException { - log.info("Initialize Struts2 Lambda Application ..."); + log.info("Initialize Struts Lambda Application ..."); Timer.start(TIMER_STRUTS_COLD_START_INIT); try { if (this.startupHandler != null) { diff --git a/aws-serverless-java-container-struts/src/test/java/com/amazonaws/serverless/proxy/struts/StrutsAwsProxyTest.java b/aws-serverless-java-container-struts/src/test/java/com/amazonaws/serverless/proxy/struts/StrutsAwsProxyTest.java index b4f9ecf95..eb890cf5b 100644 --- a/aws-serverless-java-container-struts/src/test/java/com/amazonaws/serverless/proxy/struts/StrutsAwsProxyTest.java +++ b/aws-serverless-java-container-struts/src/test/java/com/amazonaws/serverless/proxy/struts/StrutsAwsProxyTest.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; -import org.apache.struts2.StrutsJUnit4TestCase; +import org.apache.struts2.StrutsRestTestCase; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -49,24 +49,25 @@ * Unit test class for the Struts2 AWS_PROXY default implementation */ @RunWith(Parameterized.class) -public class StrutsAwsProxyTest extends StrutsJUnit4TestCase { +public class StrutsAwsProxyTest extends StrutsRestTestCase { 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(); + private static final String HTTP_METHOD_GET = "GET"; + private static final String QUERY_STRING_MODE = "mode"; private static final String QUERY_STRING_KEY = "message"; private static final String QUERY_STRING_ENCODED_VALUE = "Hello Struts2"; private static final String USER_PRINCIPAL = "user1"; private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json; charset=UTF-8"; - private static ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private final StrutsLambdaContainerHandler handler = StrutsLambdaContainerHandler .getAwsProxyHandler(); private final StrutsLambdaContainerHandler httpApiHandler = StrutsLambdaContainerHandler .getHttpApiV2ProxyHandler(); - private static Context lambdaContext = new MockLambdaContext(); - - private String type; + private final Context lambdaContext = new MockLambdaContext(); + private final String type; public StrutsAwsProxyTest(String reqType) { type = reqType; @@ -92,8 +93,8 @@ private AwsProxyResponse executeRequest(AwsProxyRequestBuilder requestBuilder, C @Test public void headers_getHeaders_echo() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "headers") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "headers") .header(CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE) .json(); @@ -106,7 +107,7 @@ public void headers_getHeaders_echo() { @Test public void context_servletResponse_setCustomHeader() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "GET") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", HTTP_METHOD_GET) .queryString("customHeader", "true") .json(); @@ -118,7 +119,7 @@ public void context_servletResponse_setCustomHeader() { @Test public void context_serverInfo_correctContext() { assumeTrue("API_GW".equals(type)); - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "GET") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", HTTP_METHOD_GET) .queryString(QUERY_STRING_KEY, "Hello Struts2") .header("Content-Type", "application/json") .queryString("contentType", "true"); @@ -131,8 +132,8 @@ public void context_serverInfo_correctContext() { @Test public void queryString_uriInfo_echo() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "query-string") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "query-string") .queryString(CUSTOM_HEADER_KEY, CUSTOM_HEADER_VALUE) .json(); @@ -146,8 +147,8 @@ public void queryString_uriInfo_echo() { @Test public void requestScheme_valid_expectHttps() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "scheme") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "scheme") .queryString(QUERY_STRING_KEY, QUERY_STRING_ENCODED_VALUE) .json(); @@ -161,8 +162,8 @@ public void requestScheme_valid_expectHttps() { @Test public void authorizer_securityContext_customPrincipalSuccess() { assumeTrue("API_GW".equals(type)); - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "principal") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "principal") .json() .authorizerPrincipal(AUTHORIZER_PRINCIPAL_ID); @@ -175,7 +176,7 @@ public void authorizer_securityContext_customPrincipalSuccess() { @Test public void errors_unknownRoute_expect404() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/unknown", "GET"); + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/unknown", HTTP_METHOD_GET); AwsProxyResponse output = executeRequest(request, lambdaContext); assertEquals(404, output.getStatusCode()); @@ -184,7 +185,7 @@ public void errors_unknownRoute_expect404() { @Test public void error_contentType_invalidContentType() { AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "POST") - .queryString("mode", "content-type") + .queryString(QUERY_STRING_MODE, "content-type") .header("Content-Type", "application/octet-stream") .body("asdasdasd"); @@ -195,7 +196,7 @@ public void error_contentType_invalidContentType() { @Test public void error_statusCode_methodNotAllowed() { AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "POST") - .queryString("mode", "not-allowed") + .queryString(QUERY_STRING_MODE, "not-allowed") .json(); AwsProxyResponse output = executeRequest(request, lambdaContext); @@ -209,7 +210,7 @@ public void responseBody_responseWriter_validBody() throws JsonProcessingExcepti value.put(QUERY_STRING_KEY, CUSTOM_HEADER_VALUE); AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "POST") .json() - .body(objectMapper.writeValueAsString(value)); + .body(OBJECT_MAPPER.writeValueAsString(value)); AwsProxyResponse output = executeRequest(request, lambdaContext); assertEquals(200, output.getStatusCode()); @@ -220,8 +221,8 @@ public void responseBody_responseWriter_validBody() throws JsonProcessingExcepti @Test public void statusCode_responseStatusCode_customStatusCode() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "custom-status-code") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "custom-status-code") .queryString("status", "201") .json(); @@ -231,7 +232,7 @@ public void statusCode_responseStatusCode_customStatusCode() { @Test public void base64_binaryResponse_base64Encoding() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "GET"); + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", HTTP_METHOD_GET); AwsProxyResponse response = executeRequest(request, lambdaContext); assertNotNull(response.getBody()); @@ -241,7 +242,7 @@ public void base64_binaryResponse_base64Encoding() { @Test public void exception_mapException_mapToNotImplemented() { AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "POST") - .queryString("mode", "not-implemented"); + .queryString(QUERY_STRING_MODE, "not-implemented"); AwsProxyResponse response = executeRequest(request, lambdaContext); assertNotNull(response.getBody()); @@ -251,7 +252,7 @@ public void exception_mapException_mapToNotImplemented() { @Test public void stripBasePath_route_shouldRouteCorrectly() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/custompath/echo", "GET") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/custompath/echo", HTTP_METHOD_GET) .json() .queryString(QUERY_STRING_KEY, "stripped"); handler.stripBasePath("/custompath"); @@ -263,7 +264,7 @@ public void stripBasePath_route_shouldRouteCorrectly() { @Test public void stripBasePath_route_shouldReturn404() { - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/custompath/echo/status-code", "GET") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/custompath/echo/status-code", HTTP_METHOD_GET) .json() .queryString("status", "201"); handler.stripBasePath("/custom"); @@ -275,8 +276,8 @@ public void stripBasePath_route_shouldReturn404() { @Test public void securityContext_injectPrincipal_expectPrincipalName() { assumeTrue("API_GW".equals(type)); - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", "GET") - .queryString("mode", "principal") + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo-request-info", HTTP_METHOD_GET) + .queryString(QUERY_STRING_MODE, "principal") .authorizerPrincipal(USER_PRINCIPAL); AwsProxyResponse resp = executeRequest(request, lambdaContext); @@ -295,7 +296,7 @@ public void queryParam_encoding_expectUnencodedParam() { e.printStackTrace(); fail("Could not decode parameter"); } - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "GET").queryString(QUERY_STRING_KEY, decodedParam); + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", HTTP_METHOD_GET).queryString(QUERY_STRING_KEY, decodedParam); AwsProxyResponse resp = executeRequest(request, lambdaContext); assertEquals(200, resp.getStatusCode()); @@ -306,7 +307,7 @@ public void queryParam_encoding_expectUnencodedParam() { public void queryParam_encoding_expectEncodedParam() { assumeTrue("API_GW".equals(type)); String paramValue = "p%2Fz%2B3"; - AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", "GET").queryString(QUERY_STRING_KEY, paramValue); + AwsProxyRequestBuilder request = new AwsProxyRequestBuilder("/echo", HTTP_METHOD_GET).queryString(QUERY_STRING_KEY, paramValue); AwsProxyResponse resp = executeRequest(request, lambdaContext); assertEquals(200, resp.getStatusCode()); @@ -323,7 +324,7 @@ private void validateMapResponseModel(AwsProxyResponse output, String key, Strin TypeReference> typeRef = new TypeReference>() { }; - HashMap response = objectMapper.readValue(output.getBody(), typeRef); + HashMap response = OBJECT_MAPPER.readValue(output.getBody(), typeRef); assertNotNull(response.get(key)); assertEquals(value, response.get(key)); } catch (IOException e) { @@ -335,7 +336,7 @@ private void validateMapResponseModel(AwsProxyResponse output, String key, Strin private void validateSingleValueModel(AwsProxyResponse output, String value) { try { assertNotNull(output.getBody()); - assertEquals(value, objectMapper.readerFor(String.class).readValue(output.getBody())); + assertEquals(value, OBJECT_MAPPER.readerFor(String.class).readValue(output.getBody())); } catch (Exception e) { e.printStackTrace(); fail("Exception while parsing response body: " + e.getMessage()); diff --git a/aws-serverless-java-container-struts/src/test/resources/log4j2.xml b/aws-serverless-java-container-struts/src/test/resources/log4j2.xml new file mode 100644 index 000000000..55ed0d21c --- /dev/null +++ b/aws-serverless-java-container-struts/src/test/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n + + + + + + + + + + + \ No newline at end of file diff --git a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/build.gradle b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/build.gradle index 240979c70..b44a7dfa8 100644 --- a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/build.gradle +++ b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/build.gradle @@ -18,22 +18,22 @@ dependencies { exclude group: 'org.apache.logging.log4j', module: 'log4j-api' exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j' } - implementation ('org.apache.struts:struts2-convention-plugin:2.5.30') { + implementation ('org.apache.struts:struts2-convention-plugin:6.0.3') { exclude group: 'org.apache.struts', module: 'struts2-core' } - implementation ('org.apache.struts:struts2-rest-plugin:2.5.30') { + implementation ('org.apache.struts:struts2-rest-plugin:6.0.3') { exclude group: 'org.apache.struts', module: 'struts2-core' } - implementation ('org.apache.struts:struts2-bean-validation-plugin:2.5.30') { + implementation ('org.apache.struts:struts2-bean-validation-plugin:6.0.3') { exclude group: 'org.apache.struts', module: 'struts2-core' } - implementation ('com.jgeppert.struts2:struts2-aws-lambda-support-plugin:1.3.0') { + implementation ('com.jgeppert.struts2:struts2-aws-lambda-support-plugin:1.4.0') { exclude group: 'org.apache.struts', module: 'struts2-core' } - implementation ('org.apache.struts:struts2-core:2.5.30') { + implementation ('org.apache.struts:struts2-core:6.0.3') { exclude group: 'org.apache.logging.log4j', module: 'log4j-api' } - implementation ('org.hibernate:hibernate-validator:5.4.3.Final') + implementation ('org.hibernate:hibernate-validator:6.1.7.Final') implementation ('com.fasterxml.jackson.core:jackson-databind:2.13.3') implementation ('org.apache.logging.log4j:log4j-core:2.17.2') implementation ('org.apache.logging.log4j:log4j-api:2.17.2') @@ -41,7 +41,7 @@ dependencies { implementation ('com.amazonaws:aws-lambda-java-log4j2:1.5.1') testImplementation('junit:junit:4.13.2') - testImplementation('org.apache.struts:struts2-junit-plugin:2.5.30') { + testImplementation('org.apache.struts:struts2-junit-plugin:6.0.3') { exclude group: 'org.apache.struts', module: 'struts2-core' } } diff --git a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/pom.xml b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/pom.xml index 05685d6d3..e9d3b8b40 100644 --- a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/pom.xml +++ b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/pom.xml @@ -15,12 +15,19 @@ 1.8 1.8 - 2.5.30 + 6.0.3 2.13.3 4.13.2 - 2.17.2 + 2.18.0 + + + struts-staging + https://repository.apache.org/content/repositories/staging/ + + + com.amazonaws.serverless @@ -63,14 +70,14 @@ com.jgeppert.struts2 struts2-aws-lambda-support-plugin - 1.3.0 + 1.4.0 org.hibernate hibernate-validator - 5.4.3.Final + 6.1.7.Final @@ -88,6 +95,11 @@ jackson-databind \${jackson.version} + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + \${jackson.version} + org.apache.logging.log4j diff --git a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/src/main/resources/struts.xml b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/src/main/resources/struts.xml index 5b86eb974..f6975ffd0 100644 --- a/aws-serverless-struts-archetype/src/main/resources/archetype-resources/src/main/resources/struts.xml +++ b/aws-serverless-struts-archetype/src/main/resources/archetype-resources/src/main/resources/struts.xml @@ -24,7 +24,7 @@ + class="org.apache.struts2.rest.handler.JacksonJsonHandler"/> diff --git a/samples/struts/pet-store/build.gradle b/samples/struts/pet-store/build.gradle index 1d734194c..a28ffc6c3 100644 --- a/samples/struts/pet-store/build.gradle +++ b/samples/struts/pet-store/build.gradle @@ -14,12 +14,12 @@ configurations { dependencies { implementation ( 'com.amazonaws.serverless:aws-serverless-java-container-struts2:[1.0,)', - 'org.apache.struts:struts2-convention-plugin:2.5.30', - 'org.apache.struts:struts2-rest-plugin:2.5.30', - 'org.apache.struts:struts2-bean-validation-plugin:2.5.30', - 'org.apache.struts:struts2-junit-plugin:2.5.30', - 'com.jgeppert.struts2:struts2-aws-lambda-support-plugin:1.3.0', - 'org.hibernate:hibernate-validator:5.4.3.Final', + 'org.apache.struts:struts2-convention-plugin:6.0.3', + 'org.apache.struts:struts2-rest-plugin:6.0.3', + 'org.apache.struts:struts2-bean-validation-plugin:6.0.3', + 'org.apache.struts:struts2-junit-plugin:6.0.3', + 'com.jgeppert.struts2:struts2-aws-lambda-support-plugin:1.4.0', + 'org.hibernate:hibernate-validator:6.1.7.Final', 'com.fasterxml.jackson.core:jackson-databind:2.13.3', 'org.apache.logging.log4j:log4j-core:2.17.2', 'org.apache.logging.log4j:log4j-api:2.17.2', diff --git a/samples/struts/pet-store/pom.xml b/samples/struts/pet-store/pom.xml index 751fa1a57..bb307b015 100644 --- a/samples/struts/pet-store/pom.xml +++ b/samples/struts/pet-store/pom.xml @@ -26,7 +26,7 @@ 1.8 1.8 - 2.5.30 + 6.0.3 2.13.3 4.13.2 2.17.2 @@ -74,14 +74,14 @@ com.jgeppert.struts2 struts2-aws-lambda-support-plugin - 1.3.0 + 1.4.0 org.hibernate hibernate-validator - 5.4.3.Final + 6.1.7.Final