Search in sources :

Example 26 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class BisWrapperPipe method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    Message result;
    try {
        if (getDirection() == Direction.WRAP) {
            String originalBisMessageHeader = (String) session.get(getBisMessageHeaderSessionKey());
            String bisConversationId = null;
            String bisExternalRefToMessageId = null;
            if (originalBisMessageHeader == null) {
                if (StringUtils.isNotEmpty(getBisConversationIdSessionKey())) {
                    bisConversationId = (String) session.get(getBisConversationIdSessionKey());
                }
                if (StringUtils.isNotEmpty(getBisExternalRefToMessageIdSessionKey())) {
                    bisExternalRefToMessageId = (String) session.get(getBisExternalRefToMessageIdSessionKey());
                }
            }
            String messageHeader = prepareMessageHeader(originalBisMessageHeader, bisConversationId, bisExternalRefToMessageId);
            String bisErrorCode = null;
            if (StringUtils.isNotEmpty(getBisErrorCodeSessionKey())) {
                bisErrorCode = (String) session.get(getBisErrorCodeSessionKey());
            }
            String bisErrorText = null;
            String bisDetailText = null;
            if (bisErrorCode != null) {
                if (StringUtils.isNotEmpty(getBisErrorTextSessionKey())) {
                    bisErrorText = (String) session.get(getBisErrorTextSessionKey());
                }
                if (bisErrorText == null) {
                    bisErrorText = errorCodeToText(bisErrorCode);
                }
                if (StringUtils.isNotEmpty(getBisErrorReasonSessionKey())) {
                    bisDetailText = (String) session.get(getBisErrorReasonSessionKey());
                }
                if (isOmitResult()) {
                    throw new PipeRunException(this, getLogPrefix(session) + "bisError occured: errorCode [" + bisErrorCode + "], errorText [" + bisErrorText + "]");
                }
            }
            String bisResult = prepareResult(bisErrorCode, bisErrorText, getBisServiceName(), getBisActionName(), bisDetailText);
            String payload;
            if (bisErrorCode == null || StringUtils.isEmpty(getOutputRoot())) {
                if (addOutputNamespaceTp != null) {
                    payload = addOutputNamespaceTp.transform(message.asSource());
                } else {
                    payload = message.asString();
                }
                payload = prepareReply(payload, isBisMessageHeaderInSoapBody() ? messageHeader : null, bisResult, isBisResultInPayload());
            } else {
                XmlBuilder outputElement = new XmlBuilder(getOutputRoot());
                if (StringUtils.isNotEmpty(getOutputNamespace())) {
                    outputElement.addAttribute("xmlns", getOutputNamespace());
                }
                payload = prepareReply(outputElement.toXML(), isBisMessageHeaderInSoapBody() ? messageHeader : null, bisResult, isBisResultInPayload());
            }
            result = wrapMessage(new Message(payload), isBisMessageHeaderInSoapBody() ? null : messageHeader, session);
        } else {
            Message body = unwrapMessage(message, session);
            if (Message.isEmpty(body)) {
                throw new PipeRunException(this, getLogPrefix(session) + "SOAP body is empty or message is not a SOAP message");
            }
            if (bisMessageHeaderTp != null) {
                String messageHeader = bisMessageHeaderTp.transform(message.asSource());
                if (messageHeader != null) {
                    session.put(getBisMessageHeaderSessionKey(), messageHeader);
                    log.debug(getLogPrefix(session) + "stored [" + messageHeader + "] in pipeLineSession under key [" + getBisMessageHeaderSessionKey() + "]");
                }
            }
            if (bisErrorTp != null) {
                String bisError = bisErrorTp.transform(message.asSource());
                if (Boolean.valueOf(bisError).booleanValue()) {
                    throw new PipeRunException(this, getLogPrefix(session) + "bisErrorXPath [" + bisErrorXe + "] returns true");
                }
            }
            if (bodyMessageTp != null) {
                result = new Message(bodyMessageTp.transform(message.asSource()));
            } else {
                result = body;
            }
            if (removeOutputNamespacesTp != null) {
                result = new Message(removeOutputNamespacesTp.transform(result.asSource()));
            }
        }
    } catch (Throwable t) {
        throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
    }
    return new PipeRunResult(getSuccessForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) PipeRunException(nl.nn.adapterframework.core.PipeRunException) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 27 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class XslErrorMessageFormatter method format.

