diff --git a/core/src/main/java/nl/nn/adapterframework/core/Adapter.java b/core/src/main/java/nl/nn/adapterframework/core/Adapter.java index b3f7ddf2d7f..a45a583429a 100644 --- a/core/src/main/java/nl/nn/adapterframework/core/Adapter.java +++ b/core/src/main/java/nl/nn/adapterframework/core/Adapter.java @@ -103,7 +103,7 @@ public class Adapter implements IAdapter, NamedBean { private String targetDesignDocument; private boolean active=true; - private ArrayList receivers = new ArrayList<>(); + private ArrayList> receivers = new ArrayList<>(); private long lastMessageDate = 0; private String lastMessageProcessingState; //"OK" or "ERROR" private PipeLine pipeline; @@ -326,32 +326,25 @@ public long getLastExitIsTimeoutDate(String pipeName) { } @Override - public synchronized String formatErrorMessage(String errorMessage, Throwable t, Message originalMessage, String messageID, INamedObject objectInError, long receivedTime) { + public Message formatErrorMessage(String errorMessage, Throwable t, Message originalMessage, String messageID, INamedObject objectInError, long receivedTime) { if (errorMessageFormatter == null) { errorMessageFormatter = new ErrorMessageFormatter(); } // you never can trust an implementation, so try/catch! try { - String formattedErrorMessage= errorMessageFormatter.format( - errorMessage, - t, - objectInError, - originalMessage, - messageID, - receivedTime); + Message formattedErrorMessage= errorMessageFormatter.format(errorMessage, t, objectInError, originalMessage, messageID, receivedTime); if(msgLog.isEnabled(MSGLOG_LEVEL_TERSE)) { - String resultOrSize = (isMsgLogHidden()) ? "SIZE="+getFileSizeAsBytes(new Message(formattedErrorMessage)) : formattedErrorMessage; + String resultOrSize = (isMsgLogHidden()) ? "SIZE="+getFileSizeAsBytes(formattedErrorMessage) : formattedErrorMessage.toString(); msgLog.log(MSGLOG_LEVEL_TERSE, String.format("Adapter [%s] messageId [%s] formatted errormessage, result [%s]", getName(), messageID, resultOrSize)); } return formattedErrorMessage; - } - catch (Exception e) { + } catch (Exception e) { String msg = "got error while formatting errormessage, original errorMessage [" + errorMessage + "]"; msg = msg + " from [" + (objectInError == null ? "unknown-null" : objectInError.getName()) + "]"; error(false, "got error while formatting errormessage", e); - return errorMessage; + return new Message(errorMessage); } } /** @@ -523,7 +516,7 @@ public Receiver getReceiverByNameAndListener(String receiverName, Class liste } @Override - public Iterable getReceivers() { + public Iterable> getReceivers() { return receivers; } @@ -590,7 +583,7 @@ public PipeLineResult processMessage(String messageId, Message message, IPipeLin objectInError = this; } } - result.setResult(new Message(formatErrorMessage(msg, t, message, messageId, objectInError, startTime))); + result.setResult(formatErrorMessage(msg, t, message, messageId, objectInError, startTime)); //if (isRequestReplyLogging()) { String format = "Adapter [%s] messageId [%s] got exit-state [%s] and result [%s] from PipeLine"; diff --git a/core/src/main/java/nl/nn/adapterframework/core/IAdapter.java b/core/src/main/java/nl/nn/adapterframework/core/IAdapter.java index 5cdaf919cc1..1edd7f1f7fe 100644 --- a/core/src/main/java/nl/nn/adapterframework/core/IAdapter.java +++ b/core/src/main/java/nl/nn/adapterframework/core/IAdapter.java @@ -48,8 +48,8 @@ public interface IAdapter extends IManagable { * the web-functions. */ public MessageKeeper getMessageKeeper(); - public Receiver getReceiverByName(String receiverName); - public Iterable getReceivers(); + public Receiver getReceiverByName(String receiverName); + public Iterable> getReceivers(); public PipeLineResult processMessage(String messageId, Message message, IPipeLineSession pipeLineSession); public PipeLineResult processMessageWithExceptions(String messageId, Message message, IPipeLineSession pipeLineSession) throws ListenerException; @@ -59,7 +59,7 @@ public interface IAdapter extends IManagable { public Configuration getConfiguration(); public boolean isAutoStart(); - public String formatErrorMessage(String errorMessage, Throwable t, Message originalMessage, String messageID, INamedObject objectInError, long receivedTime); + public Message formatErrorMessage(String errorMessage, Throwable t, Message originalMessage, String messageID, INamedObject objectInError, long receivedTime); public void forEachStatisticsKeeperBody(StatisticsKeeperIterationHandler hski, Object data, int action) throws SenderException ; diff --git a/core/src/main/java/nl/nn/adapterframework/core/IErrorMessageFormatter.java b/core/src/main/java/nl/nn/adapterframework/core/IErrorMessageFormatter.java index 4993a213aa7..8d8ef6a444b 100644 --- a/core/src/main/java/nl/nn/adapterframework/core/IErrorMessageFormatter.java +++ b/core/src/main/java/nl/nn/adapterframework/core/IErrorMessageFormatter.java @@ -26,5 +26,5 @@ */ public interface IErrorMessageFormatter { - public String format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime); + public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime); } diff --git a/core/src/main/java/nl/nn/adapterframework/core/IMessageHandler.java b/core/src/main/java/nl/nn/adapterframework/core/IMessageHandler.java index 65b4a149348..ccc4cd3b42b 100644 --- a/core/src/main/java/nl/nn/adapterframework/core/IMessageHandler.java +++ b/core/src/main/java/nl/nn/adapterframework/core/IMessageHandler.java @@ -61,6 +61,6 @@ public interface IMessageHandler { * Formats any exception thrown by any of the above methods to a message that can be returned. * Can be used if the calling system has no other way of returnin the exception to the caller. */ - public String formatException(String extrainfo, String correlationId, Message message, Throwable t); + public Message formatException(String extrainfo, String correlationId, Message message, Throwable t); } diff --git a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/ErrorMessageFormatter.java b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/ErrorMessageFormatter.java index ca2c66427f2..3dd3e64cde0 100644 --- a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/ErrorMessageFormatter.java +++ b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/ErrorMessageFormatter.java @@ -59,7 +59,7 @@ public class ErrorMessageFormatter implements IErrorMessageFormatter { * Override this method in descender-classes to obtain the required behaviour. */ @Override - public String format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { + public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { String details = null; errorMessage = getErrorMessage(errorMessage, t); @@ -102,7 +102,7 @@ public String format(String errorMessage, Throwable t, INamedObject location, Me } errorXml.addSubElement(originalMessageXml); - return errorXml.toXML(); + return new Message(errorXml.toXML()); } protected String getErrorMessage(String message, Throwable t) { diff --git a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/FixedErrorMessage.java b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/FixedErrorMessage.java index 06a14cf4659..321a17ac461 100644 --- a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/FixedErrorMessage.java +++ b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/FixedErrorMessage.java @@ -15,6 +15,7 @@ */ package nl.nn.adapterframework.errormessageformatters; +import java.io.IOException; import java.net.URL; import nl.nn.adapterframework.core.INamedObject; @@ -44,25 +45,29 @@ public class FixedErrorMessage extends ErrorMessageFormatter { private String styleSheetName = null; @Override - public String format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { + public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { - String stringToReturn = getReturnString(); - if (stringToReturn==null) { - stringToReturn=""; + Message messageToReturn = new Message(getReturnString()); + if (messageToReturn.isEmpty()) { + messageToReturn=new Message(""); } if (StringUtils.isNotEmpty(getFileName())) { try { - stringToReturn += Misc.resourceToString(ClassUtils.getResourceURL(classLoader, getFileName()), SystemUtils.LINE_SEPARATOR); + messageToReturn = new Message(messageToReturn.asString() + Misc.resourceToString(ClassUtils.getResourceURL(classLoader, getFileName()), SystemUtils.LINE_SEPARATOR)); } catch (Throwable e) { log.error("got exception loading error message file [" + getFileName() + "]", e); } - } - if (StringUtils.isEmpty(stringToReturn)) { - stringToReturn = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime); + } + if (messageToReturn.isEmpty()) { + messageToReturn = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime); } if (StringUtils.isNotEmpty(getReplaceFrom())) { - stringToReturn = Misc.replace(stringToReturn, getReplaceFrom(), getReplaceTo() ); + try { + messageToReturn = new Message(Misc.replace(messageToReturn.asString(), getReplaceFrom(), getReplaceTo())); + } catch (IOException e) { + log.error("got error formatting errorMessage", e); + } } if (StringUtils.isNotEmpty(styleSheetName)) { @@ -71,15 +76,15 @@ public String format(String errorMessage, Throwable t, INamedObject location, Me try{ String xsltResult = null; Transformer transformer = XmlUtils.createTransformer(xsltSource); - xsltResult = XmlUtils.transformXml(transformer, stringToReturn); - stringToReturn = xsltResult; + xsltResult = XmlUtils.transformXml(transformer, messageToReturn.asSource()); + messageToReturn = new Message(xsltResult); } catch (Throwable e) { log.error("got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", e); } } } - return stringToReturn; + return messageToReturn; } diff --git a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/SoapErrorMessage.java b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/SoapErrorMessage.java index 24dde97b8db..0f5c553cc48 100644 --- a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/SoapErrorMessage.java +++ b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/SoapErrorMessage.java @@ -27,10 +27,10 @@ public class SoapErrorMessage extends ErrorMessageFormatter { @Override - public String format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { + public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { try { - return SoapWrapper.getInstance().createSoapFaultMessage(getErrorMessage(errorMessage, t)).asString(); + return SoapWrapper.getInstance().createSoapFaultMessage(getErrorMessage(errorMessage, t)); } catch (Exception e) { log.error("got error getting soapWrapper instance", e); return super.format(errorMessage, t, location, originalMessage, messageId, receivedTime); diff --git a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/XslErrorMessageFormatter.java b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/XslErrorMessageFormatter.java index 5e6ea2ca3bc..8d24e6d3c31 100644 --- a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/XslErrorMessageFormatter.java +++ b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/XslErrorMessageFormatter.java @@ -57,9 +57,9 @@ public class XslErrorMessageFormatter extends ErrorMessageFormatter { private String xpathExpression; @Override - public String format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { + public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) { - String result = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime); + Message result = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime); if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) { try { @@ -94,7 +94,7 @@ public String format(String errorMessage, Throwable t, INamedObject location, Me XmlUtils.setTransformerParameters(errorTransformer, parametervalues ); } - result = XmlUtils.transformXml(errorTransformer, result); + result = new Message(XmlUtils.transformXml(errorTransformer, result.asSource())); } catch (IOException e) { log.error(" cannot retrieve [" + styleSheet + "]", e); } catch (javax.xml.transform.TransformerConfigurationException te) { diff --git a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/Y01ErrorMessageFormatter.java b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/Y01ErrorMessageFormatter.java index f74f85a5c01..6fe124f67e6 100644 --- a/core/src/main/java/nl/nn/adapterframework/errormessageformatters/Y01ErrorMessageFormatter.java +++ b/core/src/main/java/nl/nn/adapterframework/errormessageformatters/Y01ErrorMessageFormatter.java @@ -29,7 +29,7 @@ */ public class Y01ErrorMessageFormatter extends ErrorMessageFormatter { - public String format( + public Message format( String message, Throwable t, INamedObject location, @@ -58,6 +58,6 @@ public String format( - return result; + return new Message(result); } } diff --git a/core/src/main/java/nl/nn/adapterframework/http/PushingListenerAdapter.java b/core/src/main/java/nl/nn/adapterframework/http/PushingListenerAdapter.java index 8886bedb6b6..2aed715d313 100644 --- a/core/src/main/java/nl/nn/adapterframework/http/PushingListenerAdapter.java +++ b/core/src/main/java/nl/nn/adapterframework/http/PushingListenerAdapter.java @@ -93,7 +93,7 @@ public Message processRequest(String correlationId, Message rawMessage, Map pa } } - public static String transformXml(Transformer t, Document d) throws TransformerException, IOException { - return transformXml(t, new DOMSource(d)); - } - public static String transformXml(Transformer t, String s) throws TransformerException, IOException, SAXException { return transformXml(t, s, isNamespaceAwareByDefault()); } diff --git a/core/src/main/java/nl/nn/adapterframework/webcontrol/pipes/ShowConfigurationStatus.java b/core/src/main/java/nl/nn/adapterframework/webcontrol/pipes/ShowConfigurationStatus.java index e9a48e8ff48..4407f92749c 100644 --- a/core/src/main/java/nl/nn/adapterframework/webcontrol/pipes/ShowConfigurationStatus.java +++ b/core/src/main/java/nl/nn/adapterframework/webcontrol/pipes/ShowConfigurationStatus.java @@ -392,8 +392,8 @@ private List retrieveErrorStoreCounters(List c private int retrieveErrorStoragesMessageCount(Adapter adapter) { int totalCounter = 0; - for (Receiver receiver: adapter.getReceivers()) { - IMessageBrowser errorStorage = receiver.getErrorStorageBrowser(); + for (Receiver receiver: adapter.getReceivers()) { + IMessageBrowser errorStorage = receiver.getErrorStorageBrowser(); if (errorStorage != null) { int counter; try { @@ -408,7 +408,7 @@ private int retrieveErrorStoragesMessageCount(Adapter adapter) { return totalCounter; } - private int getErrorStorageMessageCountWithTimeout(IMessageBrowser errorStorage, int timeout) throws ListenerException, TimeOutException { + private int getErrorStorageMessageCountWithTimeout(IMessageBrowser errorStorage, int timeout) throws ListenerException, TimeOutException { if (timeout <= 0) { return errorStorage.getMessageCount(); } @@ -510,13 +510,13 @@ private XmlBuilder toAdapterXml(Configuration configurationSelected, Adapter ada } private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter adapter, ShowConfigurationStatusManager showConfigurationStatusManager, ShowConfigurationStatusAdapterManager showConfigurationStatusAdapterManager) { - Iterator recIt = adapter.getReceivers().iterator(); + Iterator> recIt = adapter.getReceivers().iterator(); if (!recIt.hasNext()) { return null; } XmlBuilder receiversXML = new XmlBuilder("receivers"); while (recIt.hasNext()) { - Receiver receiver = recIt.next(); + Receiver receiver = recIt.next(); XmlBuilder receiverXML = new XmlBuilder("receiver"); receiversXML.addSubElement(receiverXML); @@ -554,7 +554,7 @@ private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter a } if (configurationSelected != null) { ISender sender = null; - IListener listener = receiver.getListener(); + IListener listener = receiver.getListener(); receiverXML.addAttribute("listenerClass", ClassUtils.nameOf(listener)); if (listener instanceof HasPhysicalDestination) { String pd = ((HasPhysicalDestination) listener).getPhysicalDestinationName(); @@ -563,7 +563,7 @@ private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter a if (listener instanceof HasSender) { sender = ((HasSender) listener).getSender(); } - IMessageBrowser ts = receiver.getErrorStorageBrowser(); + IMessageBrowser ts = receiver.getErrorStorageBrowser(); receiverXML.addAttribute("hasErrorStorage", "" + (ts != null)); if (ts != null) { try { @@ -663,8 +663,8 @@ private XmlBuilder toReceiversXml(Configuration configurationSelected, Adapter a } - private boolean isAvailable(Receiver receiver) { - IListener listener = receiver.getListener(); + private boolean isAvailable(Receiver receiver) { + IListener listener = receiver.getListener(); boolean isRestListener = (listener instanceof RestListener); boolean isJavaListener = (listener instanceof JavaListener); boolean isWebServiceListener = (listener instanceof WebServiceListener); @@ -721,7 +721,7 @@ private XmlBuilder toPipesXml(Adapter adapter) { if (sender instanceof JdbcSenderBase) { pipeElem.addAttribute("isJdbcSender", "true"); } - IListener listener = msp.getListener(); + IListener listener = msp.getListener(); if (listener != null) { pipeElem.addAttribute("listenerName", listener.getName()); pipeElem.addAttribute("listenerClass", ClassUtils.nameOf(listener)); @@ -730,7 +730,7 @@ private XmlBuilder toPipesXml(Adapter adapter) { pipeElem.addAttribute("listenerDestination", pd); } } - ITransactionalStorage messageLog = msp.getMessageLog(); + ITransactionalStorage messageLog = msp.getMessageLog(); if (messageLog != null) { pipeElem.addAttribute("hasMessageLog", "true"); String messageLogCount; diff --git a/core/src/test/java/nl/nn/adapterframework/http/rest/ApiListenerServletTest.java b/core/src/test/java/nl/nn/adapterframework/http/rest/ApiListenerServletTest.java index f2c1ae9c9f4..e873c12c663 100644 --- a/core/src/test/java/nl/nn/adapterframework/http/rest/ApiListenerServletTest.java +++ b/core/src/test/java/nl/nn/adapterframework/http/rest/ApiListenerServletTest.java @@ -704,10 +704,10 @@ public Message processRequest(IListener origin, String correlationId, M } @Override - public String formatException(String extrainfo, String correlationId, Message message, Throwable t) { + public Message formatException(String extrainfo, String correlationId, Message message, Throwable t) { t.printStackTrace(); - return t.getMessage(); + return new Message(t.getMessage()); } } diff --git a/larva/src/main/java/nl/nn/adapterframework/testtool/ListenerMessageHandler.java b/larva/src/main/java/nl/nn/adapterframework/testtool/ListenerMessageHandler.java index 857d42f1c85..d143a336c34 100644 --- a/larva/src/main/java/nl/nn/adapterframework/testtool/ListenerMessageHandler.java +++ b/larva/src/main/java/nl/nn/adapterframework/testtool/ListenerMessageHandler.java @@ -149,7 +149,7 @@ public Message processRequest(IListener origin, String correlationId, Object raw } @Override - public String formatException(String origin, String arg1, Message arg2, Throwable arg3) { + public Message formatException(String origin, String arg1, Message arg2, Throwable arg3) { log.error("formatException(String arg0, String arg1, String arg2, Throwable arg3) not implemented"); return null; }