Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Currently the following versions are maintained:
|---------|--------|-----------------------------|-----------------|------------------------|----------------|---------------|
| 1.x | [1.x](https://github.com/aws/serverless-java-container/tree/1.x) | Java EE (javax.*) | 5.x (Boot 2.x) | 2.x | :white_check_mark: | :white_check_mark: |
| 2.x | [main](https://github.com/aws/serverless-java-container/tree/main) | Jakarta EE 9-10 (jakarta.*) | 6.x (Boot 3.x) | 3.x | :x: | :x: |
| 3.x | | Jakarta EE 11 (jakarta.*) | 7.x (Boot 4.x) | 4.x | :x: | :x: |
| 3.x | [main](https://github.com/aws/serverless-java-container/tree/main) | Jakarta EE 11 (jakarta.*) | 7.x (Boot 4.x) | 4.x | :x: | :x: |

Follow the quick start guides in [our wiki](https://github.com/aws/serverless-java-container/wiki) to integrate Serverless Java Container with your project:
* [Spring quick start](https://github.com/aws/serverless-java-container/wiki/Quick-start---Spring)
Expand Down
9 changes: 5 additions & 4 deletions aws-serverless-java-container-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
<name>AWS Serverless Java container support - Core</name>
<description>Allows Java applications written for a servlet container to run in AWS Lambda</description>
<url>https://aws.amazon.com/lambda</url>
<version>2.1.5-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>

<parent>
<groupId>com.amazonaws.serverless</groupId>
<artifactId>aws-serverless-java-container</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<properties>
<jaxrs.version>3.1.0</jaxrs.version>
<servlet.version>6.0.0</servlet.version>
<jackson.version>3.0.2</jackson.version>
</properties>

<dependencies>
Expand All @@ -40,13 +41,13 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<groupId>tools.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>${jackson.version}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.amazonaws.serverless.proxy.model.ErrorModel;
import com.amazonaws.serverless.proxy.model.Headers;

import com.fasterxml.jackson.core.JsonProcessingException;
import tools.jackson.core.JacksonException;
import jakarta.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -103,7 +103,7 @@ protected String getErrorJson(String message) {

try {
return LambdaContainerHandler.getObjectMapper().writeValueAsString(new ErrorModel(message));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
log.error("Could not produce error JSON", e);
return "{ \"message\": \"" + message + "\" }";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import com.amazonaws.serverless.proxy.model.ContainerConfig;
import com.amazonaws.services.lambda.runtime.Context;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectReader;
import tools.jackson.databind.ObjectWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -86,10 +84,9 @@ public abstract class LambdaContainerHandler<RequestType, ResponseType, Containe
}

private static void registerAfterBurner() {
objectMapper.registerModule(new AfterburnerModule());
// AfterburnerModule is built-in in Jackson 3, no need to register
}


//-------------------------------------------------------------
// Constructors
//-------------------------------------------------------------
Expand Down Expand Up @@ -258,12 +255,9 @@ public void proxyStream(InputStream input, OutputStream output, Context context)
ResponseType resp = proxy(request, context);

objectWriter.writeValue(output, resp);
} catch (JsonParseException e) {
} catch (JacksonException e) {
log.error("Error while parsing request object stream", e);
getObjectMapper().writeValue(output, exceptionHandler.handle(e));
} catch (JsonMappingException e) {
log.error("Error while mapping object to RequestType class", e);
getObjectMapper().writeValue(output, exceptionHandler.handle(e));
} finally {
output.flush();
output.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.amazonaws.serverless.proxy.internal.SecurityUtils;
import com.amazonaws.serverless.proxy.model.HttpApiV2ProxyRequest;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.JsonNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -66,7 +66,7 @@ public Principal getUserPrincipal() {
return (() -> {
return subject;
});
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
log.error("Error while attempting to parse JWT body for requestId: " + SecurityUtils.crlf(event.getRequestContext().getRequestId()), e);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
package com.amazonaws.serverless.proxy.model;

import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
import tools.jackson.core.JsonGenerator;
import tools.jackson.core.JsonParser;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.annotation.JsonDeserialize;
import tools.jackson.databind.annotation.JsonSerialize;
import tools.jackson.databind.deser.std.StdDeserializer;
import tools.jackson.databind.ser.std.StdSerializer;
import tools.jackson.databind.type.TypeFactory;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -77,18 +76,17 @@ public HttpApiV2AuthorizerDeserializer() {
}

@Override
public HttpApiV2AuthorizerMap deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
public HttpApiV2AuthorizerMap deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
HttpApiV2AuthorizerMap map = new HttpApiV2AuthorizerMap();
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
JsonNode node = deserializationContext.readTree(jsonParser);
if (node.has(JWT_KEY)) {
HttpApiV2JwtAuthorizer authorizer = LambdaContainerHandler.getObjectMapper()
.treeToValue(node.get(JWT_KEY), HttpApiV2JwtAuthorizer.class);
map.putJwtAuthorizer(authorizer);
}
if (node.has(LAMBDA_KEY)) {
Map<String, Object> context = LambdaContainerHandler.getObjectMapper().treeToValue(node.get(LAMBDA_KEY),
TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class));
LambdaContainerHandler.getObjectMapper().getTypeFactory().constructMapType(HashMap.class, String.class, Object.class));
map.put(LAMBDA_KEY, context);
}
if (node.has(IAM_KEY)) {
Expand All @@ -110,16 +108,19 @@ public HttpApiV2AuthorizerSerializer() {

@Override
public void serialize(HttpApiV2AuthorizerMap httpApiV2AuthorizerMap, JsonGenerator jsonGenerator,
SerializerProvider serializerProvider) throws IOException {
SerializationContext serializationContext) {
jsonGenerator.writeStartObject();
if (httpApiV2AuthorizerMap.isJwt()) {
jsonGenerator.writeObjectField(JWT_KEY, httpApiV2AuthorizerMap.getJwtAuthorizer());
jsonGenerator.writeName(JWT_KEY);
jsonGenerator.writePOJO(httpApiV2AuthorizerMap.getJwtAuthorizer());
}
if (httpApiV2AuthorizerMap.isLambda()) {
jsonGenerator.writeObjectField(LAMBDA_KEY, httpApiV2AuthorizerMap.getLambdaAuthorizerContext());
jsonGenerator.writeName(LAMBDA_KEY);
jsonGenerator.writePOJO(httpApiV2AuthorizerMap.getLambdaAuthorizerContext());
}
if (httpApiV2AuthorizerMap.isIam()) {
jsonGenerator.writeObjectField(IAM_KEY, httpApiV2AuthorizerMap.get(IAM_KEY));
jsonGenerator.writeName(IAM_KEY);
jsonGenerator.writePOJO(httpApiV2AuthorizerMap.get(IAM_KEY));
}
jsonGenerator.writeEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.amazonaws.serverless.exceptions.InvalidResponseObjectException;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.model.ErrorModel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -47,7 +47,7 @@ void typedHandle_InvalidRequestEventException_500State() {

@Test
void typedHandle_InvalidRequestEventException_responseString()
throws JsonProcessingException {
throws JacksonException {
AwsProxyResponse resp = exceptionHandler.handle(new InvalidRequestEventException(INVALID_REQUEST_MESSAGE, null));

assertNotNull(resp);
Expand All @@ -74,7 +74,7 @@ void typedHandle_InvalidResponseObjectException_502State() {

@Test
void typedHandle_InvalidResponseObjectException_responseString()
throws JsonProcessingException {
throws JacksonException {
AwsProxyResponse resp = exceptionHandler.handle(new InvalidResponseObjectException(INVALID_RESPONSE_MESSAGE, null));

assertNotNull(resp);
Expand Down Expand Up @@ -106,7 +106,7 @@ void typedHandle_InternalServerErrorException_500State() {

@Test
void typedHandle_InternalServerErrorException_responseString()
throws JsonProcessingException {
throws JacksonException {
InternalServerErrorException mockInternalServerErrorException = Mockito.mock(InternalServerErrorException.class);
Mockito.when(mockInternalServerErrorException.getMessage()).thenReturn(INTERNAL_SERVER_ERROR_MESSAGE);

Expand All @@ -131,7 +131,7 @@ void typedHandle_InternalServerErrorException_jsonContentTypeHeader() {

@Test
void typedHandle_NullPointerException_responseObject()
throws JsonProcessingException {
throws JacksonException {
AwsProxyResponse resp = exceptionHandler.handle(new NullPointerException());

assertNotNull(resp);
Expand Down Expand Up @@ -248,7 +248,7 @@ void getErrorJson_ErrorModel_validJson()
void getErrorJson_JsonParsinException_validJson()
throws IOException {
ObjectMapper mockMapper = mock(ObjectMapper.class);
JsonProcessingException exception = mock(JsonProcessingException.class);
JacksonException exception = mock(JacksonException.class);
when(mockMapper.writeValueAsString(any(Object.class))).thenThrow(exception);

String output = exceptionHandler.getErrorJson(INVALID_RESPONSE_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.amazonaws.serverless.proxy.model.*;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.JacksonException;
import tools.jackson.databind.ObjectMapper;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.io.IOUtils;
import org.apache.hc.core5.http.ContentType;
Expand Down Expand Up @@ -106,7 +106,7 @@ public AwsProxyRequestBuilder alb() {
try {
String json = objectMapper.writeValueAsString(this.request);
albRequest = objectMapper.readValue(json, AwsProxyRequest.class);
} catch (JsonProcessingException jpe) {
} catch (JacksonException jpe) {
throw new RuntimeException(jpe);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ public AwsProxyRequestBuilder body(Object body) {
if (request.getMultiValueHeaders() != null && request.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).startsWith(MediaType.APPLICATION_JSON)) {
try {
return body(LambdaContainerHandler.getObjectMapper().writeValueAsString(body));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
throw new UnsupportedOperationException("Could not serialize object: " + e.getMessage());
}
} else {
Expand Down Expand Up @@ -438,7 +438,7 @@ public InputStream buildStream() {
try {
String requestJson = LambdaContainerHandler.getObjectMapper().writeValueAsString(request);
return new ByteArrayInputStream(requestJson.getBytes(StandardCharsets.UTF_8));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
return null;
}
}
Expand All @@ -448,7 +448,7 @@ public InputStream toHttpApiV2RequestStream() {
try {
String requestJson = LambdaContainerHandler.getObjectMapper().writeValueAsString(req);
return new ByteArrayInputStream(requestJson.getBytes(StandardCharsets.UTF_8));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.io.IOException;
import org.junit.jupiter.api.Test;
import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

public class AwsProxyRequestTest {
private static final String CUSTOM_HEADER_KEY_LOWER_CASE = "custom-header";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.amazonaws.serverless.proxy.model;

import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import tools.jackson.core.JacksonException;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
Expand Down Expand Up @@ -181,7 +181,7 @@ void deserialize_fromJsonString_authorizerPopulatedCorrectly() {
assertTrue(req.getRequestContext().getAuthorizer().getJwtAuthorizer().getClaims().containsKey("claim1"));
assertEquals(2, req.getRequestContext().getAuthorizer().getJwtAuthorizer().getScopes().size());
assertEquals(RequestSource.API_GATEWAY, req.getRequestSource());
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while parsing request" + e.getMessage());
}
Expand All @@ -196,7 +196,7 @@ void deserialize_fromJsonString_authorizerEmptyMap() {
assertFalse(req.getRequestContext().getAuthorizer().isJwt());
assertFalse(req.getRequestContext().getAuthorizer().isLambda());
assertFalse(req.getRequestContext().getAuthorizer().isIam());
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while parsing request" + e.getMessage());
}
Expand All @@ -212,7 +212,7 @@ void deserialize_fromJsonString_lambdaAuthorizer() {
assertTrue(req.getRequestContext().getAuthorizer().isLambda());
assertEquals(5, req.getRequestContext().getAuthorizer().getLambdaAuthorizerContext().size());
assertEquals(1, req.getRequestContext().getAuthorizer().getLambdaAuthorizerContext().get("numberKey"));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while parsing request" + e.getMessage());
}
Expand All @@ -239,7 +239,7 @@ void deserialize_fromJsonString_iamAuthorizer() {
req.getRequestContext().getAuthorizer().getIamAuthorizer().getUserArn());
assertEquals("AIDACOSFODNN7EXAMPLE2",
req.getRequestContext().getAuthorizer().getIamAuthorizer().getUserId());
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while parsing request" + e.getMessage());
}
Expand All @@ -254,7 +254,7 @@ void deserialize_fromJsonString_isBase64EncodedPopulates() {
req = LambdaContainerHandler.getObjectMapper().readValue(NO_AUTH_PROXY, HttpApiV2ProxyRequest.class);
assertTrue(req.isBase64Encoded());
assertEquals(RequestSource.API_GATEWAY, req.getRequestSource());
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while parsing request" + e.getMessage());
}
Expand All @@ -277,7 +277,7 @@ void serialize_toJsonString_authorizerPopulatesCorrectly() {
assertTrue(reqString.contains("\"scopes\":[\"first\",\"second\"]"));
assertTrue(reqString.contains("\"authorizer\":{\"jwt\":{"));
assertTrue(reqString.contains("\"isBase64Encoded\":false"));
} catch (JsonProcessingException e) {
} catch (JacksonException e) {
e.printStackTrace();
fail("Exception while serializing request" + e.getMessage());
}
Expand Down
Loading
Loading