View Javadoc

1   /*
2    * $Id: CopyAttachmentInInterceptor.java 19191 2010-08-25 21:05:23Z tcarlson $
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.api.MuleMessage;
15  import org.mule.module.cxf.CxfConstants;
16  import org.mule.transport.http.HttpConstants;
17  
18  import java.util.Collection;
19  
20  import org.apache.cxf.interceptor.Fault;
21  import org.apache.cxf.message.Attachment;
22  import org.apache.cxf.message.Message;
23  import org.apache.cxf.phase.AbstractPhaseInterceptor;
24  import org.apache.cxf.phase.Phase;
25  
26  import static org.mule.api.config.MuleProperties.MULE_EVENT_PROPERTY;
27  
28  public class CopyAttachmentInInterceptor extends AbstractPhaseInterceptor
29  {
30      public CopyAttachmentInInterceptor()
31      {
32          super(Phase.PRE_INVOKE);
33      }
34  
35      public void handleMessage(Message message) throws Fault
36      {
37          MuleEvent event = (MuleEvent) message.get(MULE_EVENT_PROPERTY);
38          MuleMessage muleMsg;
39          if (event == null) 
40          {
41              event = (MuleEvent) message.get(CxfConstants.MULE_EVENT);
42          } 
43          
44          muleMsg = event.getMessage();
45          Collection<Attachment> atts = message.getAttachments();
46          if (atts != null)
47          {
48              muleMsg.setOutboundProperty(CxfConstants.ATTACHMENTS, atts);
49              muleMsg.setOutboundProperty(HttpConstants.HEADER_CONTENT_TYPE, muleMsg.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
50          }
51      }
52  
53  }
54  
55