public static void deleteAttachments(MessageContext msgContext) {
if (log.isDebugEnabled()) {
log.debug("Entering deleteAttachments()");
}
Attachments attachments = msgContext.getAttachmentMap();
if (attachments != null) {
// Get the list of Content IDs for the attachments...but does not try to pull the stream for new attachments.
// (Pulling the stream for new attachments will probably fail...the stream is probably closed)
List keys = attachments.getContentIDList();
if (keys != null && keys.size() > 0) {
String key = null;
File file = null;
LifecycleManager lcm = (LifecycleManager)msgContext.getRootContext().getAxisConfiguration().getParameterValue(DeploymentConstants.ATTACHMENTS_LIFECYCLE_MANAGER);
DataSource dataSource = null;
for (int i = 0; i < keys.size(); i++) {
try {
key = (String) keys.get(i);
dataSource = attachments.getDataHandler(key).getDataSource();
if(dataSource instanceof CachedFileDataSource){
file = ((CachedFileDataSource)dataSource).getFile();
if (log.isDebugEnabled()) {
log.debug("Delete cache attachment file: "+file.getName());
}