View Javadoc

1   /*
2    * $Id: CopyAttachmentOutInterceptor.java 21250 2011-02-10 22:54:24Z dandiep $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf.support;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.module.cxf.CxfConstants;
15  
16  import java.util.Collection;
17  
18  import org.apache.cxf.interceptor.Fault;
19  import org.apache.cxf.message.Attachment;
20  import org.apache.cxf.message.Message;
21  import org.apache.cxf.phase.AbstractPhaseInterceptor;
22  import org.apache.cxf.phase.Phase;
23  
24  /**
25   * Copies any attachments which were stored by the proxy to the outbound CXF message.
26   */
27  public class CopyAttachmentOutInterceptor extends AbstractPhaseInterceptor
28  {
29      public CopyAttachmentOutInterceptor()
30      {
31          super(Phase.SETUP);
32      }
33  
34      public void handleMessage(Message message) throws Fault
35      {
36          MuleEvent event = (MuleEvent) message.getExchange().get(CxfConstants.MULE_EVENT);
37          Collection<Attachment> a = event.getMessage().getInvocationProperty(CxfConstants.ATTACHMENTS);
38          
39          if (a != null) 
40          {
41              message.setAttachments(a);
42          }
43      }
44  }
45  
46