use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class PdfPipeTest method multiThreadedMailWithWordAttachment.
@Test
public void multiThreadedMailWithWordAttachment() throws Exception {
pipe.setName("multiThreadedmailWithWordAttachment");
pipe.setAction(DocumentAction.CONVERT);
pipe.registerForward(new PipeForward("success", "dummy"));
pipe.configure();
pipe.start();
PipeLineSession session = new PipeLineSession();
List<URL> inputs = new ArrayList<URL>();
for (int i = 0; i < 5; i++) {
inputs.add(TestFileUtils.getTestFileURL("/PdfPipe/MailWithAttachments/mailWithWordAttachment.msg"));
}
String expected = TestFileUtils.getTestFileMessage("/PdfPipe/xml-results/mailWithWordAttachment.xml").asString();
inputs.parallelStream().forEach(item -> {
try {
PipeRunResult prr = pipe.doPipe(Message.asMessage(new File(item.toURI())), session);
Message result = prr.getResult();
MatchUtils.assertXmlEquals("Conversion XML does not match", applyIgnores(result.asString()), applyIgnores(expected), true);
} catch (Exception e) {
fail("Failed to execute test " + e.getMessage());
}
});
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class PdfPipeTest method attachFileToMainDoc.
@Test
public void attachFileToMainDoc() throws Exception {
pipe.setAction(DocumentAction.COMBINE);
pipe.setMainDocumentSessionKey("mainDoc");
pipe.setFilenameToAttachSessionKey("attachedFilename");
Message mainDoc = TestFileUtils.getNonRepeatableTestFileMessage("/PdfPipe/combine/maindoc.pdf");
session.put(pipe.getMainDocumentSessionKey(), mainDoc);
session.put(pipe.getFilenameToAttachSessionKey(), "attachedFile");
Message fileToAttachMainDoc = TestFileUtils.getNonRepeatableTestFileMessage("/PdfPipe/combine/filetobeattached.pdf");
PipeRunResult prr = doPipe(pipe, fileToAttachMainDoc, session);
Message result = prr.getResult();
Path resultingFile = Files.createTempFile("PdfPipeTest", ".pdf");
Files.copy(result.asInputStream(), resultingFile, StandardCopyOption.REPLACE_EXISTING);
String expectedFilePath = new File(TestFileUtils.getTestFileURL("/PdfPipe/combine/combined.pdf").toURI()).getCanonicalPath();
// comparison
PDFUtil pdfUtil = new PDFUtil();
assertTrue(pdfUtil.compare(expectedFilePath, resultingFile.toFile().getCanonicalPath()));
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class CmisSender method sendMessageForActionCreate.
private Message sendMessageForActionCreate(Session cmisSession, Message message, PipeLineSession session, ParameterValueList pvl) throws SenderException {
String fileName = null;
try {
fileName = session.getMessage(getParameterOverriddenAttributeValue(pvl, "filenameSessionKey", getFilenameSessionKey())).asString();
} catch (IOException e) {
throw new SenderException("Unable to get filename from session key [" + getFilenameSessionKey() + "]", e);
}
String mediaType;
Map<String, Object> props = new HashMap<String, Object>();
Element cmisElement;
try {
if (XmlUtils.isWellFormed(message, "cmis")) {
cmisElement = XmlUtils.buildElement(message);
} else {
cmisElement = XmlUtils.buildElement("<cmis/>");
}
String objectTypeId = XmlUtils.getChildTagAsString(cmisElement, "objectTypeId");
if (StringUtils.isNotEmpty(objectTypeId)) {
props.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
} else {
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
}
String name = XmlUtils.getChildTagAsString(cmisElement, "name");
if (StringUtils.isEmpty(fileName)) {
fileName = XmlUtils.getChildTagAsString(cmisElement, "fileName");
}
mediaType = XmlUtils.getChildTagAsString(cmisElement, "mediaType");
if (StringUtils.isNotEmpty(name)) {
props.put(PropertyIds.NAME, name);
} else if (StringUtils.isNotEmpty(fileName)) {
props.put(PropertyIds.NAME, fileName);
} else {
props.put(PropertyIds.NAME, "[unknown]");
}
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
if (propertiesElement != null) {
processProperties(propertiesElement, props);
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "exception parsing [" + message + "]", e);
}
if (StringUtils.isEmpty(mediaType)) {
mediaType = getDefaultMediaType();
}
ContentStream contentStream;
try {
Message inputFromSessionKey = session.getMessage(getParameterOverriddenAttributeValue(pvl, "fileSessionKey", getFileSessionKey()));
if (convert2Base64 && inputFromSessionKey.asObject() instanceof String) {
inputFromSessionKey = new Message(Base64.decodeBase64(inputFromSessionKey.asByteArray()));
}
long fileLength = inputFromSessionKey.size();
contentStream = cmisSession.getObjectFactory().createContentStream(fileName, fileLength, mediaType, inputFromSessionKey.asInputStream());
} catch (IOException e) {
throw new SenderException(e);
}
if (isUseRootFolder()) {
Folder folder = cmisSession.getRootFolder();
Document document = folder.createDocument(props, contentStream, VersioningState.NONE);
log.debug(getLogPrefix() + "created new document [ " + document.getId() + "]");
return new Message(document.getId());
}
ObjectId objectId = cmisSession.createDocument(props, null, contentStream, VersioningState.NONE);
log.debug(getLogPrefix() + "created new document [ " + objectId.getId() + "]");
return new Message(objectId.getId());
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class CmisSender method sendMessageForActionGet.
private Message sendMessageForActionGet(Session cmisSession, Message message, PipeLineSession session, ParameterValueList pvl) throws SenderException, TimeoutException {
if (Message.isEmpty(message)) {
throw new SenderException(getLogPrefix() + "input string cannot be empty but must contain a documentId");
}
CmisObject object = null;
try {
object = getCmisObject(cmisSession, message);
} catch (CmisObjectNotFoundException e) {
if (StringUtils.isNotEmpty(getResultOnNotFound())) {
log.info(getLogPrefix() + "document with id [" + message + "] not found", e);
return new Message(getResultOnNotFound());
}
throw new SenderException(e);
}
Document document = (Document) object;
try {
boolean getProperties = isGetProperties();
boolean getDocumentContent = isGetDocumentContent();
if (pvl != null) {
if (pvl.contains("getProperties"))
getProperties = pvl.get("getProperties").asBooleanValue(isGetProperties());
if (pvl.contains("getDocumentContent"))
getDocumentContent = pvl.get("getDocumentContent").asBooleanValue(isGetDocumentContent());
}
if (isStreamResultToServlet()) {
HttpServletResponse response = (HttpServletResponse) session.get(PipeLineSession.HTTP_RESPONSE_KEY);
ContentStream contentStream = document.getContentStream();
InputStream inputStream = contentStream.getStream();
String contentType = contentStream.getMimeType();
if (StringUtils.isNotEmpty(contentType)) {
log.debug(getLogPrefix() + "setting response Content-Type header [" + contentType + "]");
response.setHeader("Content-Type", contentType);
}
String contentDisposition = "attachment; filename=\"" + contentStream.getFileName() + "\"";
log.debug(getLogPrefix() + "setting response Content-Disposition header [" + contentDisposition + "]");
response.setHeader("Content-Disposition", contentDisposition);
OutputStream outputStream;
outputStream = response.getOutputStream();
Misc.streamToStream(inputStream, outputStream);
log.debug(getLogPrefix() + "copied document content input stream [" + inputStream + "] to output stream [" + outputStream + "]");
return Message.nullMessage();
} else if (getProperties) {
if (getDocumentContent) {
ContentStream contentStream = document.getContentStream();
InputStream inputStream = contentStream.getStream();
if (convert2Base64) {
byte[] bytes = Misc.streamToBytes(inputStream);
session.put(getFileSessionKey(), Base64.encodeBase64String(bytes));
} else {
session.put(getFileSessionKey(), inputStream);
}
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
XmlBuilder propertiesXml = new XmlBuilder("properties");
for (Iterator<Property<?>> it = document.getProperties().iterator(); it.hasNext(); ) {
Property<?> property = it.next();
propertiesXml.addSubElement(CmisUtils.getPropertyXml(property));
}
cmisXml.addSubElement(propertiesXml);
return new Message(cmisXml.toXML());
} else {
ContentStream contentStream = document.getContentStream();
InputStream inputStream = contentStream.getStream();
if (StringUtils.isNotEmpty(getFileSessionKey())) {
if (convert2Base64) {
byte[] bytes = Misc.streamToBytes(inputStream);
session.put(getFileSessionKey(), Base64.encodeBase64String(bytes));
} else {
session.put(getFileSessionKey(), inputStream);
}
return Message.nullMessage();
}
session.put("contentStream:MimeType", contentStream.getMimeType());
session.put("contentStream:Filename", contentStream.getFileName());
MessageContext context = new MessageContext();
context.withName(contentStream.getFileName()).withMimeType(contentStream.getMimeType());
return new Message(inputStream, context);
}
} catch (IOException e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.
the class CmisSender method sendMessageForActionFind.
private Message sendMessageForActionFind(Session cmisSession, Message message) throws SenderException, TimeoutException {
Element queryElement = null;
try {
if (XmlUtils.isWellFormed(message, "query")) {
queryElement = XmlUtils.buildElement(message);
} else {
queryElement = XmlUtils.buildElement("<query/>");
}
} catch (DomBuilderException e) {
throw new SenderException(e);
}
String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
OperationContext operationContext = cmisSession.createOperationContext();
if (StringUtils.isNotEmpty(maxItems)) {
operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
}
boolean sav = false;
if (StringUtils.isNotEmpty(searchAllVersions)) {
sav = Boolean.parseBoolean(searchAllVersions);
}
if (StringUtils.isNotEmpty(includeAllowableActions)) {
operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
}
XmlBuilder cmisXml = new XmlBuilder("cmis");
ItemIterable<QueryResult> q = cmisSession.query(statement, sav, operationContext);
if (q == null) {
cmisXml.addAttribute("totalNumItems", 0);
} else {
if (StringUtils.isNotEmpty(skipCount)) {
long sc = Long.parseLong(skipCount);
q = q.skipTo(sc);
}
if (StringUtils.isNotEmpty(maxItems)) {
q = q.getPage();
}
XmlBuilder rowsetXml = new XmlBuilder("rowset");
for (QueryResult qResult : q) {
XmlBuilder rowXml = new XmlBuilder("row");
for (PropertyData<?> property : qResult.getProperties()) {
rowXml.addSubElement(CmisUtils.getPropertyXml(property));
}
rowsetXml.addSubElement(rowXml);
}
cmisXml.addAttribute("totalNumItems", q.getTotalNumItems());
cmisXml.addSubElement(rowsetXml);
}
return new Message(cmisXml.toXML());
}
Aggregations