List of usage examples for javax.xml.soap SOAPMessage removeAllAttachments
public abstract void removeAllAttachments();
From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java
@Validated @Test//from w ww.j a va 2 s .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.ibm.soatf.component.soap.SOAPComponent.java
private void checkSOAPMessage(boolean ok) throws SoapComponentException { ProgressMonitor.init(2, "Loading message from file..."); String filename = new StringBuilder(serviceName).append(NAME_DELIMITER).append(operationName) .append(NAME_DELIMITER).append(RESPONSE_FILE_SUFFIX).toString(); final File file = new File(workingDir, filename); InputStream is = null;//from ww w. ja va2s .c o m try { final byte[] xmlMessage = FileUtils.readFileToByteArray(file); is = new ByteArrayInputStream(xmlMessage); SOAPMessage response = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL) .createMessage(new MimeHeaders(), is); ProgressMonitor.increment("Checking for fault..."); response.removeAllAttachments(); SOAPEnvelope envp = response.getSOAPPart().getEnvelope(); SOAPBody someBody = envp.getBody(); if (ok) { if (someBody.getFault() == null) { cor.addMsg("soap body is OK"); cor.markSuccessful(); } else { final String msg = "found soap fault in response body:\n" + new String(xmlMessage); cor.addMsg(msg); throw new SoapComponentException(msg); } } else { if (someBody.getFault() != null) { cor.addMsg("found soap fault in response body"); cor.markSuccessful(); } else { final String msg = "response body doesn't contain soap fault:\n" + new String(xmlMessage); cor.addMsg(msg); throw new SoapComponentException(msg); } } } catch (IOException | SOAPException ex) { throw new SoapComponentException("error while trying to parse response", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { logger.debug("Not able to close input stream. ", ex); } } } }
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test/* w ww . j a v a 2s. co m*/ public void testStringAttachment() throws Exception { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(); 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); assertTrue(message.countAttachments() == 1); Iterator it = message.getAttachments(); while (it.hasNext()) { attachment = (AttachmentPart) it.next(); Object content = attachment.getContent(); String id = attachment.getContentId(); assertEquals(content, stringContent); } message.removeAllAttachments(); assertTrue(message.countAttachments() == 0); }