Skip to content

Commit ddebe84

Browse files
committed
Updated proxyStream method to handle stream flushing and closing. Changed all samples and archetypes to remove the close() call for issue #183.
1 parent 18d3385 commit ddebe84

File tree

10 files changed

+11
-28
lines changed

10 files changed

+11
-28
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public class StreamLambdaHandler implements RequestStreamHandler {
2929
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
3030
throws IOException {
3131
handler.proxyStream(inputStream, outputStream, context);
32-
33-
// just in case it wasn't closed by the mapper
34-
outputStream.close();
3532
}
3633
}
3734
```

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

Lines changed: 7 additions & 0 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

@@ -211,6 +215,9 @@ public void proxyStream(InputStream input, OutputStream output, Context context)
211215
} catch (JsonMappingException e) {
212216
log.error("Error while mapping object to RequestType class", e);
213217
getObjectMapper().writeValue(output, exceptionHandler.handle(e));
218+
} finally {
219+
output.flush();
220+
output.close();
214221
}
215222
}
216223

aws-serverless-jersey-archetype/src/main/resources/archetype-resources/src/main/java/StreamLambdaHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import java.io.InputStream;
1414
import java.io.OutputStream;
1515

16+
import ${groupId}.resource.PingResource;
17+
1618

1719
public class StreamLambdaHandler implements RequestStreamHandler {
1820
private static final ResourceConfig jerseyApplication = new ResourceConfig()
19-
.packages("${groupId}.resource")
21+
.register(PingResource.class)
2022
.register(JacksonFeature.class);
2123
private static final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
2224
= JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
@@ -25,8 +27,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
2527
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
2628
throws IOException {
2729
handler.proxyStream(inputStream, outputStream, context);
28-
29-
// just in case it wasn't closed by the mapper
30-
outputStream.close();
3130
}
3231
}

aws-serverless-spark-archetype/src/main/resources/archetype-resources/src/main/java/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
3333
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
3434
throws IOException {
3535
handler.proxyStream(inputStream, outputStream, context);
36-
37-
// just in case it wasn't closed by the mapper
38-
outputStream.close();
3936
}
4037
}

aws-serverless-spring-archetype/src/main/resources/archetype-resources/src/main/java/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
2929
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
3030
throws IOException {
3131
handler.proxyStream(inputStream, outputStream, context);
32-
33-
// just in case it wasn't closed by the mapper
34-
outputStream.close();
3532
}
3633
}

aws-serverless-springboot-archetype/src/main/resources/archetype-resources/src/main/java/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
2929
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
3030
throws IOException {
3131
handler.proxyStream(inputStream, outputStream, context);
32-
33-
// just in case it wasn't closed by the mapper
34-
outputStream.close();
3532
}
3633
}

samples/jersey/pet-store/src/main/java/com/amazonaws/serverless/sample/jersey/StreamLambdaHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.amazonaws.serverless.sample.jersey;
22

33

4+
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
45
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
56
import com.amazonaws.serverless.proxy.jersey.JerseyLambdaContainerHandler;
67
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
@@ -32,8 +33,5 @@ public StreamLambdaHandler() {
3233
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
3334
throws IOException {
3435
handler.proxyStream(inputStream, outputStream, context);
35-
36-
// just in case it wasn't closed by the mapper
37-
outputStream.close();
3836
}
3937
}

samples/spark/pet-store/src/main/java/com/amazonaws/serverless/sample/spark/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,5 @@ public StreamLambdaHandler() {
5050
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
5151
throws IOException {
5252
handler.proxyStream(inputStream, outputStream, context);
53-
54-
// just in case it wasn't closed by the mapper
55-
outputStream.close();
5653
}
5754
}

samples/spring/pet-store/src/main/java/com/amazonaws/serverless/sample/spring/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,5 @@ public StreamLambdaHandler() {
4747
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
4848
throws IOException {
4949
handler.proxyStream(inputStream, outputStream, context);
50-
51-
// just in case it wasn't closed by the mapper
52-
outputStream.close();
5350
}
5451
}

samples/springboot/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot/StreamLambdaHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,5 @@ public StreamLambdaHandler() {
4646
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
4747
throws IOException {
4848
handler.proxyStream(inputStream, outputStream, context);
49-
50-
// just in case it wasn't closed by the mapper
51-
outputStream.close();
5249
}
5350
}

0 commit comments

Comments
 (0)