1616import java .io .File ;
1717import java .net .URL ;
1818import java .util .HashMap ;
19- import java .util .Map ;
2019import java .util .Objects ;
2120
2221/**
2322 * This class implements a GATE application using AWS Lambda.
2423 * It loads the application from the .gapp file defined by the GATE_APP_FILE environment variable.
2524 * For every lambda invocation, it runs the application and outputs the result in GateXML format.
2625 */
27- public class App implements RequestHandler <APIGatewayProxyRequestEvent , GatewayResponse > {
26+ public class App implements RequestHandler <APIGatewayProxyRequestEvent , APIGatewayProxyResponseEvent > {
2827 static {
2928 try {
3029 Gate .init ();
@@ -36,12 +35,13 @@ public class App implements RequestHandler<APIGatewayProxyRequestEvent, GatewayR
3635 private static final Logger logger = LogManager .getLogger (App .class );
3736 private static final CorpusController application = loadApplication ();
3837
39- public GatewayResponse handleRequest (APIGatewayProxyRequestEvent input , final Context context ) {
40- final Map <String , String > headers = new HashMap <>();
41- headers .put ("Content-Type" , "text/plain" );
38+ public APIGatewayProxyResponseEvent handleRequest (APIGatewayProxyRequestEvent input , final Context context ) {
39+ final APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent ()
40+ .withHeaders (new HashMap <>());
41+ response .getHeaders ().put ("Content-Type" , "text/plain" );
4242
4343 if (!input .getHeaders ().get ("Content-Type" ).equalsIgnoreCase ("text/plain" )) {
44- return new GatewayResponse ("We only support text/plain input." , headers , 400 );
44+ return response . withBody ("We only support text/plain input." ). withStatusCode ( 400 );
4545 }
4646
4747 try {
@@ -50,18 +50,18 @@ public GatewayResponse handleRequest(APIGatewayProxyRequestEvent input, final Co
5050 corpus .add (doc );
5151 try {
5252 application .execute ();
53- headers .put ("Content-Type" , "application/xml" );
54- return new GatewayResponse (doc .toXml (), headers , 200 );
53+ response . getHeaders () .put ("Content-Type" , "application/xml" );
54+ return response . withBody (doc .toXml ()). withStatusCode ( 200 );
5555 } catch (ExecutionException e ) {
5656 logger .error (e );
57- return new GatewayResponse (e .getMessage (), headers , 500 );
57+ return response . withBody (e .getMessage ()). withStatusCode ( 500 );
5858 } finally {
5959 corpus .clear ();
6060 Factory .deleteResource (doc );
6161 }
6262 } catch (ResourceInstantiationException e ) {
6363 logger .warn (e );
64- return new GatewayResponse (e .getMessage (), headers , 400 );
64+ return response . withBody (e .getMessage ()). withStatusCode ( 400 );
6565 }
6666 }
6767
0 commit comments