use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class BisUtils method prepareMessageHeader.
public String prepareMessageHeader(String originalMessageText, boolean messageHeaderInSoapBody, String conversationId, String externalRefToMessageId) throws DomBuilderException, IOException, TransformerException {
XmlBuilder messageHeaderElement = new XmlBuilder("MessageHeader");
messageHeaderElement.addAttribute("xmlns", "http://www.ing.com/CSP/XSD/General/Message_2");
XmlBuilder fromElement = new XmlBuilder("From");
XmlBuilder idElement = new XmlBuilder("Id");
idElement.setValue(AppConstants.getInstance().getProperty("instance.name", ""));
fromElement.addSubElement(idElement);
messageHeaderElement.addSubElement(fromElement);
XmlBuilder headerFieldsElement = new XmlBuilder("HeaderFields");
XmlBuilder conversationIdElement = new XmlBuilder("ConversationId");
if (originalMessageText == null) {
conversationIdElement.setValue(conversationId);
} else {
if (messageHeaderInSoapBody) {
if (oldMessageHeaderConversationIdTp != null) {
conversationIdElement.setValue(oldMessageHeaderConversationIdTp.transform(originalMessageText, null, true));
}
} else {
if (messageHeaderConversationIdTp != null) {
conversationIdElement.setValue(messageHeaderConversationIdTp.transform(originalMessageText, null, true));
}
}
}
headerFieldsElement.addSubElement(conversationIdElement);
XmlBuilder messageIdElement = new XmlBuilder("MessageId");
messageIdElement.setValue(Misc.getHostname() + "_" + Misc.createSimpleUUID());
headerFieldsElement.addSubElement(messageIdElement);
XmlBuilder externalRefToMessageIdElement = new XmlBuilder("ExternalRefToMessageId");
if (originalMessageText == null) {
externalRefToMessageIdElement.setValue(externalRefToMessageId);
} else {
if (messageHeaderInSoapBody) {
if (oldMessageHeaderExternalRefToMessageIdTp != null) {
externalRefToMessageIdElement.setValue(oldMessageHeaderExternalRefToMessageIdTp.transform(originalMessageText, null, true));
}
} else {
if (messageHeaderExternalRefToMessageIdTp != null) {
externalRefToMessageIdElement.setValue(messageHeaderExternalRefToMessageIdTp.transform(originalMessageText, null, true));
}
}
}
headerFieldsElement.addSubElement(externalRefToMessageIdElement);
XmlBuilder timestampElement = new XmlBuilder("Timestamp");
timestampElement.setValue(DateUtils.format(new Date(), "yyyy-MM-dd'T'HH:mm:ss"));
headerFieldsElement.addSubElement(timestampElement);
messageHeaderElement.addSubElement(headerFieldsElement);
return messageHeaderElement.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class BisUtils method prepareResult.
public String prepareResult(String errorCode, String errorText, String serviceName, String actionName, String detailText) throws DomBuilderException, IOException, TransformerException {
XmlBuilder resultElement = new XmlBuilder("Result");
resultElement.addAttribute("xmlns", "http://www.ing.com/CSP/XSD/General/Message_2");
XmlBuilder statusElement = new XmlBuilder("Status");
if (errorCode == null) {
statusElement.setValue("OK");
} else {
statusElement.setValue("ERROR");
}
resultElement.addSubElement(statusElement);
if (errorCode != null) {
XmlBuilder errorListElement = new XmlBuilder("ErrorList");
XmlBuilder errorElement = new XmlBuilder("Error");
XmlBuilder codeElement = new XmlBuilder("Code");
codeElement.setValue(errorCode);
errorElement.addSubElement(codeElement);
XmlBuilder reasonElement = new XmlBuilder("Reason");
reasonElement.setCdataValue(errorText);
errorElement.addSubElement(reasonElement);
XmlBuilder serviceElement = new XmlBuilder("Service");
XmlBuilder serviceNameElement = new XmlBuilder("Name");
serviceNameElement.setValue(serviceName);
serviceElement.addSubElement(serviceNameElement);
XmlBuilder serviceContextElement = new XmlBuilder("Context");
serviceContextElement.setValue("1");
serviceElement.addSubElement(serviceContextElement);
XmlBuilder actionElement = new XmlBuilder("Action");
XmlBuilder actionNameElement = new XmlBuilder("Name");
actionNameElement.setValue(actionName);
actionElement.addSubElement(actionNameElement);
XmlBuilder actionVersionElement = new XmlBuilder("Version");
actionVersionElement.setValue("1");
actionElement.addSubElement(actionVersionElement);
serviceElement.addSubElement(actionElement);
errorElement.addSubElement(serviceElement);
XmlBuilder detailListElement = new XmlBuilder("DetailList");
XmlBuilder detailElement = new XmlBuilder("Detail");
XmlBuilder detailCodeElement = new XmlBuilder("Code");
detailElement.addSubElement(detailCodeElement);
XmlBuilder detailTextElement = new XmlBuilder("Text");
detailTextElement.setCdataValue(detailText);
detailElement.addSubElement(detailTextElement);
detailListElement.addSubElement(detailElement);
errorElement.addSubElement(detailListElement);
errorListElement.addSubElement(errorElement);
resultElement.addSubElement(errorListElement);
}
return resultElement.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class BisWrapperPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String result;
try {
if ("wrap".equalsIgnoreCase(getDirection())) {
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(input.toString(), null, true);
} else {
payload = input.toString();
}
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(payload, isBisMessageHeaderInSoapBody() ? null : messageHeader);
} else {
String body = unwrapMessage(input.toString());
if (StringUtils.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(input.toString(), null, true);
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(input.toString(), null, true);
if (Boolean.valueOf(bisError).booleanValue()) {
throw new PipeRunException(this, getLogPrefix(session) + "bisErrorXPath [" + bisErrorXe + "] returns true");
}
}
if (bodyMessageTp != null) {
result = bodyMessageTp.transform(input.toString(), null, true);
} else {
result = body;
}
if (removeOutputNamespacesTp != null) {
result = removeOutputNamespacesTp.transform(result, null, true);
}
}
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
}
return new PipeRunResult(getForward(), result);
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class BisWrapperPipe method prepareMessageHeader.
private String prepareMessageHeader(String originalMessageHeader, String conversationId, String externalRefToMessageId) throws DomBuilderException, IOException, TransformerException {
XmlBuilder messageHeaderElement = new XmlBuilder("MessageHeader");
messageHeaderElement.addAttribute("xmlns", "http://www.ing.com/CSP/XSD/General/Message_2");
XmlBuilder fromElement = new XmlBuilder("From");
XmlBuilder idElement = new XmlBuilder("Id");
idElement.setValue(AppConstants.getInstance().getProperty("instance.name", ""));
fromElement.addSubElement(idElement);
messageHeaderElement.addSubElement(fromElement);
XmlBuilder headerFieldsElement = new XmlBuilder("HeaderFields");
XmlBuilder conversationIdElement = new XmlBuilder("ConversationId");
if (originalMessageHeader == null) {
conversationIdElement.setValue(conversationId);
} else {
if (bisMessageHeaderConversationIdTp != null) {
conversationIdElement.setValue(bisMessageHeaderConversationIdTp.transform(originalMessageHeader, null, true));
}
}
headerFieldsElement.addSubElement(conversationIdElement);
XmlBuilder messageIdElement = new XmlBuilder("MessageId");
messageIdElement.setValue(Misc.getHostname() + "_" + Misc.createSimpleUUID());
headerFieldsElement.addSubElement(messageIdElement);
XmlBuilder externalRefToMessageIdElement = new XmlBuilder("ExternalRefToMessageId");
if (originalMessageHeader == null) {
externalRefToMessageIdElement.setValue(externalRefToMessageId);
} else {
if (bisMessageHeaderExternalRefToMessageIdTp != null) {
externalRefToMessageIdElement.setValue(bisMessageHeaderExternalRefToMessageIdTp.transform(originalMessageHeader, null, true));
}
}
headerFieldsElement.addSubElement(externalRefToMessageIdElement);
XmlBuilder timestampElement = new XmlBuilder("Timestamp");
timestampElement.setValue(DateUtils.format(new Date(), "yyyy-MM-dd'T'HH:mm:ss"));
headerFieldsElement.addSubElement(timestampElement);
messageHeaderElement.addSubElement(headerFieldsElement);
return messageHeaderElement.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class FxfWrapperPipe method doPipe.
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
if ("wrap".equalsIgnoreCase(getDirection())) {
XmlBuilder xmlStartTransfer_Action = new XmlBuilder("StartTransfer_Action");
xmlStartTransfer_Action.addAttribute("xmlns", "http://nn.nl/XSD/Infrastructure/Transfer/FileTransfer/1/StartTransfer/" + retrieveStartTransferVersion());
XmlBuilder xmlTransferDetails = new XmlBuilder("TransferDetails");
xmlStartTransfer_Action.addSubElement(xmlTransferDetails);
XmlBuilder xmlSenderApplication = new XmlBuilder("SenderApplication");
xmlSenderApplication.setValue(instanceName);
xmlTransferDetails.addSubElement(xmlSenderApplication);
XmlBuilder xmlRecipientApplication = new XmlBuilder("RecipientApplication");
xmlTransferDetails.addSubElement(xmlRecipientApplication);
XmlBuilder xmlFilename = new XmlBuilder("Filename");
if (input != null) {
String filename = input.toString();
if (isTransformFilename()) {
String filenameOnIufState = "/opt/data/FXF/" + instanceNameLowerCase + "/" + getFlowId() + "/out/" + new File(filename).getName();
xmlFilename.setValue(filenameOnIufState);
} else {
xmlFilename.setValue(filename);
}
}
xmlTransferDetails.addSubElement(xmlFilename);
XmlBuilder xmlTransferFlowId = new XmlBuilder("TransferFlowId");
String transferFlowId = getFlowId().substring(0, 2) + environment + getFlowId().substring(3);
xmlTransferFlowId.setValue(transferFlowId);
xmlTransferDetails.addSubElement(xmlTransferFlowId);
return super.doPipe(xmlStartTransfer_Action.toXML(), session);
} else {
String soapBody = (String) super.doPipe(input, session).getResult();
session.put(getSoapBodySessionKey(), soapBody);
String transferFlowId;
String clientFilename;
try {
transferFlowId = transferFlowIdTp.transform(soapBody, null);
session.put(getTransferFlowIdSessionKey(), transferFlowId);
clientFilename = clientFilenameTp.transform(soapBody, null);
session.put(getClientFilenameSessionKey(), clientFilename);
} catch (Throwable t) {
throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
}
String flowId = transferFlowId.substring(0, 2) + "X" + transferFlowId.substring(3);
session.put(getFlowIdSessionKey(), flowId);
session.put(getFxfDirSessionKey(), fxfDir);
// Transform the filename as it is known locally on the IUF state
// machine to the filename as know on the application server (which
// has a mount to the IUF state machine).
String fxfFile = fxfDir + File.separator + flowId + File.separator + "in" + File.separator + new File(clientFilename).getName();
session.put(getFxfFileSessionKey(), fxfFile);
return new PipeRunResult(getForward(), fxfFile);
}
}
Aggregations