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);
}
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;
}
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);
}
}
}
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);
}
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);
}
}
Aggregations