AttachmentPart attachment = message.createAttachmentPart(); String stringContent = "Update address for Sunny Skies " + "Inc., to 10 Upbeat Street, Pleasant Grove, CA 95439"; attachment.setContent(stringContent, "text/plain"); attachment.setContentId("update_address"); message.addAttachmentPart(attachment);
/** * Creates an AttachmentPart object and populates it with the specified data of the specified content type. * @param content an Object containing the content for this SOAPMessage object * @param contentType a String object giving the type of content; examples are "text/xml", "text/plain", and "image/jpeg" * @return a new AttachmentPart object that contains the given data */ public AttachmentPart createAttachmentPart(Object content, String contentType) { AttachmentPart part = createAttachmentPart(); part.setContent(content, contentType); return part; }
throws SOAPException { AttachmentPart attachment = soapMessage.createAttachmentPart(); attachment.setContent( new ByteArrayInputStream( theBytes ), contentType ); soapMessage.addAttachmentPart( attachment );
byte[] encoded = Files.readAllBytes(Paths.get("C:\\Users\\timofb\\Documents\\test.txt")); String soapXml = new String(encoded, StandardCharsets.UTF_8); SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); java.net.URL endpoint = new URL("http://" + ip + "/cs-repository/services/xds-iti41"); SOAPConnection connection = soapConnectionFactory.createConnection(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(encoded)); AttachmentPart attachment = message.createAttachmentPart(); attachment.setContent("sm_content", "text/plain"); attachment.setContentId("1.9f910338bf0cac0e783bfdec7e53be9237684caa8f8f4e6d@apache.org"); message.addAttachmentPart(attachment); SOAPMessage response = connection.call(message, endpoint); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.writeTo(out); String strMsg = new String(out.toByteArray()); return strMsg;
/** * Creates an <CODE>AttachmentPart</CODE> object and populates it with the specified data of the * specified content type. * * @param content an <CODE>Object</CODE> containing the content for this * <CODE>SOAPMessage</CODE> object * @param contentType a <CODE>String</CODE> object giving the type of content; examples are * "text/xml", "text/plain", and "image/jpeg" * @return a new <CODE>AttachmentPart</CODE> object that contains the given data * @throws IllegalArgumentException * if the contentType does not match the type of the content object, or if there was no * <CODE> DataContentHandler</CODE> object for the given content object * @see DataHandler DataHandler * @see javax.activation.DataContentHandler DataContentHandler */ public AttachmentPart createAttachmentPart(Object content, String contentType) { AttachmentPart attachmentpart = createAttachmentPart(); attachmentpart.setContent(content, contentType); return attachmentpart; }
throw NativeMessages.MESSAGES.couldNotDetermineMimeType(partName); part.setContent(value, mimeType);
/** * Creates an {@code AttachmentPart} object and populates it with * the specified data of the specified content type. The type of the * {@code Object} should correspond to the value given for the * {@code Content-Type}. * * @param content * an {@code Object} containing the content for the * {@code AttachmentPart} object to be created * @param contentType * a {@code String} object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new {@code AttachmentPart} object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * {@code DataContentHandler} object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an <code>AttachmentPart</code> object and populates it with * the specified data of the specified content type. The type of the * <code>Object</code> should correspond to the value given for the * <code>Content-Type</code>. * * @param content * an <code>Object</code> containing the content for the * <code>AttachmentPart</code> object to be created * @param contentType * a <code>String</code> object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new <code>AttachmentPart</code> object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * <code>DataContentHandler</code> object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an {@code AttachmentPart} object and populates it with * the specified data of the specified content type. The type of the * {@code Object} should correspond to the value given for the * {@code Content-Type}. * * @param content * an {@code Object} containing the content for the * {@code AttachmentPart} object to be created * @param contentType * a {@code String} object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new {@code AttachmentPart} object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * {@code DataContentHandler} object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an <code>AttachmentPart</code> object and populates it with * the specified data of the specified content type. The type of the * <code>Object</code> should correspond to the value given for the * <code>Content-Type</code>. * * @param content * an <code>Object</code> containing the content for the * <code>AttachmentPart</code> object to be created * @param contentType * a <code>String</code> object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new <code>AttachmentPart</code> object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * <code>DataContentHandler</code> object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an {@code AttachmentPart} object and populates it with * the specified data of the specified content type. The type of the * {@code Object} should correspond to the value given for the * {@code Content-Type}. * * @param content * an {@code Object} containing the content for the * {@code AttachmentPart} object to be created * @param contentType * a {@code String} object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new {@code AttachmentPart} object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * {@code DataContentHandler} object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an {@code AttachmentPart} object and populates it with * the specified data of the specified content type. The type of the * {@code Object} should correspond to the value given for the * {@code Content-Type}. * * @param content * an {@code Object} containing the content for the * {@code AttachmentPart} object to be created * @param contentType * a {@code String} object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new {@code AttachmentPart} object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * {@code DataContentHandler} object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
/** * Creates an <code>AttachmentPart</code> object and populates it with * the specified data of the specified content type. The type of the * <code>Object</code> should correspond to the value given for the * <code>Content-Type</code>. * * @param content * an <code>Object</code> containing the content for the * <code>AttachmentPart</code> object to be created * @param contentType * a <code>String</code> object giving the type of content; * examples are "text/xml", "text/plain", and "image/jpeg" * @return a new <code>AttachmentPart</code> object that contains the * given data * @exception IllegalArgumentException * may be thrown if the contentType does not match the type * of the content object, or if there was no * <code>DataContentHandler</code> object for the given * content object * @see javax.activation.DataHandler * @see javax.activation.DataContentHandler */ public AttachmentPart createAttachmentPart( Object content, String contentType) { AttachmentPart attachment = createAttachmentPart(); attachment.setContent(content, contentType); return attachment; }
@Test public void testSWA() throws Exception { SOAPFactory soapFac = SOAPFactory.newInstance(); MessageFactory msgFac = MessageFactory.newInstance(); SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance(); SOAPMessage msg = msgFac.createMessage(); QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach"); 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()); }