Search in sources :

Example 16 with URLDataSource

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);
}
Also used : URLDataSource(javax.activation.URLDataSource) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) URL(java.net.URL) URLDataSource(javax.activation.URLDataSource) DataSource(javax.activation.DataSource) Test(org.junit.Test)

Example 17 with URLDataSource

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);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) URLDataSource(javax.activation.URLDataSource) MessagePart(org.mycore.common.MCRMailer.EMail.MessagePart) DataHandler(javax.activation.DataHandler) Date(java.util.Date) URL(java.net.URL) URLDataSource(javax.activation.URLDataSource) DataSource(javax.activation.DataSource) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) List(java.util.List) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 18 with URLDataSource

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));
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) URLDataSource(javax.activation.URLDataSource) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 19 with URLDataSource

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);
}
Also used : URLDataSource(javax.activation.URLDataSource) QName(javax.xml.namespace.QName) SOAPBinding(javax.xml.ws.soap.SOAPBinding) DataHandler(javax.activation.DataHandler) DataHandler(javax.activation.DataHandler) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 20 with URLDataSource

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;
}
Also used : URLDataSource(javax.activation.URLDataSource) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) DataHandler(javax.activation.DataHandler) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Properties(java.util.Properties) MimeBodyPart(javax.mail.internet.MimeBodyPart) Session(javax.mail.Session)

Aggregations

URLDataSource (javax.activation.URLDataSource)21 DataHandler (javax.activation.DataHandler)14 MimeBodyPart (javax.mail.internet.MimeBodyPart)11 URL (java.net.URL)9 DataSource (javax.activation.DataSource)9 MimeMultipart (javax.mail.internet.MimeMultipart)8 IOException (java.io.IOException)6 Multipart (javax.mail.Multipart)6 FileDataSource (javax.activation.FileDataSource)5 MimeMessage (javax.mail.internet.MimeMessage)5 InputStream (java.io.InputStream)4 Properties (java.util.Properties)4 Message (javax.mail.Message)4 Session (javax.mail.Session)4 InternetAddress (javax.mail.internet.InternetAddress)4 File (java.io.File)3 MessagingException (javax.mail.MessagingException)3 Date (java.util.Date)2 BodyPart (javax.mail.BodyPart)2 QName (javax.xml.namespace.QName)2