use of javax.activation.URLDataSource in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithDataSourcMessageModeXMLBinding.
@Test
public void testInvokeWithDataSourcMessageModeXMLBinding() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
XMLService service = new XMLService();
assertNotNull(service);
Dispatch<DataSource> disp = service.createDispatch(portNameXML, DataSource.class, Mode.MESSAGE);
setAddress(disp, addNumbersAddress);
TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
addHandlersProgrammatically(disp, handler);
URL is = getClass().getResource("/messages/XML_GreetMeDocLiteralReq.xml");
DataSource ds = new URLDataSource(is);
DataSource resp = disp.invoke(ds);
assertNotNull(resp);
}
use of javax.activation.URLDataSource in project mycore by MyCoRe-Org.
the class MCRMailer method trySending.
private static void trySending(EMail mail) throws Exception {
MimeMessage msg = new MimeMessage(mailSession);
msg.setFrom(EMail.buildAddress(mail.from));
Optional<List<InternetAddress>> toList = EMail.buildAddressList(mail.to);
if (toList.isPresent())
msg.addRecipients(Message.RecipientType.TO, toList.get().toArray(new InternetAddress[toList.get().size()]));
Optional<List<InternetAddress>> replyToList = EMail.buildAddressList(mail.replyTo);
if (replyToList.isPresent())
msg.setReplyTo((replyToList.get().toArray(new InternetAddress[replyToList.get().size()])));
Optional<List<InternetAddress>> bccList = EMail.buildAddressList(mail.bcc);
if (bccList.isPresent())
msg.addRecipients(Message.RecipientType.BCC, bccList.get().toArray(new InternetAddress[bccList.get().size()]));
msg.setSentDate(new Date());
msg.setSubject(mail.subject, encoding);
if (mail.parts != null && !mail.parts.isEmpty() || mail.msgParts != null && mail.msgParts.size() > 1) {
Multipart multipart = new MimeMultipart();
// Create the message part
MimeBodyPart messagePart = new MimeBodyPart();
if (mail.msgParts.size() > 1) {
multipart = new MimeMultipart("mixed");
MimeMultipart alternative = new MimeMultipart("alternative");
for (MessagePart m : mail.msgParts) {
messagePart = new MimeBodyPart();
messagePart.setText(m.message, encoding, m.type.value());
alternative.addBodyPart(messagePart);
}
messagePart = new MimeBodyPart();
messagePart.setContent(alternative);
multipart.addBodyPart(messagePart);
} else {
Optional<MessagePart> plainMsg = mail.getTextMessage();
if (plainMsg.isPresent()) {
messagePart.setText(plainMsg.get().message, encoding);
multipart.addBodyPart(messagePart);
}
}
if (mail.parts != null && !mail.parts.isEmpty()) {
for (String part : mail.parts) {
messagePart = new MimeBodyPart();
URL url = new URL(part);
DataSource source = new URLDataSource(url);
messagePart.setDataHandler(new DataHandler(source));
String fileName = url.getPath();
if (fileName.contains("\\")) {
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
} else if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
}
messagePart.setFileName(fileName);
multipart.addBodyPart(messagePart);
}
}
msg.setContent(multipart);
} else {
Optional<MessagePart> plainMsg = mail.getTextMessage();
if (plainMsg.isPresent()) {
msg.setText(plainMsg.get().message, encoding);
}
}
LOGGER.info("Sending e-mail to {}", mail.to);
Transport.send(msg);
}
use of javax.activation.URLDataSource in project quickstarts by jboss-switchyard.
the class SoapAttachmentClient method sendMessage.
public static SOAPMessage sendMessage(String switchyard_web_service) throws Exception {
SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = conFactory.createConnection();
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage msg = msgFactory.createMessage();
SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
bodyElement.addTextNode("cid:switchyard.png");
AttachmentPart ap = msg.createAttachmentPart();
URL imageUrl = Classes.getResource("switchyard.png");
ap.setDataHandler(new DataHandler(new URLDataSource(imageUrl)));
ap.setContentId("switchyard.png");
msg.addAttachmentPart(ap);
return connection.call(msg, new URL(switchyard_web_service));
}
use of javax.activation.URLDataSource in project jbossws-cxf by jbossws.
the class JBWS3250TestCase method testMtomSawpFile.
@Test
@RunAsClient
public void testMtomSawpFile() throws Exception {
URL wsdlURL = new URL(baseURL + "?wsdl");
QName serviceName = new QName("http://ws.jboss.org/jbws3250", "TestEndpointService");
Endpoint port = Service.create(wsdlURL, serviceName).getPort(Endpoint.class);
SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
binding.setMTOMEnabled(true);
URL url = JBossWSTestHelper.getResourceURL("jaxws/jbws3250/wsf.png");
URLDataSource urlDatasource = new URLDataSource(url);
javax.activation.DataHandler dh = new DataHandler(urlDatasource);
MTOMRequest request = new MTOMRequest();
request.setContent(dh);
request.setId("largeSize_mtom_request");
MTOMResponse mtomResponse = port.echo(request);
Assert.assertEquals("Response for requestID:largeSize_mtom_request", mtomResponse.getResponse());
byte[] responseBytes = IOUtils.convertToBytes(mtomResponse.getContent());
Assert.assertTrue(responseBytes.length > 65536);
}
use of javax.activation.URLDataSource in project pentaho-kettle by pentaho.
the class MailTest method createMimeMessage.
private Message createMimeMessage(String specialCharacters, File attachedFile) throws Exception {
Session session = Session.getInstance(new Properties());
Message message = new MimeMessage(session);
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart attachedFileAndContent = new MimeBodyPart();
attachedFile.deleteOnExit();
// create a data source
URLDataSource fds = new URLDataSource(attachedFile.toURI().toURL());
// get a data Handler to manipulate this file type;
attachedFileAndContent.setDataHandler(new DataHandler(fds));
// include the file in the data source
String tempFileName = attachedFile.getName();
message.setSubject(specialCharacters);
attachedFileAndContent.setFileName(tempFileName);
attachedFileAndContent.setText(specialCharacters);
multipart.addBodyPart(attachedFileAndContent);
message.setContent(multipart);
return message;
}
Aggregations