List of usage examples for javax.xml.soap SOAPMessage saveRequired
public abstract boolean saveRequired();
From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java
@Validated @Test/*from w w w .j a v a 2s.co m*/ public final void testRemoveAllAttachments() throws Exception { SOAPMessage message = getFactory().createMessage(); for (int i = 0; i < 5; i++) { AttachmentPart att = message.createAttachmentPart("test" + i, "text/plain"); message.addAttachmentPart(att); } assertEquals(5, message.countAttachments()); message.removeAllAttachments(); assertEquals(0, message.countAttachments()); if (message.saveRequired()) { message.saveChanges(); } String[] contentType = message.getMimeHeaders().getHeader("Content-Type"); assertNotNull(contentType); assertEquals(1, contentType.length); assertEquals(messageSet.getVersion().getContentType(), new MimeType(contentType[0]).getBaseType()); }
From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java
@Validated @Test//from w w w .j a v a 2 s .c o m public void testAddAttachmentPart() throws Exception { SOAPMessage message = getFactory().createMessage(); AttachmentPart attachment = message.createAttachmentPart(); message.addAttachmentPart(attachment); Iterator it = message.getAttachments(); assertTrue(it.hasNext()); assertSame(attachment, it.next()); assertFalse(it.hasNext()); // Check that the content type automatically changes to SwA if (message.saveRequired()) { message.saveChanges(); } String[] contentTypeArray = message.getMimeHeaders().getHeader("Content-Type"); assertNotNull(contentTypeArray); assertEquals(1, contentTypeArray.length); MimeType contentType = new MimeType(contentTypeArray[0]); assertEquals("multipart/related", contentType.getBaseType()); assertEquals(messageSet.getVersion().getContentType(), contentType.getParameter("type")); assertNotNull(contentType.getParameter("boundary")); }
From source file:test.saaj.TestAttachmentSerialization.java
public int saveMsgWithAttachments(OutputStream os) throws Exception { MessageFactory mf = MessageFactory.newInstance(); SOAPMessage msg = mf.createMessage(); SOAPPart sp = msg.getSOAPPart(); SOAPEnvelope envelope = sp.getEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPBody body = envelope.getBody(); SOAPElement el = header.addHeaderElement(envelope.createName("field4", NS_PREFIX, NS_URI)); SOAPElement el2 = el.addChildElement("field4b", NS_PREFIX); SOAPElement el3 = el2.addTextNode("field4value"); el = body.addBodyElement(envelope.createName("bodyfield3", NS_PREFIX, NS_URI)); el2 = el.addChildElement("bodyfield3a", NS_PREFIX); el2.addTextNode("bodyvalue3a"); el2 = el.addChildElement("bodyfield3b", NS_PREFIX); el2.addTextNode("bodyvalue3b"); el2 = el.addChildElement("datefield", NS_PREFIX); AttachmentPart ap = msg.createAttachmentPart(); ap.setContent("some attachment text...", "text/plain"); msg.addAttachmentPart(ap);/*ww w .j a va 2s .c o m*/ String jpgfilename = "docs/images/axis.jpg"; File myfile = new File(jpgfilename); FileDataSource fds = new FileDataSource(myfile); DataHandler dh = new DataHandler(fds); AttachmentPart ap2 = msg.createAttachmentPart(dh); ap2.setContentType("image/jpg"); msg.addAttachmentPart(ap2); // Test for Bug #17664 if (msg.saveRequired()) { msg.saveChanges(); } MimeHeaders headers = msg.getMimeHeaders(); assertTrue(headers != null); String[] contentType = headers.getHeader("Content-Type"); assertTrue(contentType != null); msg.writeTo(os); os.flush(); return msg.countAttachments(); }