@Override
public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) {
    Message result = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime);
    if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
        try {
            Transformer errorTransformer;
            if (StringUtils.isNotEmpty(getStyleSheet())) {
                URL url = ClassUtils.getResourceURL(this, styleSheet);
                errorTransformer = XmlUtils.createTransformer(url);
            } else {
                String xpath = getXpathExpression();
                // if (StringUtils.isEmpty(xpath)) {
                // xpath="/errorMessage/@message";
                // }
                errorTransformer = XmlUtils.createTransformer(XmlUtils.createXPathEvaluatorSource(xpath));
            }
            ParameterList params = getParameterList();
            if (params != null) {
                try {
                    params.configure();
                } catch (ConfigurationException e) {
                    log.error("exception while configuring parameters", e);
                }
                Map<String, Object> parametervalues = null;
                try {
                    parametervalues = params.getValues(new Message(errorMessage), new PipeLineSession()).getValueMap();
                } catch (ParameterException e) {
                    log.error("got exception extracting parameters", e);
                }
                XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
            }
            result = new Message(XmlUtils.transformXml(errorTransformer, result.asSource()));
        } catch (IOException e) {
            log.error(" cannot retrieve [" + styleSheet + "]", e);
        } catch (javax.xml.transform.TransformerConfigurationException te) {
            log.error("got error creating transformer from file [" + styleSheet + "]", te);
        } catch (Exception tfe) {
            log.error("could not transform [" + result + "] using stylesheet [" + styleSheet + "]", tfe);
        }
    } else {
        log.warn("no stylesheet defined for XslErrorMessageFormatter");
    }
    return result;
}
Also used : Transformer(javax.xml.transform.Transformer) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) INamedObject(nl.nn.adapterframework.core.INamedObject) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 28 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class PipeLineSession method close.

@Override
public void close() {
    log.debug("Closing PipeLineSession");
    while (!closeables.isEmpty()) {
        Iterator<Entry<Message, String>> it = closeables.entrySet().iterator();
        Entry<Message, String> entry = it.next();
        Message messageToClose = entry.getKey();
        try {
            log.warn("messageId [" + getMessageId() + "] auto closing resource " + entry.getValue());
            messageToClose.close();
        } catch (Exception e) {
            log.warn("Exception closing resource", e);
        } finally {
            closeables.remove(messageToClose);
        }
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 29 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class PipeLineSession method scheduleCloseOnSessionExit.

public void scheduleCloseOnSessionExit(AutoCloseable resource, String requester) {
    // create a dummy Message, to be able to schedule the resource for close on exit of session
    Message resourceMessage = new Message(new StringReader("dummy")) {

        @Override
        public void close() throws Exception {
            resource.close();
        }
    };
    scheduleCloseOnSessionExit(resourceMessage, ClassUtils.nameOf(resource) + " of " + requester);
}
Also used : Message(nl.nn.adapterframework.stream.Message) StringReader(java.io.StringReader)

Example 30 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class ExchangeFileSystem method getMimeContent.

@Override
public Message getMimeContent(EmailMessage emailMessage) throws FileSystemException {
    try {
        emailMessage.load(new PropertySet(ItemSchema.MimeContent));
        MimeContent mc = emailMessage.getMimeContent();
        return new Message(mc.getContent());
    } catch (Exception e) {
        throw new FileSystemException("Could not get MimeContent", e);
    }
}
Also used : ResponseMessage(microsoft.exchange.webservices.data.core.service.response.ResponseMessage) EmailMessage(microsoft.exchange.webservices.data.core.service.item.EmailMessage) Message(nl.nn.adapterframework.stream.Message) MimeContent(microsoft.exchange.webservices.data.property.complex.MimeContent) PropertySet(microsoft.exchange.webservices.data.core.PropertySet) URISyntaxException(java.net.URISyntaxException) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ServiceVersionException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceVersionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceResponseException(microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

Message (nl.nn.adapterframework.stream.Message)598 Test (org.junit.Test)385 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)220 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)114 IOException (java.io.IOException)112 SenderException (nl.nn.adapterframework.core.SenderException)97 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)54 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)54 Parameter (nl.nn.adapterframework.parameters.Parameter)52 PipeForward (nl.nn.adapterframework.core.PipeForward)41 Date (java.util.Date)37 TimeoutException (nl.nn.adapterframework.core.TimeoutException)31 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)31 PipeRunException (nl.nn.adapterframework.core.PipeRunException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)29 InputStream (java.io.InputStream)29 ParameterList (nl.nn.adapterframework.parameters.ParameterList)28 ListenerException (nl.nn.adapterframework.core.ListenerException)27 ParameterException (nl.nn.adapterframework.core.ParameterException)25 SAXException (org.xml.sax.SAXException)19