View Javadoc

1   /*
2    * $Id: ResetStaxInterceptor.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.module.xml.stax.ReversibleXMLStreamReader;
14  
15  import java.util.List;
16  
17  import org.apache.cxf.interceptor.Fault;
18  import org.apache.cxf.interceptor.StaxInInterceptor;
19  import org.apache.cxf.message.Message;
20  import org.apache.cxf.message.MessageContentsList;
21  import org.apache.cxf.phase.AbstractPhaseInterceptor;
22  import org.apache.cxf.phase.Phase;
23  
24  /**
25   * Replaces the XMLStreamReader with a ReversibleXMLStreamReader which caches the xml events so 
26   * we can replay them later.
27   */
28  public class ResetStaxInterceptor extends AbstractPhaseInterceptor<Message>
29  {
30  
31      public ResetStaxInterceptor()
32      {
33          super(Phase.PRE_INVOKE);
34          getAfter().add(StaxInInterceptor.class.getName());
35      }
36  
37      public void handleMessage(Message message) throws Fault
38      {
39          ReversibleXMLStreamReader reader = message.getContent(ReversibleXMLStreamReader.class);
40          reader.reset();
41          
42          // Replace the message contents because if you're using WSS4J, it leaves the
43          // stream pointing to the body, when we want it pointing to the envelope.
44          MessageContentsList parameters = new MessageContentsList();
45          parameters.add(reader);
46          message.setContent(List.class, parameters);
47      }
48  }
49  
50