22
33import com .amazonaws .services .lambda .runtime .Context ;
44import com .amazonaws .services .lambda .runtime .RequestHandler ;
5+ import com .amazonaws .services .lambda .runtime .events .APIGatewayProxyRequestEvent ;
6+ import com .amazonaws .services .lambda .runtime .events .APIGatewayProxyResponseEvent ;
7+
58import gate .*;
69import gate .creole .ExecutionException ;
710import gate .creole .ResourceInstantiationException ;
2124 * It loads the application from the .gapp file defined by the GATE_APP_FILE environment variable.
2225 * For every lambda invocation, it runs the application and outputs the result in GateXML format.
2326 */
24- public class App implements RequestHandler < Map < String , ?> , GatewayResponse > {
27+ public class App implements RequestHandler <APIGatewayProxyRequestEvent , GatewayResponse > {
2528 static {
2629 try {
2730 Gate .init ();
@@ -33,18 +36,16 @@ public class App implements RequestHandler< Map<String, ?>, GatewayResponse> {
3336 private static final Logger logger = LogManager .getLogger (App .class );
3437 private static final CorpusController application = loadApplication ();
3538
36- public GatewayResponse handleRequest (final Map < String , ?> input , final Context context ) {
39+ public GatewayResponse handleRequest (APIGatewayProxyRequestEvent input , final Context context ) {
3740 final Map <String , String > headers = new HashMap <>();
3841 headers .put ("Content-Type" , "text/plain" );
3942
40- @ SuppressWarnings ("unchecked" )
41- final Map <String , String > inputHeaders = (Map <String , String >) input .get ("headers" );
42- if (!inputHeaders .get ("Content-Type" ).equalsIgnoreCase ("text/plain" )) {
43+ if (!input .getHeaders ().get ("Content-Type" ).equalsIgnoreCase ("text/plain" )) {
4344 return new GatewayResponse ("We only support text/plain input." , headers , 400 );
4445 }
4546
4647 try {
47- final Document doc = Factory .newDocument (input .get ( "body" ). toString ());
48+ final Document doc = Factory .newDocument (input .getBody ());
4849 final Corpus corpus = application .getCorpus ();
4950 corpus .add (doc );
5051 try {
0 commit comments