/** * You can directly access the attachment map of the message context from * here. Returned attachment map can be empty. * * @return attachment */ public Attachments getAttachmentMap() { return getAttachmentMap(true); }
/** * Extracts the attachments from the current message request. * * @return List of attachments or an empty array if none exist. */ public static DataHandler[] getAttachments() { final MessageContext messageContext = getCurrentMessageContext(); if (messageContext.getAttachmentMap() == null) { throw new RuntimeException("You can not retreieve attachments when you do " + "not have the activation.jar and mail.jars available"); } final Set contentIds = messageContext.getAttachmentMap().getContentIDSet(); int attachmentCount = contentIds.size(); final DataHandler[] attachments = new DataHandler[attachmentCount]; int count = 0; for (final Iterator iterator = contentIds.iterator(); iterator.hasNext(); count++) { attachments[count] = messageContext.getAttachment((String)iterator.next()); } return attachments; }
/** * Helper util method to get the logging done whenever injecting the message into synapse * * @param log - Log appender to be used to append logs * @param messageContext - MessageContext which will be logged */ public static void doHandlerLogging(Log log, MessageContext messageContext) { if (log.isDebugEnabled()) { log.debug("Synapse handler received a new message for message mediation..."); log.debug("Received To: " + (messageContext.getTo() != null ? messageContext.getTo().getAddress() : "null")); log.debug("SOAPAction: " + (messageContext.getSoapAction() != null ? messageContext.getSoapAction() : "null")); log.debug("WSA-Action: " + (messageContext.getWSAAction() != null ? messageContext.getWSAAction() : "null")); String[] cids = messageContext.getAttachmentMap().getAllContentIDs(); if (cids != null && cids.length > 0) { for (int i = 0; i < cids.length; i++) { log.debug("Attachment : " + cids[i]); } } log.debug("Body : \n" + messageContext.getEnvelope()); } }
/** * Helper util method to get the logging done whenever injecting the message into synapse * * @param log - Log appender to be used to append logs * @param messageContext - MessageContext which will be logged */ public static void doHandlerLogging(Log log, MessageContext messageContext) { if (log.isDebugEnabled()) { log.debug("Synapse handler received a new message for message mediation..."); log.debug("Received To: " + (messageContext.getTo() != null ? messageContext.getTo().getAddress() : "null")); log.debug("SOAPAction: " + (messageContext.getSoapAction() != null ? messageContext.getSoapAction() : "null")); log.debug("WSA-Action: " + (messageContext.getWSAAction() != null ? messageContext.getWSAAction() : "null")); String[] cids = messageContext.getAttachmentMap().getAllContentIDs(); if (cids != null && cids.length > 0) { for (int i = 0; i < cids.length; i++) { log.debug("Attachment : " + cids[i]); } } log.debug("Body : \n" + messageContext.getEnvelope()); } }
/** * Prepare the message in the given message context so that the underlying input stream can be * closed. * * @param msgContext */ public static void detachInputStream(MessageContext msgContext) throws AxisFault { if (msgContext != null) { OMXMLParserWrapper builder = (OMXMLParserWrapper)msgContext.getProperty(Constants.BUILDER); if (builder != null) { builder.detach(); } else { Attachments attachments = msgContext.getAttachmentMap(false); if (attachments != null) { attachments.getAllContentIDs(); } else { SOAPEnvelope envelope = msgContext.getEnvelope(); if (envelope != null) { envelope.build(); } } } } }
getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif");
final Attachments attachments = msgContext.getAttachmentMap();
getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif");
getText(); Attachments attachment = response.getAttachmentMap(); dataHandler = attachment.getDataHandler(imageContentId); File tempFile = File.createTempFile("swa-", ".gif");
List<String> attachmentIDs = persistAttachments(inMessageContext.getAttachmentMap()); if (attachmentIDs != null && !attachmentIDs.isEmpty()) { bpelMessageContext.setAttachmentIDList(attachmentIDs);
/** * Gets all requested attachments as a list of {@link Attachment} objects so they can be processed by WSS4j. * * @param attachmentId The Content-Id of the requested attachment, or<br> * <code>null</code> if all attachments are requested * @return The list of attachments * @throws IOException When one of the requested attachment can not be accessed */ private List<Attachment> getAttachments(final String attachmentId) throws IOException { final List<org.apache.wss4j.common.ext.Attachment> attachmentList = new ArrayList<>(); final Attachments attachments = msgContext.getAttachmentMap(); if (attachments != null) { for (final Object o : attachments.getContentIDSet()) { final String cid = (String) o; // Check if this is the correct attachment, if none content-id is specified it is always okay if (attachmentId != null && !attachmentId.equals(cid)) continue; // Create the WSS4J Attachhment object final Attachment att = new Attachment(); final DataHandler attachment = attachments.getDataHandler(cid); att.setMimeType(attachment.getContentType()); att.setId(cid); att.setSourceStream(attachment.getInputStream()); attachmentList.add(att); } } return attachmentList; }
@Override public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (final Callback callback : callbacks) { if (callback instanceof AttachmentRequestCallback) { final AttachmentRequestCallback reqCallback = (AttachmentRequestCallback) callback; // Is one specific attachment requested or all? String attachmentId = reqCallback.getAttachmentId(); if ("Attachments".equals(attachmentId)) attachmentId = null; // all attachments reqCallback.setAttachments(getAttachments(attachmentId)); } else if (callback instanceof AttachmentResultCallback) { final AttachmentResultCallback resultCallback = (AttachmentResultCallback) callback; final Attachment resultAttachment = resultCallback.getAttachment(); // Wrap the stream from the WSS4J Attachment in a DataHandler that can be used by Axis2 final DataHandler dh = new DataHandler(new AttachmentDataSource(resultAttachment.getMimeType(), resultAttachment.getSourceStream())); msgContext.getAttachmentMap().addDataHandler(resultCallback.getAttachmentId(), dh); } else { throw new UnsupportedCallbackException(callback, "Unsupported callback"); } } }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
public AxisMessage(MessageContext msgContext) throws Exception { envelope = msgContext.getEnvelope(); // If possible, build the parent (i.e. the OMDocument) to make sure that the entire message is read. // If the transport doesn't handle the end of the message properly, then this problem // will show up here. OMDocument document = (OMDocument)envelope.getParent(); if (document != null) { document.build(); } else { envelope.build(); } // TODO: quick & dirty hack to force expansion of OMSourceElement payloads OMElement content = envelope.getBody().getFirstElement(); if (content instanceof OMSourcedElement) { ((OMSourcedElement)content).getFirstOMChild(); ((OMSourcedElement)content).build(); } if (msgContext.isDoingSwA()) { // Make sure that all attachments are read attachments = msgContext.getAttachmentMap(); attachments.getAllContentIDs(); } messageType = (String)msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE); }
String[] cids = mc.getAttachmentMap().getAllContentIDs(); if (cids != null && cids.length > 0) { for (String cid : cids) {
String[] cids = null; try { cids = mc.getAttachmentMap().getAllContentIDs(); } catch (Exception ex){
Attachments attachments = ori.getAttachmentMap(); if (attachments != null && attachments.getAllContentIDs().length > 0) { String[] cIDs = attachments.getAllContentIDs();
newMC.setAttachmentMap(ori.getAttachmentMap());
Attachments attachments = ori.getAttachmentMap(); if (attachments != null && attachments.getAllContentIDs().length > 0) { String[] cIDs = attachments.getAllContentIDs();