use of javax.activation.DataSource in project nhin-d by DirectProject.
the class DocumentRepositoryAbstract method provideAndRegisterDocumentSet.
/**
* Handle an incoming ProvideAndRegisterDocumentSetRequestType object and
* transform to XDM or relay to another XDR endponit.
*
* @param prdst
* The incoming ProvideAndRegisterDocumentSetRequestType object
* @return a RegistryResponseType object
* @throws Exception
*/
protected RegistryResponseType provideAndRegisterDocumentSet(ProvideAndRegisterDocumentSetRequestType prdst, SafeThreadData threadData) throws Exception {
RegistryResponseType resp = null;
try {
@SuppressWarnings("unused") InitialContext ctx = new InitialContext();
DirectDocuments documents = xdsDirectDocumentsTransformer.transform(prdst);
List<String> forwards = new ArrayList<String>();
// Get endpoints (first check direct:to header, then go to intendedRecipients)
if (StringUtils.isNotBlank(threadData.getDirectTo()))
forwards = Arrays.asList((new URI(threadData.getDirectTo()).getSchemeSpecificPart()));
else {
forwards = ParserHL7.parseDirectRecipients(documents);
}
// messageId = UUID.randomUUID().toString(); remove this , its is not righ,
//we should keep the message id of the original message for a lot of reasons vpl
// TODO patID and subsetId for atn
String patId = threadData.getMessageId();
String subsetId = threadData.getMessageId();
getAuditMessageGenerator().provideAndRegisterAudit(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
// Send to SMTP endpoints
if (getResolver().hasSmtpEndpoints(forwards)) {
String replyEmail;
// Get a reply address (first check direct:from header, then go to authorPerson)
if (StringUtils.isNotBlank(threadData.getDirectFrom()))
replyEmail = (new URI(threadData.getDirectFrom())).getSchemeSpecificPart();
else {
// replyEmail = documents.getSubmissionSet().getAuthorPerson();
replyEmail = documents.getSubmissionSet().getAuthorTelecommunication();
// replyEmail = StringUtils.splitPreserveAllTokens(replyEmail, "^")[0];
replyEmail = ParserHL7.parseXTN(replyEmail);
replyEmail = StringUtils.contains(replyEmail, "@") ? replyEmail : "nhindirect@nhindirect.org";
}
LOGGER.info("SENDING EMAIL TO " + getResolver().getSmtpEndpoints(forwards) + " with message id " + threadData.getMessageId());
// Construct message wrapper
DirectMessage message = new DirectMessage(replyEmail, getResolver().getSmtpEndpoints(forwards));
message.setSubject("XD* Originated Message");
message.setBody("Please find the attached XDM file.");
message.setDirectDocuments(documents);
// Send mail
MailClient mailClient = getMailClient();
String fileName = threadData.getMessageId().replaceAll("urn:uuid:", "");
mailClient.mail(message, fileName, threadData.getSuffix());
getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
}
// Send to XD endpoints
for (String reqEndpoint : getResolver().getXdEndpoints(forwards)) {
String endpointUrl = getResolver().resolve(reqEndpoint);
String to = StringUtils.remove(endpointUrl, "?wsdl");
threadData.setTo(to);
threadData.setDirectTo(to);
threadData.save();
List<Document> docs = prdst.getDocument();
// Make a copy of the original documents
List<Document> originalDocs = new ArrayList<Document>();
for (Document d : docs) originalDocs.add(d);
// Clear document list
docs.clear();
// Re-add documents
for (Document d : originalDocs) {
Document doc = new Document();
doc.setId(d.getId());
DataHandler dh = d.getValue();
ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
dh.writeTo(buffOS);
byte[] buff = buffOS.toByteArray();
DataSource source = new ByteArrayDataSource(buff, documents.getDocument(d.getId()).getMetadata().getMimeType());
DataHandler dhnew = new DataHandler(source);
doc.setValue(dhnew);
docs.add(doc);
}
LOGGER.info(" SENDING TO ENDPOINT " + to);
DocumentRepositoryProxy proxy = new DocumentRepositoryProxy(endpointUrl, new DirectSOAPHandlerResolver());
RegistryResponseType rrt = proxy.provideAndRegisterDocumentSetB(prdst);
String test = rrt.getStatus();
if (test.indexOf("Failure") >= 0) {
String error = "";
try {
error = rrt.getRegistryErrorList().getRegistryError().get(0).getCodeContext();
} catch (Exception x) {
}
throw new Exception("Failure Returned from XDR forward:" + error);
}
getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
}
resp = getRepositoryProvideResponse(threadData.getMessageId());
String relatesTo = threadData.getRelatesTo();
threadData.setRelatesTo(threadData.getMessageId());
threadData.setAction("urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse");
threadData.setTo(null);
threadData.save();
} catch (Exception e) {
e.printStackTrace();
throw (e);
}
return resp;
}
use of javax.activation.DataSource in project AuthMeReloaded by AuthMe.
the class EmailService method embedImageIntoEmailContent.
private static String embedImageIntoEmailContent(File image, HtmlEmail email, String content) throws EmailException {
DataSource source = new FileDataSource(image);
String tag = email.embed(source, image.getName());
return content.replace("<image />", "<img src=\"cid:" + tag + "\">");
}
use of javax.activation.DataSource in project zm-mailbox by Zimbra.
the class Mime method fixBase64MimePartLineFolding.
/**
* Some devices send wide base64 encoded message body i.e. without line folding.
* As per RFC https://www.ietf.org/rfc/rfc2045.txt see 6.8. Base64 Content-Transfer-Encoding
* "The encoded output stream must be represented in lines of no more than 76 characters each."
*
* To fix the issue here, re-writing the same content to message part.
* @param mm
* @throws MessagingException
* @throws IOException
*/
public static void fixBase64MimePartLineFolding(MimeMessage mm) throws MessagingException, IOException {
List<MPartInfo> mList = Mime.getParts(mm);
for (MPartInfo mPartInfo : mList) {
String ct = mPartInfo.getMimePart().getHeader("Content-Transfer-Encoding", ":");
if (MimeConstants.ET_BASE64.equalsIgnoreCase(ct)) {
InputStream io = mPartInfo.getMimePart().getInputStream();
String ctype = mPartInfo.getMimePart().getContentType();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(io, bos);
DataSource ds = new ByteArrayDataSource(bos.toByteArray(), ctype);
DataHandler dh = new DataHandler(ds);
mPartInfo.getMimePart().setDataHandler(dh);
mPartInfo.getMimePart().setHeader("Content-Transfer-Encoding", ct);
mPartInfo.getMimePart().setHeader("Content-Type", ctype);
}
}
}
use of javax.activation.DataSource in project zm-mailbox by Zimbra.
the class MessageRFC822Handler method getContentImpl.
/**
* Returns the subject of the attached message.
*/
@Override
protected String getContentImpl() throws MimeHandlerException {
DataSource ds = getDataSource();
if (ds == null) {
return null;
}
InputStream is = null;
String content = null;
try {
is = ds.getInputStream();
if (is == null) {
return null;
}
InternetHeaders headers = new InternetHeaders(is);
String[] subject = headers.getHeader("Subject");
if (subject == null || subject.length == 0 || subject[0] == null) {
return null;
}
int maxLength = MimeHandlerManager.getIndexedTextLimit();
if (subject[0].length() > maxLength) {
content = subject[0].substring(0, maxLength);
} else {
content = subject[0];
}
} catch (Exception e) {
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
return content;
}
use of javax.activation.DataSource in project zm-mailbox by Zimbra.
the class TextCalendarHandler method analyze.
private void analyze(boolean needCal) throws MimeHandlerException {
if (mContent != null)
return;
DataSource source = getDataSource();
if (source == null) {
mContent = "";
return;
}
InputStream is = null;
try {
is = source.getInputStream();
String charset = MimeConstants.P_CHARSET_UTF8;
String ctStr = source.getContentType();
if (ctStr != null) {
String cs = Mime.getCharset(ctStr);
if (cs != null)
charset = cs;
}
if (needCal) {
miCalendar = ZCalendarBuilder.build(is, charset);
StringBuilder buf = new StringBuilder(1024);
int maxLength = MimeHandlerManager.getIndexedTextLimit();
for (Iterator<ZComponent> compIter = miCalendar.getComponentIterator(); compIter.hasNext() && buf.length() < maxLength; ) {
ZComponent comp = compIter.next();
for (Iterator<ZProperty> propIter = comp.getPropertyIterator(); propIter.hasNext(); ) {
ZProperty prop = propIter.next();
if (sIndexedProps.contains(prop.getName())) {
String value = prop.getValue();
if (value != null && value.length() > 0) {
if (buf.length() > 0)
buf.append(' ');
buf.append(value);
}
}
}
}
mContent = buf.toString();
} else {
IcsParseHandler handler = new IcsParseHandler();
ZCalendarBuilder.parse(is, charset, handler);
mContent = handler.getContent();
}
} catch (Exception e) {
mContent = "";
ZimbraLog.index.warn("error reading text/calendar mime part", e);
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
}
Aggregations