From 0c0d2da2980ec7a42609f1def44b5ff33b77243c Mon Sep 17 00:00:00 2001 From: peggy <190728@nttdata.com> Date: Tue, 10 Sep 2019 12:03:19 -0700 Subject: [PATCH] sftp mdc --- .../autoconfigure/plugins/sftp/SftpDocumentInput.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/bc/gov/open/jrccaccess/autoconfigure/plugins/sftp/SftpDocumentInput.java b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/bc/gov/open/jrccaccess/autoconfigure/plugins/sftp/SftpDocumentInput.java index 95c1f314..6c9d9798 100644 --- a/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/bc/gov/open/jrccaccess/autoconfigure/plugins/sftp/SftpDocumentInput.java +++ b/jrcc-access-spring-boot-autoconfigure/src/main/java/ca/bc/gov/open/jrccaccess/autoconfigure/plugins/sftp/SftpDocumentInput.java @@ -1,11 +1,13 @@ package ca.bc.gov.open.jrccaccess.autoconfigure.plugins.sftp; +import ca.bc.gov.open.jrccaccess.autoconfigure.common.Constants; import ca.bc.gov.open.jrccaccess.autoconfigure.services.DocumentReadyHandler; import ca.bc.gov.open.jrccaccess.libs.TransactionInfo; import ca.bc.gov.open.jrccaccess.libs.services.exceptions.DocumentFilenameMissingException; import ca.bc.gov.open.jrccaccess.libs.services.exceptions.DocumentMessageException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.stereotype.Component; @@ -46,12 +48,17 @@ public void handleMessage(Message message) throws DocumentMessageEx logger.debug("Attempting to get file name"); String fileName = getFilename(message); logger.info("Successfully get file name."); + MDC.put(Constants.MDC_KEY_FILENAME, fileName); TransactionInfo transactionInfo = new TransactionInfo(fileName,"sftp", LocalDateTime.now()); logger.debug("Attempting to handler document content"); this.documentReadyHandler.handle(content, transactionInfo); logger.info("successfully handled incoming document."); + MDC.clear(); } catch (IOException e) { - throw new DocumentMessageException(MessageFormat.format("Sftp Input Plugin error while reading the file.{0},{1}.",e.getMessage(),e.getCause())); + String logMsg = MessageFormat.format("Sftp Input Plugin error while reading the file.{0},{1}.",e.getMessage(),e.getCause()); + logger.error(logMsg); + MDC.clear(); + throw new DocumentMessageException(logMsg); } }