/** * Adds an attachment to the attachment Map of this message context. This * attachment gets serialised as a MIME attachment when sending the message * if SOAP with Attachments is enabled. Content ID of the MIME part will be * auto generated by Axis2. * * @param dataHandler * @return the auto generated content ID of the MIME attachment */ public String addAttachment(DataHandler dataHandler) { String contentID = UIDGenerator.generateContentId(); addAttachment(contentID, dataHandler); return contentID; }
/** * Adds an attachment to the attachment Map of this message context. This * attachment gets serialised as a MIME attachment when sending the message * if SOAP with Attachments is enabled. Content ID of the MIME part will be * auto generated by Axis2. * * @param dataHandler * @return the auto generated content ID of the MIME attachment */ public String addAttachment(DataHandler dataHandler) { String contentID = UIDGenerator.generateContentId(); addAttachment(contentID, dataHandler); return contentID; }
/** * Sends the given <code>contents</code> using the appropriate current message * response using DIME. * * @param contents the contents of the attachment * @param contentType the content type (i.e. mime type) * @param dime whether or not DIME should be used (instead of MIME) */ public static void saveAttachment( final Object contents, final String contentType, boolean dime) { if (contents != null) { // the message context stores all the request/response specific stuff final MessageContext messageContext = getCurrentMessageContext(); messageContext.addAttachment(convertContents(contents, contentType)); if (dime) { // - tell axis to use DIME // TODO: does axis2 even support DIME? } } }
private void enableCompression(final IPayload p, final MessageContext mc) { // Replace current datahandler of attachment with CompressionDataHandler to facilitate compression final String cid = p.getPayloadURI(); final DataHandler source = mc.getAttachment(cid); mc.addAttachment(cid, new CompressionDataHandler(source)); log.trace("Replaced DataHandler to enable compression"); // Set the part properties to indicate AS4 Compression feature was used and original MIME Type // First ensure that there do not exists properties with this name // partProperties should not be null here final Collection<IProperty> partProperties = p.getProperties(); final Collection<IProperty> remove = new ArrayList<>(); for(final IProperty pp : partProperties) if (CompressionFeature.FEATURE_PROPERTY_NAME.equals(pp.getName()) || CompressionFeature.MIME_TYPE_PROPERTY_NAME.equals(pp.getName())) remove.add(pp); partProperties.removeAll(remove); partProperties.add(new Property(CompressionFeature.FEATURE_PROPERTY_NAME, CompressionFeature.COMPRESSED_CONTENT_TYPE)); partProperties.add(new Property(CompressionFeature.MIME_TYPE_PROPERTY_NAME, source.getContentType())); log.trace("Set PartProperties to indicate compression"); }
/** * Method to build a MEP Client with an attachment in the method context. * * @deprecated Please use * {@link #buildMEPClient(EndpointReference, OMElement, Map, String, String, String)} instead. * @param endpoint The endpoint to configure the client for. * @param request The request to add as a SOAP envelope. * @param attachmentMap The attachment map. * @return The built MEP Client * @throws AxisFault on failure to initialize the client. */ @Deprecated private OperationClient buildMEPClient(final EndpointReference endpoint, final OMElement request, final Map<String, DataHandler> attachmentMap) throws AxisFault { ServiceClient serviceClient = new ServiceClient(); Options serviceOptions = new Options(); serviceOptions.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); serviceOptions.setTo(endpoint); serviceOptions.setAction("mediate"); serviceClient.setOptions(serviceOptions); MessageContext messageContext = new MessageContext(); SOAPEnvelope soapEnvelope = TransportUtils.createSOAPEnvelope(request); messageContext.setEnvelope(soapEnvelope); for (String contentId : attachmentMap.keySet()) { messageContext.addAttachment(contentId, attachmentMap.get(contentId)); } OperationClient mepClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP); mepClient.addMessageContext(messageContext); return mepClient; }
messageContext.addAttachment(contentId, attachmentMap.get(contentId));
messageContext.addAttachment(contentId, attachmentMap.get(contentId));
messageContext.addAttachment(contentId, attachmentMap.get(contentId));
FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler);
FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler);
public void uploadFileUsingSwA(String fileName) throws Exception { Options options = new Options(); options.setTo(targetEPR); options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setTo(targetEPR); ServiceClient sender = new ServiceClient(null,null); sender.setOptions(options); OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); MessageContext mc = new MessageContext(); mc.setEnvelope(createEnvelope()); FileDataSource fileDataSource = new FileDataSource("test-resources/mtom/test.jpg"); DataHandler dataHandler = new DataHandler(fileDataSource); mc.addAttachment("FirstAttachment",dataHandler); mepClient.addMessageContext(mc); mepClient.execute(true); }
FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); String attachmentID = mc.addAttachment(dataHandler);
final String cid = p.getPayloadURI(); log.trace("Add payload to message as attachment with Content-id: " + cid); mc.addAttachment(cid, dh); log.debug("Payload content located at '" + p.getContentLocation() + "' added to message"); return;
DataSource dataSource = new ByteArrayDataSource((byte[]) value); DataHandler dataHandler = new DataHandler(dataSource); String contentID = msgCtx.addAttachment(dataHandler); OMElement binaryData = soapFactory.createOMElement(FIXConstants.FIX_BINARY_FIELD, null); String binaryCID = "cid:" + contentID;
DataSource dataSource = new ByteArrayDataSource((byte[]) value); DataHandler dataHandler = new DataHandler(dataSource); String contentID = msgCtx.addAttachment(dataHandler); OMElement binaryData = soapFactory.createOMElement( FIXConstants.FIX_BINARY_FIELD, null);
mc.addAttachment(cid, new CompressionDataHandler(mc.getAttachment(cid), mimeType)); log.trace("Replaced DataHandler to enable decompression");
public void testClonePartiallyWithAttachments() throws Exception { MessageContext origMc = new MessageContext(); String contentId = origMc.addAttachment(new DataHandler("test", "text/html")); MessageContext newMc = MessageHelper.clonePartially(origMc); DataHandler dh = newMc.getAttachment(contentId); assertNotNull(dh); assertEquals("test", dh.getContent()); }
messageContext.addAttachment(contentId, attachmentMap.get(contentId));
for (String cID : cIDs) { if (!cID.equals(soapPart)) { newMC.addAttachment(cID, attachments.getDataHandler(cID));
for (String cID : cIDs) { if (!cID.equals(soapPart)) { newMC.addAttachment(cID, attachments.getDataHandler(cID));