List of usage examples for javax.xml.soap AttachmentPart getBase64Content
public abstract InputStream getBase64Content() throws SOAPException;
From source file:org.apache.axis2.saaj.AttachmentTest.java
@Validated @Test//from ww w . j a v a 2 s .com public void testSetBase64Content() { try { MessageFactory factory = MessageFactory.newInstance(); SOAPMessage msg = factory.createMessage(); AttachmentPart ap = msg.createAttachmentPart(); String urlString = "http://ws.apache.org/images/project-logo.jpg"; if (isNetworkedResourceAvailable(urlString)) { URL url = new URL(urlString); DataHandler dh = new DataHandler(url); //Create InputStream from DataHandler's InputStream InputStream is = dh.getInputStream(); byte buf[] = IOUtils.getStreamAsByteArray(is); //Setting Content via InputStream for image/jpeg mime type ByteArrayOutputStream bos = new ByteArrayOutputStream(); Base64.encode(buf, 0, buf.length, bos); buf = bos.toByteArray(); InputStream stream = new ByteArrayInputStream(buf); ap.setBase64Content(stream, "image/jpeg"); //Getting Content.. should return InputStream object InputStream r = ap.getBase64Content(); if (r != null) { if (r instanceof InputStream) { //InputStream object was returned (ok) } else { fail("Unexpected object was returned"); } } } } catch (Exception e) { fail("Exception: " + e); } }