Skip to content

Commit

Permalink
Updated proxyStream method to handle stream flushing and closing. Cha…
Browse files Browse the repository at this point in the history
…nged all samples and archetypes to remove the close() call for issue #183.
  • Loading branch information
sapessi committed Oct 22, 2018
1 parent 18d3385 commit ddebe84
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 28 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class StreamLambdaHandler implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

private static ContainerConfig config = ContainerConfig.defaultConfig();
private static ObjectMapper objectMapper = new ObjectMapper();
static {
objectMapper.registerModule(new AfterburnerModule());
}



Expand Down Expand Up @@ -211,6 +215,9 @@ public void proxyStream(InputStream input, OutputStream output, Context context)
} 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 @@ -13,10 +13,12 @@
import java.io.InputStream;
import java.io.OutputStream;

import ${groupId}.resource.PingResource;


public class StreamLambdaHandler implements RequestStreamHandler {
private static final ResourceConfig jerseyApplication = new ResourceConfig()
.packages("${groupId}.resource")
.register(PingResource.class)
.register(JacksonFeature.class);
private static final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
= JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
Expand All @@ -25,8 +27,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@ public class StreamLambdaHandler implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amazonaws.serverless.sample.jersey;


import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
import com.amazonaws.serverless.proxy.jersey.JerseyLambdaContainerHandler;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
Expand Down Expand Up @@ -32,8 +33,5 @@ public StreamLambdaHandler() {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,5 @@ public StreamLambdaHandler() {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@ public StreamLambdaHandler() {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@ public StreamLambdaHandler() {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);

// just in case it wasn't closed by the mapper
outputStream.close();
}
}

0 comments on commit ddebe84

Please sign in to comment.