use of nl.nn.adapterframework.stream.MessageContext 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.MessageContext in project iaf by ibissource.
the class JMSFacade method getContext.
public MessageContext getContext(javax.jms.Message message) throws JMSException {
MessageContext result = new MessageContext();
result.withName(message.getJMSMessageID());
result.withModificationTime(message.getJMSTimestamp());
Enumeration<String> names = message.getPropertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
result.put(name, message.getObjectProperty(name));
}
return result;
}
use of nl.nn.adapterframework.stream.MessageContext in project iaf by ibissource.
the class MessageUtils method getContext.
/**
* Fetch metadata from the {@link HttpServletRequest} such as Content-Length, Content-Type (mimetype + charset)
*/
public static MessageContext getContext(HttpServletRequest request) {
MessageContext result = new MessageContext();
result.withCharset(request.getCharacterEncoding());
int contentLength = request.getContentLength();
if (contentLength >= 0) {
result.withSize(contentLength);
}
String contentType = request.getContentType();
if (StringUtils.isNotEmpty(contentType)) {
try {
ContentType parsedContentType = ContentType.parse(contentType);
if (parsedContentType.getMimeType() != null) {
result.withMimeType(parsedContentType.getMimeType());
}
Charset parsedCharset = parsedContentType.getCharset();
if (parsedCharset != null) {
result.withCharset(parsedCharset.displayName());
}
} catch (Exception e) {
// For now just log when we cannot parse, perhaps we should abort the request?
LOG.warn("unable to parse charset from contentType [{}]", contentType, e);
}
}
Enumeration<String> names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
result.put(name, request.getHeader(name));
}
return result;
}
use of nl.nn.adapterframework.stream.MessageContext in project iaf by ibissource.
the class ParameterTest method testContextKeyWithSessionKeyAndXPath.
@Test
public void testContextKeyWithSessionKeyAndXPath() throws ConfigurationException, ParameterException {
Parameter p = new Parameter();
p.setName("dummy");
p.setSessionKey("fakeSessionKey");
p.setContextKey("fakeContextKey");
p.setXpathExpression("count(root/a)");
p.configure();
Message input = new Message("fakeMessage1", new MessageContext().with("fakeContextKey", "<root><a/><a/></root>"));
Message sessionValue = new Message("fakeMessage2", new MessageContext().with("fakeContextKey", "<root><a/><a/><a/></root>"));
PipeLineSession session = new PipeLineSession();
session.put("fakeSessionKey", sessionValue);
ParameterValueList alreadyResolvedParameters = new ParameterValueList();
assertEquals("3", p.getValue(alreadyResolvedParameters, input, session, false));
}
use of nl.nn.adapterframework.stream.MessageContext in project iaf by ibissource.
the class ParameterTest method testContextKeyWithSessionKey.
@Test
public void testContextKeyWithSessionKey() throws ConfigurationException, ParameterException {
Parameter p = new Parameter();
p.setName("dummy");
p.setSessionKey("fakeSessionKey");
p.setContextKey("fakeContextKey");
p.configure();
Message input = new Message("fakeMessage1", new MessageContext().with("fakeContextKey", "fakeContextValue1"));
Message sessionValue = new Message("fakeMessage2", new MessageContext().with("fakeContextKey", "fakeContextValue2"));
PipeLineSession session = new PipeLineSession();
session.put("fakeSessionKey", sessionValue);
ParameterValueList alreadyResolvedParameters = new ParameterValueList();
assertEquals("fakeContextValue2", p.getValue(alreadyResolvedParameters, input, session, false));
}
Aggregations