Java 8 AttachmentPart - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AttachmentPart class.

This code example shows how to use the following methods:setContentId, setDataHandler
        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));
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addMimeHeader, setContentId, setRawContent
This code example shows how to use the following methods:setContent
        msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
        AttachmentPart ap1 = msg.createAttachmentPart();
        ap1.setContent("Attachment content", "text/plain");
        msg.addAttachmentPart(ap1);
        AttachmentPart ap2 = msg.createAttachmentPart();
        ap2.setContent("Attachment content - Part 2", "text/plain");
        msg.addAttachmentPart(ap2);
        msg.saveChanges();
         
        SOAPConnection con = conFac.createConnection();
        URL endpoint = new URL("http://localhost:" + PORT 
                               + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1"); 
        SOAPMessage response = con.call(msg, endpoint); 
        QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
        assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
        assertEquals(2, response.countAttachments());
    } 
 
    private void doGreeterRPCLit(SOAPServiceRPCLit service,
                                 QName portName,
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDataHandler
    } 
 
    @Override 
    public DataHandler getDataHandler() { 
        try { 
            return saajAttachment.getDataHandler();
        } 
        catch (SOAPException ex) {
            throw new SaajAttachmentException(ex);
        } 
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setContentId
         
        // REVIEW 
        // Do we need to copy the content type from the datahandler ? 
         
        // Preserve the original content id 
        ap.setContentId(cid);
        return ap;
    } 
 
 
    /** 
     * Create a JAX-WS Message from the information on an Axis 2 Message Context 
     * 
     * @param msgContext 
     * @return Message 
     */ 
    public static Message getMessageFromMessageContext(MessageContext msgContext)
            throws WebServiceException {
        if (log.isDebugEnabled()) {
            log.debug("Start getMessageFromMessageContext");
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentType
    public void imageService() throws Exception {
        SOAPMessage response = sendMessage();
        XMLAssert.assertXMLEqual(RESPONSE, XMLHelper.toString(response.getSOAPPart().getDocumentElement()));
        Assert.assertTrue(response.getAttachments().hasNext());
        AttachmentPart attachment = (AttachmentPart)response.getAttachments().next();
        Assert.assertNotNull(attachment);
        Assert.assertEquals("image/jpeg", attachment.getContentType());
        /* this assertion appears to be platform-dependent  
        Assert.assertEquals(16384, attachment.getSize()); 
        */ 
    } 
 
    public SOAPMessage sendMessage() throws Exception {
        SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
 
        SOAPConnection connection = conFactory.createConnection();
        MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SOAPMessage msg = msgFactory.createMessage();
        SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-mtom:1.0", "image"));
        bodyElement.setTextContent(imageData);
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentId
                soapPart.getContentId());
        Iterator attachments = message.getAttachments();
        assertTrue(attachments.hasNext());
        AttachmentPart ap = (AttachmentPart)attachments.next();
        assertEquals("<urn:uuid:E3F7CE4554928DA89B1231365678347>", 
                ap.getContentId());
        assertFalse(attachments.hasNext());
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentType
    public void imageService() throws Exception {
        SOAPMessage response = sendMessage();
        XMLAssert.assertXMLEqual(RESPONSE, XMLHelper.toString(response.getSOAPPart().getDocumentElement()));
        Assert.assertTrue(response.getAttachments().hasNext());
        AttachmentPart attachment = (AttachmentPart)response.getAttachments().next();
        Assert.assertNotNull(attachment);
        Assert.assertEquals("image/jpeg", attachment.getContentType());
        /* this assertion appears to be platform-dependent  
        Assert.assertEquals(16384, attachment.getSize()); 
        */ 
    } 
 
    public SOAPMessage sendMessage() throws Exception {
        SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
 
        SOAPConnection connection = conFactory.createConnection();
        MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SOAPMessage msg = msgFactory.createMessage();
        SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-mtom:1.0", "image"));
        bodyElement.setTextContent(imageData);
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 AttachmentPart Methods: