Refine search
URL url = new URL("http://greatproducts.com/gizmos/img.jpg"); DataHandler dataHandler = new DataHandler(url); AttachmentPart attachment = message.createAttachmentPart(dataHandler); attachment.setContentId("attached_image"); message.addAttachmentPart(attachment);
public void writeTo(SOAPMessage saaj) throws SOAPException { AttachmentPart part = saaj.createAttachmentPart(); part.setDataHandler(dh); part.setContentId(contentId); saaj.addAttachmentPart(part); } }
/** * Sets the MIME header "Content-Id" with the given value. * * @param contentId a <CODE>String</CODE> giving the value of the "Content-Id" header * @throws IllegalArgumentException * if there was a problem with the specified <CODE> contentId</CODE> value * @see #getContentId() getContentId() */ public void setContentId(String contentId) { setMimeHeader("Content-Id", contentId); }
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);
java.util.Iterator iterator = message.getAttachments(); while (iterator.hasNext()) { AttachmentPart attachment = (AttachmentPart)iterator.next(); String id = attachment.getContentId(); String type = attachment.getContentType(); System.out.print("Attachment " + id + " has content type " + type); if (type.equals("text/plain")) { Object content = attachment.getContent(); System.out.println("Attachment contains:\n" + content); } }
public SOAPMessage sendMessage() throws Exception { SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = conFactory.createConnection(); MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage msg = msgFactory.createMessage(); SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage")); bodyElement.addTextNode("cid:switchyard.png"); // CXF does not set content-type. msg.getMimeHeaders().addHeader("Content-Type", "multipart/related; type=\"text/xml\"; start=\"<root.message@cxf.apache.org>\""); msg.getSOAPPart().setContentId("<root.message@cxf.apache.org>"); AttachmentPart ap = msg.createAttachmentPart(); ap.setDataHandler(new DataHandler(new StreamDataSource())); ap.setContentId("<switchyard.png>"); msg.addAttachmentPart(ap); return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE)); }
part.getDataHandler().writeTo(baos); if (contentOnly) { part.setContentType(mimeType); String[] cLength = part.getMimeHeader(MimeConstants.CONTENT_LENGTH); if (cLength != null && !cLength[0].equals("")) part.setMimeHeader(MimeConstants.CONTENT_LENGTH, Integer.toString(cipherOutput.length)); part.clearContent(); part.setDataHandler(new javax.activation.DataHandler(new _DS(cipherOutput, mimeType))); part.removeAllMimeHeaders(); String hname = hdr.getName(); String hvale = hdr.getValue(); part.setMimeHeader(hname, hvale); part.clearContent(); part.setDataHandler(decryptedAttachment.getDataHandler());
AttachmentPart attachment = soapMessage.createAttachmentPart(); attachment.setContent( new ByteArrayInputStream( theBytes ), contentType ); soapMessage.addAttachmentPart( attachment ); throws SOAPException, MalformedURLException { URL url = new URL( urlLocation ); AttachmentPart attachment = soapMessage.createAttachmentPart( new DataHandler( url ) ); attachment.setContentType( contentType ); soapMessage.addAttachmentPart( attachment ); buf.append( "\n--------------------------------------------\n" ); AttachmentPart attachment = attachments.next(); buf.append( "\nContent Location: " + attachment.getContentLocation() ); buf.append( "\nContent Id: " + attachment.getContentId() ); buf.append( "\nContent Size: " + attachment.getSize() ); buf.append( "\nContent Type: " + attachment.getContentType() );
private AttachmentPart createAttachment( GetMap getMap, ByteArrayOutputStream stream, SOAPMessage message, String contentId ) { DataSource ds = new ByteArrayDataSource( stream.toByteArray() ); DataHandler dataHandler = new DataHandler( ds ); AttachmentPart attachmentPart = message.createAttachmentPart( dataHandler ); attachmentPart.setContentId( contentId ); attachmentPart.setContentType( getMap.getFormat() ); return attachmentPart; }
message.getSOAPPart().getEnvelope().addNamespaceDeclaration(SCHEMA_PREFIX, W3C_XML_SCHEMA_NS_URI); message.getSOAPPart().getEnvelope().addNamespaceDeclaration(SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI); SOAPBody body = message.getSOAPPart().getEnvelope().getBody(); DataHandler attachment = attachmentHandler.getAttachments().get(id); AttachmentPart part = message.createAttachmentPart(attachment); part.setContentType(attachment.getContentType()); String contentId = "<" + id.substring(4) + ">"; part.setContentId(contentId); part.setMimeHeader("Content-Transfer-Encoding", "binary"); message.addAttachmentPart(part);
if (omText.isOptimized()) { // is this an attachment? final DataHandler datahandler = (DataHandler)omText.getDataHandler(); AttachmentPart attachment = saajSOAPMsg.createAttachmentPart(datahandler); final String id = IDGenerator.generateID(); attachment.setContentId("<" + id + ">"); attachment.setContentType(datahandler.getContentType()); saajSOAPMsg.addAttachmentPart(attachment); saajSOAPMsg.getSOAPPart().getEnvelope().createName("href"), "cid:" + id); } else {
@Override public InputStream getInputStream() throws IOException { try { return saajAttachment.getDataHandler().getInputStream(); } catch (SOAPException ex) { throw new SaajAttachmentException(ex); } }
@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()); }
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;
part.getDataHandler().writeTo(baos); cipherInput = ((ByteArrayOutputStream)baos).toByteArray(); } else { String uri = part.getContentId(); part.removeAllMimeHeaders(); part.setMimeHeader(MimeConstants.CONTENT_ID, uri); }else { uri = part.getContentLocation(); if (uri != null){ part.setMimeHeader(MimeConstants.CONTENT_LOCATION, uri); part.setContentType(cType); part.setMimeHeader(MimeConstants.CONTENT_LENGTH,Integer.toString(cLength)); part.setMimeHeader("Content-Transfer-Encoding", "base64"); part.setDataHandler(dh);
@Test 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()); */ }
String mimeType = MimeUtils.getBaseMimeType(handler.getContentType()); NativeLoggers.ROOT_LOGGER.mimeTypeNotAllowed(mimeType, paramMetaData.getXmlName(), mimeTypes); part.setDataHandler((DataHandler)value); throw NativeMessages.MESSAGES.couldNotDetermineMimeType(partName); part.setContent(value, mimeType); part.setContentId(swaCID);
@Override public Attachment addAttachment(String contentId, DataHandler dataHandler) { Assert.hasLength(contentId, "contentId must not be empty"); Assert.notNull(dataHandler, "dataHandler must not be null"); SOAPMessage message = getSaajMessage(); AttachmentPart attachmentPart = message.createAttachmentPart(dataHandler); message.addAttachmentPart(attachmentPart); attachmentPart.setContentId(contentId); attachmentPart.setMimeHeader(TransportConstants.HEADER_CONTENT_TRANSFER_ENCODING, "binary"); return new SaajAttachment(attachmentPart); }
/** * 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; }
protected void addAttachmentParts(MimeMultipart multipart) throws SOAPException, MessagingException { Iterator attachmentParts = soapMessage.getAttachments(); while (attachmentParts.hasNext()) { AttachmentPart attachmentPart = (AttachmentPart)attachmentParts.next(); DataHandler handler = attachmentPart.getDataHandler(); MimeBodyPart mimePart = new MimeBodyPart(); mimePart.setDataHandler(handler); Iterator mimeHeaders = attachmentPart.getAllMimeHeaders(); while (mimeHeaders.hasNext()) { MimeHeader soapHeader = (MimeHeader)mimeHeaders.next(); mimePart.addHeader(soapHeader.getName(), soapHeader.getValue()); } if (mimePart.getHeader(MimeConstants.CONTENT_TYPE) == null) { String type = handler.getContentType(); mimePart.setHeader(MimeConstants.CONTENT_TYPE, (type != null) ? type : MimeConstants.TYPE_APPLICATION_OCTET_STREAM); } if (mimePart.getHeader(MimeConstants.CONTENT_ID) == null) { mimePart.setHeader(MimeConstants.CONTENT_ID, CIDGenerator.generateFromCount()); } // TODO - Binary encoding is the most efficient, however, some transports (old mail servers) // require 7 bit ascii. Can we ask the remoting layer about the transport's binary safety? mimePart.setHeader(MimeConstants.CONTENT_TRANSFER_ENCODING, MimeConstants.BINARY_ENCODING); multipart.addBodyPart(mimePart); } }