Search in sources :

Example 1 with AttachmentPart

use of javax.xml.soap.AttachmentPart in project quickstarts by jboss-switchyard.

the class SoapAttachmentClient method main.

public static void main(String[] args) throws Exception {
    String port = System.getProperty("org.switchyard.component.soap.client.port", "8080");
    SOAPMessage response = sendMessage("http://localhost:" + port + "/soap-attachment/ImageServiceService");
    SOAPUtil.prettyPrint(response, System.out);
    @SuppressWarnings("unchecked") Iterator<AttachmentPart> iterator = response.getAttachments();
    AttachmentPart ap = iterator.next();
    System.out.println("Response attachment: " + ap.getContentId() + " with content type " + ap.getContentType());
}
Also used : AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 2 with AttachmentPart

use of javax.xml.soap.AttachmentPart 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 3 with AttachmentPart

use of javax.xml.soap.AttachmentPart in project jdk8u_jdk by JetBrains.

the class MailTest method addSoapAttachement.

void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) SOAPException(javax.xml.soap.SOAPException) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

AttachmentPart (javax.xml.soap.AttachmentPart)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 MessageFactory (javax.xml.soap.MessageFactory)2 URL (java.net.URL)1 DataHandler (javax.activation.DataHandler)1 URLDataSource (javax.activation.URLDataSource)1 QName (javax.xml.namespace.QName)1 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)1 SOAPConnection (javax.xml.soap.SOAPConnection)1 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)1 SOAPException (javax.xml.soap.SOAPException)1