use of javax.activation.FileDataSource in project cxf by apache.
the class MTOMSecurityTest method testSignedMTOMInline.
// The attachment is inlined + the SOAP Body signed
@org.junit.Test
public void testSignedMTOMInline() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = MTOMSecurityTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSignedMTOMInlinePort");
DoubleItMtomPortType port = service.getPort(portQName, DoubleItMtomPortType.class);
updateAddressPort(port, PORT);
DataSource source = new FileDataSource(new File("src/test/resources/java.jpg"));
DoubleIt4 doubleIt = new DoubleIt4();
doubleIt.setNumberToDouble(25);
port.doubleIt4(25, new DataHandler(source));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of javax.activation.FileDataSource in project MassBank-web by MassBank.
the class SendMail method send.
/**
* メール送信関数
* @param info メール送信情報オブジェクト
* @return 結果
*/
public static boolean send(SendMailInfo info) {
// メール送信情報チェック
if (!info.isCheck()) {
Logger.global.severe("The mail sending failed.");
return false;
}
String[] smtpItems = info.getSmtp().split(",");
if (smtpItems.length >= 1) {
host = smtpItems[0].trim();
}
if (smtpItems.length >= 2) {
port = smtpItems[1].trim();
}
if (smtpItems.length >= 3) {
user = smtpItems[2].trim();
}
if (smtpItems.length >= 4) {
pass = smtpItems[3].trim();
}
if (port.equals("")) {
port = "25";
}
System.out.println(host + "/" + port + "/" + user + "/" + pass);
try {
// SMTPサーバーのアドレスを設定
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
if (port.equals("465") || port.equals("587")) {
props.put("mail.smtp.ssl.trust", host);
if (port.equals("465")) {
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
} else if (port.equals("587")) {
props.put("mail.smtp.starttls.enable", "true");
}
}
Session session = null;
if (user.equals("") || pass.equals("")) {
props.put("mail.smtp.auth", "false");
session = Session.getDefaultInstance(props, null);
} else {
props.put("mail.smtp.auth", "true");
session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pass);
}
});
}
MimeMessage mimeMsg = new MimeMessage(session);
// 送信元メールアドレスと送信者名を設定
mimeMsg.setFrom(new InternetAddress(info.getFrom(), info.getFromName(), "utf-8"));
// 送信先メールアドレスを設定
mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(info.getTo()));
if (!info.getCc().equals("")) {
mimeMsg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(info.getCc()));
}
if (!info.getBcc().equals("")) {
mimeMsg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(info.getBcc()));
}
// メールタイトルを設定
mimeMsg.setSubject(info.getSubject(), "utf-8");
// メールボディ用マルチパートオブジェクト生成
MimeMultipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
// 本文
mbp.setText(info.getContents(), "utf-8");
mp.addBodyPart(mbp);
File[] files = info.getFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
// 添付ファイル
mbp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(files[i]);
mbp.setDataHandler(new DataHandler(fds));
mbp.setFileName(MimeUtility.encodeWord(fds.getName()));
mp.addBodyPart(mbp);
}
}
// メール内容にマルチパートオブジェクトと送信日付を設定して送信
mimeMsg.setContent(mp);
mimeMsg.setSentDate(new Date());
Transport.send(mimeMsg);
} catch (Exception e) {
Logger.global.severe("The mail sending failed.");
e.printStackTrace();
return false;
}
return true;
}
use of javax.activation.FileDataSource in project hub-alert by blackducksoftware.
the class MimeMultipartBuilder method addAttachmentBodyParts.
private void addAttachmentBodyParts(final MimeMultipart email) throws MessagingException {
for (final String filePath : attachmentFilePaths) {
final MimeBodyPart attachmentBodyPart = new MimeBodyPart();
final DataSource source = new FileDataSource(filePath);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(FilenameUtils.getName(filePath));
email.addBodyPart(attachmentBodyPart);
}
}
use of javax.activation.FileDataSource in project cxf by apache.
the class DataSourceProvider method readFrom.
public T readFrom(Class<T> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, String> headers, InputStream is) throws IOException {
DataSource ds = null;
if (cls == FileDataSource.class) {
File file = new BinaryDataProvider<File>().readFrom(File.class, File.class, annotations, type, headers, is);
ds = new FileDataSource(file);
} else if (cls == DataSource.class || cls == DataHandler.class) {
ds = new InputStreamDataSource(is, type.toString());
} else {
LOG.warning("Unsupported DataSource class: " + cls.getName());
throw ExceptionUtils.toWebApplicationException(null, null);
}
return cls.cast(DataSource.class.isAssignableFrom(cls) ? ds : new DataHandler(ds));
}
use of javax.activation.FileDataSource in project vboard by voyages-sncf-technologies.
the class MessagesController method sendNotificationEmail.
// Send notification and global emails
public void sendNotificationEmail(User to, String content, List<Pin> pins, String title) throws Exception {
// Javax mail used
MimeMessage message = this.emailSenderService.setEmail(to);
message.setSubject(title, "utf-8");
String footer = this.footerTemplate;
footer = String.format(footer, hostName);
content = content + footer;
message.setText(content, "utf-8", "html");
// This mail has 2 part, the BODY and the embedded image
MimeMultipart multipart = new MimeMultipart();
// first part (the html)
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(content, "text/html; charset=UTF-8");
multipart.addBodyPart(messageBodyPart);
HashSet<Profil> users = new HashSet<>();
// Images
for (Pin pin : pins) {
users.add(this.userDAO.findByEmail(User.getEmailFromString(pin.getAuthor()).get()));
if (!isBlank(pin.getImgType()) && !pin.getImgType().contains("<iframe") && !pin.getImgType().startsWith("https") && !pin.getImgType().endsWith("svg") && !pin.getImgType().endsWith("gif")) {
try {
messageBodyPart = new MimeBodyPart();
String vblogUrl = "http://" + hostName + "/vblog/wp-content/uploads";
DataSource img;
if (pin.getImgType().contains(vblogUrl)) {
img = new FileDataSource(imageManager.getBlogImagesDirectory().resolve(pin.getImgType().substring(pin.getImgType().indexOf(vblogUrl) + vblogUrl.length())).toFile());
} else {
img = new FileDataSource(imageManager.getPinsImagesDirectory().resolve(pin.getPinId() + ".png").toFile());
}
messageBodyPart.setDataHandler(new DataHandler(img));
messageBodyPart.setHeader("Content-ID", "<" + pin.getPinId() + ">");
// add image to the multipart
multipart.addBodyPart(messageBodyPart);
} catch (Exception e) {
this.logger.error("Image non trouvée sur le NAS:{}.png", pin.getPinId());
}
}
}
this.addLeadersImgs(multipart, users);
messageBodyPart = new MimeBodyPart();
DataSource img = new FileDataSource(imageManager.getAvatarImagesDirectory().resolve("default.png").toFile());
messageBodyPart.setDataHandler(new DataHandler(img));
messageBodyPart.setHeader("Content-ID", "<default>");
multipart.addBodyPart(messageBodyPart);
// put everything together
message.setContent(multipart);
// Send message
Transport.send(message);
}
Aggregations