View Javadoc

1   /*
2    * $Id: CopyAttachmentInInterceptor.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.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  public class CopyAttachmentInInterceptor extends AbstractPhaseInterceptor
27  {
28      public CopyAttachmentInInterceptor()
29      {
30          super(Phase.PRE_INVOKE);
31      }
32  
33      public void handleMessage(Message message) throws Fault
34      {
35          MuleEvent event = (MuleEvent) message.getExchange().get(CxfConstants.MULE_EVENT);
36          MuleMessage muleMsg = event.getMessage();
37          Collection<Attachment> atts = message.getAttachments();
38          if (atts != null)
39          {
40              muleMsg.setInvocationProperty(CxfConstants.ATTACHMENTS, atts);
41              muleMsg.setOutboundProperty(HttpConstants.HEADER_CONTENT_TYPE, muleMsg.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
42          }
43      }
44  
45  }
46  
47