diff --git a/src/main/java/co/zeroae/gate/App.java b/src/main/java/co/zeroae/gate/App.java index c0645bf..4c338e7 100644 --- a/src/main/java/co/zeroae/gate/App.java +++ b/src/main/java/co/zeroae/gate/App.java @@ -53,17 +53,17 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in try { 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); + return response.withBody(export(doc, responseType)).withStatusCode(200); } 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); @@ -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(); } }