Skip to content

Commit 05aeb79

Browse files
authored
Merge pull request #202 from awslabs/core
Merging 1.2 changes from core branch
2 parents 0fa8730 + 5b7cb74 commit 05aeb79

File tree

126 files changed

+4200
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+4200
-409
lines changed

README.md

Lines changed: 2 additions & 4 deletions
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

@@ -28,9 +29,6 @@ public class StreamLambdaHandler implements RequestStreamHandler {
2829
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
2930
throws IOException {
3031
handler.proxyStream(inputStream, outputStream, context);
31-
32-
// just in case it wasn't closed by the mapper
33-
outputStream.close();
3432
}
3533
}
3634
```

aws-serverless-java-container-core/pom.xml

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
<groupId>com.amazonaws.serverless</groupId>
1313
<artifactId>aws-serverless-java-container</artifactId>
1414
<version>1.2-SNAPSHOT</version>
15+
<relativePath>..</relativePath>
1516
</parent>
1617

1718
<properties>
18-
<jackson.version>2.9.5</jackson.version>
19+
<jackson.version>2.9.7</jackson.version>
1920
<jaxrs.version>2.1</jaxrs.version>
2021
<servlet.version>3.1.0</servlet.version>
2122
</properties>
@@ -49,6 +50,14 @@
4950
<version>${jackson.version}</version>
5051
</dependency>
5152

53+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.module/jackson-module-afterburner -->
54+
<dependency>
55+
<groupId>com.fasterxml.jackson.module</groupId>
56+
<artifactId>jackson-module-afterburner</artifactId>
57+
<version>${jackson.version}</version>
58+
</dependency>
59+
60+
5261
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
5362
<dependency>
5463
<groupId>commons-fileupload</groupId>
@@ -67,6 +76,50 @@
6776

6877
<build>
6978
<plugins>
79+
<plugin>
80+
<groupId>org.jacoco</groupId>
81+
<artifactId>jacoco-maven-plugin</artifactId>
82+
<version>0.8.1</version>
83+
<configuration>
84+
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
85+
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
86+
</configuration>
87+
<executions>
88+
<execution>
89+
<id>default-prepare-agent</id>
90+
<goals>
91+
<goal>prepare-agent</goal>
92+
</goals>
93+
</execution>
94+
<execution>
95+
<id>jacoco-site</id>
96+
<phase>package</phase>
97+
<goals>
98+
<goal>report</goal>
99+
</goals>
100+
</execution>
101+
<execution>
102+
<id>jacoco-check</id>
103+
<phase>test</phase>
104+
<goals>
105+
<goal>check</goal>
106+
</goals>
107+
<configuration>
108+
<haltOnFailure>true</haltOnFailure>
109+
<rules><rule>
110+
<element>BUNDLE</element>
111+
<limits>
112+
<limit>
113+
<counter>INSTRUCTION</counter>
114+
<value>COVEREDRATIO</value>
115+
<minimum>${jacoco.minCoverage}</minimum>
116+
</limit>
117+
</limits>
118+
</rule></rules>
119+
</configuration>
120+
</execution>
121+
</executions>
122+
</plugin>
70123
<plugin>
71124
<groupId>com.github.spotbugs</groupId>
72125
<artifactId>spotbugs-maven-plugin</artifactId>
@@ -109,7 +162,7 @@
109162
<plugin>
110163
<groupId>org.owasp</groupId>
111164
<artifactId>dependency-check-maven</artifactId>
112-
<version>3.1.1</version>
165+
<version>3.3.2</version>
113166
<configuration>
114167
<skipProvidedScope>true</skipProvidedScope>
115168
<suppressionFiles>

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/AwsProxyExceptionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
1717
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
1818
import com.amazonaws.serverless.proxy.model.ErrorModel;
19+
import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap;
1920

2021
import com.fasterxml.jackson.core.JsonProcessingException;
2122
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -57,14 +58,14 @@ public class AwsProxyExceptionHandler
5758
// Variables - Private - Static
5859
//-------------------------------------------------------------
5960

60-
private static Map<String, String> headers = new HashMap<>();
61+
private static MultiValuedTreeMap<String, String> headers = new MultiValuedTreeMap<>(String.CASE_INSENSITIVE_ORDER);
6162

6263
//-------------------------------------------------------------
6364
// Constructors
6465
//-------------------------------------------------------------
6566

6667
static {
67-
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
68+
headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
6869
}
6970

7071

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/LambdaContainerHandler.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.fasterxml.jackson.databind.ObjectMapper;
2929
import com.fasterxml.jackson.databind.ObjectReader;
3030
import com.fasterxml.jackson.databind.ObjectWriter;
31+
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

@@ -81,6 +82,9 @@ public abstract class LambdaContainerHandler<RequestType, ResponseType, Containe
8182

8283
private static ContainerConfig config = ContainerConfig.defaultConfig();
8384
private static ObjectMapper objectMapper = new ObjectMapper();
85+
static {
86+
objectMapper.registerModule(new AfterburnerModule());
87+
}
8488

8589

8690

@@ -135,8 +139,13 @@ public static ObjectMapper getObjectMapper() {
135139
* @param basePath The base path to be stripped from the request
136140
*/
137141
public void stripBasePath(String basePath) {
138-
config.setStripBasePath(true);
139-
config.setServiceBasePath(basePath);
142+
if (basePath == null || "".equals(basePath)) {
143+
config.setStripBasePath(false);
144+
config.setServiceBasePath(null);
145+
} else {
146+
config.setStripBasePath(true);
147+
config.setServiceBasePath(basePath);
148+
}
140149
}
141150

142151
/**
@@ -206,6 +215,9 @@ public void proxyStream(InputStream input, OutputStream output, Context context)
206215
} catch (JsonMappingException e) {
207216
log.error("Error while mapping object to RequestType class", e);
208217
getObjectMapper().writeValue(output, exceptionHandler.handle(e));
218+
} finally {
219+
output.flush();
220+
output.close();
209221
}
210222
}
211223

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/SecurityUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,16 @@ public static String getValidFilePath(String inputPath) {
168168
* @throws IllegalArgumentException If the given path is not valid or outside of /tmp
169169
*/
170170
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
171-
public static String getValidFilePath(String inputPath, boolean isWrite) {
171+
public static String getValidFilePath(final String inputPath, boolean isWrite) {
172172
if (inputPath == null || "".equals(inputPath.trim())) {
173173
return null;
174174
}
175+
String testInputPath = inputPath;
176+
if (testInputPath.startsWith("file://")) {
177+
testInputPath = testInputPath.substring(6);
178+
}
175179

176-
File f = new File(inputPath);
180+
File f = new File(testInputPath);
177181
try {
178182
String canonicalPath = f.getCanonicalPath();
179183

@@ -192,9 +196,9 @@ public static String getValidFilePath(String inputPath, boolean isWrite) {
192196
throw new IllegalArgumentException("File path not allowed: " + encode(canonicalPath));
193197
}
194198

195-
return canonicalPath;
199+
return (inputPath.startsWith("file://") ? "file://" + canonicalPath : canonicalPath);
196200
} catch (IOException e) {
197-
log.error("Invalid file path: {}", encode(inputPath));
201+
log.error("Invalid file path: {}", encode(testInputPath));
198202
throw new IllegalArgumentException("Invalid file path", e);
199203
}
200204
}

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/ApacheCombinedServletLogFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String format(ContainerRequestType servletRequest, ContainerResponseType
108108
logLineBuilder.append("\"");
109109
logLineBuilder.append(servletRequest.getMethod().toUpperCase(Locale.ENGLISH));
110110
logLineBuilder.append(" ");
111-
logLineBuilder.append(servletRequest.getPathInfo());
111+
logLineBuilder.append(servletRequest.getRequestURI());
112112
logLineBuilder.append(" ");
113113
logLineBuilder.append(servletRequest.getProtocol());
114114
logLineBuilder.append("\" ");

0 commit comments

Comments
 (0)