From b8452498cd1a28f2db05673b59229cfb450602f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Sun, 31 Jan 2021 07:21:19 -0500 Subject: [PATCH 1/2] Move the exception handling one try/catch block up --- src/main/java/co/zeroae/gate/App.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/co/zeroae/gate/App.java b/src/main/java/co/zeroae/gate/App.java index c0645bf..b285a7e 100644 --- a/src/main/java/co/zeroae/gate/App.java +++ b/src/main/java/co/zeroae/gate/App.java @@ -54,16 +54,16 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in application.execute(); response.getHeaders().put("Content-Type", responseType); return response.withBody(encode(doc, responseType)).withStatusCode(200); - } catch (ExecutionException e) { - logger.error(e); - return response.withBody(e.getMessage()).withStatusCode(400); - } catch (IOException e) { - logger.error(e); - return response.withBody(e.getMessage()).withStatusCode(406); } finally { corpus.clear(); Factory.deleteResource(doc); } + } catch (ExecutionException e) { + logger.error(e); + return response.withBody(e.getMessage()).withStatusCode(400); + } catch (IOException e) { + logger.error(e); + return response.withBody(e.getMessage()).withStatusCode(406); } catch (ResourceInstantiationException e) { logger.warn(e); return response.withBody(e.getMessage()).withStatusCode(400); From b69130972cf3305254818a625929533bca1a2894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Sun, 31 Jan 2021 07:27:25 -0500 Subject: [PATCH 2/2] Rename encode to export --- src/main/java/co/zeroae/gate/App.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/zeroae/gate/App.java b/src/main/java/co/zeroae/gate/App.java index b285a7e..4c338e7 100644 --- a/src/main/java/co/zeroae/gate/App.java +++ b/src/main/java/co/zeroae/gate/App.java @@ -53,7 +53,7 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in try { application.execute(); response.getHeaders().put("Content-Type", responseType); - return response.withBody(encode(doc, responseType)).withStatusCode(200); + return response.withBody(export(doc, responseType)).withStatusCode(200); } finally { corpus.clear(); Factory.deleteResource(doc); @@ -74,7 +74,7 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in * @param doc an instance of gate.Document * @param responseType One of the supported response types */ - private String encode(Document doc, String responseType) throws IOException { + private String export(Document doc, String responseType) throws IOException { final FeatureMap exportOptions = Factory.newFeatureMap(); // Take *all* annotation types. @@ -90,8 +90,7 @@ private String encode(Document doc, String responseType) throws IOException { gateJsonExporter.setAnnotationTypes(doc.getAnnotationSetNames()); gateJsonExporter.export(doc, baos, exportOptions); return baos.toString(); - } - else { + } else { return doc.toXml(); } }