From a9e048077a33ba17faa37cb0cd5cae9146945b12 Mon Sep 17 00:00:00 2001 From: James Creel Date: Mon, 16 Jul 2018 14:44:43 -0500 Subject: [PATCH] Improved archivematica logging --- .../ArchivematicaFilesystemRepository.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/tamu/app/service/repository/ArchivematicaFilesystemRepository.java b/src/main/java/edu/tamu/app/service/repository/ArchivematicaFilesystemRepository.java index 4bb37d09..6e6bb4e7 100644 --- a/src/main/java/edu/tamu/app/service/repository/ArchivematicaFilesystemRepository.java +++ b/src/main/java/edu/tamu/app/service/repository/ArchivematicaFilesystemRepository.java @@ -23,6 +23,8 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; +import org.apache.jena.atlas.logging.Log; +import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.Base64Utils; @@ -32,6 +34,7 @@ import edu.tamu.app.model.Document; import edu.tamu.app.model.ProjectRepository; import edu.tamu.app.model.repo.DocumentRepo; +import edu.tamu.app.service.DocumentFactory; import edu.tamu.app.utilities.CsvUtility; public class ArchivematicaFilesystemRepository implements Repository { @@ -45,6 +48,8 @@ public class ArchivematicaFilesystemRepository implements Repository { private ProjectRepository projectRepository; private CsvUtility csvUtility; + + private static final Logger logger = Logger.getLogger(ArchivematicaFilesystemRepository.class); public ArchivematicaFilesystemRepository(ProjectRepository projectRepository) { this.projectRepository = projectRepository; @@ -61,7 +66,7 @@ public Document push(Document document) throws IOException { // make the top level container for the transfer package File archivematicaPackageDirectory = new File(getArchivematicaTopDirectory() + File.separator + document.getProject().getName() + "_" + document.getName()); - System.out.println("Writing Archivematica Transfer Package for Document " + itemDirectoryPath + " to " + archivematicaPackageDirectory.getCanonicalPath()); + logger.info("Writing Archivematica Transfer Package for Document " + itemDirectoryPath + " to " + archivematicaPackageDirectory.getCanonicalPath()); if (!archivematicaPackageDirectory.isDirectory()) archivematicaPackageDirectory.mkdir(); @@ -175,7 +180,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica try { connection.setRequestMethod("POST"); } catch (ProtocolException e) { - ProtocolException pe = new ProtocolException("Failed to set Archivematica request method to GET; that protocol for the request is invalid. {" + e.getMessage() + "}"); + ProtocolException pe = new ProtocolException("Failed to set Archivematica request method to POST; that protocol for the request is invalid. {" + e.getMessage() + "}"); pe.setStackTrace(e.getStackTrace()); throw pe; } @@ -184,7 +189,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica String itemDirectoryName = document.getProject().getName() + "_" + document.getName(); String pathString = getArchivematicaTransferSourceLocationUUID() + ":" + getArchivematicaTransferLocationDirectoryName() + File.separator + itemDirectoryName; - System.out.println("Transfer package path string: " + pathString); + logger.info("Transfer package path string: " + pathString); String encodedPath = Base64Utils.encodeToString(pathString.getBytes()); // Write post data by opening an output stream on the connection and @@ -201,8 +206,7 @@ private boolean startArchivematicaTransfer(Document document, File archivematica String params = ""; params += "name=" + document.getProject().getName() + "_" + document.getName() + "&type=standard" + "&paths[]=" + encodedPath; try { - System.out.println("POST DATA: "); - System.out.println(params); + logger.info("POST request parameters being sent to archivematica: "+ params); connection.getOutputStream().write(params.getBytes()); @@ -214,12 +218,13 @@ private boolean startArchivematicaTransfer(Document document, File archivematica // Read response from item post StringBuilder response = new StringBuilder(); + BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(connection.getInputStream())); } catch (IOException e) { - IOException ioe = new IOException("Could not get input stream for a response from the connection of the post request. Response message was \"" + connection.getResponseMessage() + IOException ioe = new IOException("Could not get input stream for a response from the connection of the POST request. Response message was \"" + connection.getResponseMessage() + "\" with this exception thrown: {" + e.getMessage() + "}"); ioe.setStackTrace(e.getStackTrace()); throw ioe; @@ -236,6 +241,8 @@ private boolean startArchivematicaTransfer(Document document, File archivematica ioe.setStackTrace(e.getStackTrace()); throw ioe; } + + logger.info("POST request to archivematica resulted in response code of " + connection.getResponseCode() + " with response: " + response.toString()); // Close streams try {