View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf.support;
8   
9   import org.mule.module.xml.stax.ReversibleXMLStreamReader;
10  
11  import java.util.List;
12  
13  import org.apache.cxf.interceptor.Fault;
14  import org.apache.cxf.interceptor.StaxInInterceptor;
15  import org.apache.cxf.message.Message;
16  import org.apache.cxf.message.MessageContentsList;
17  import org.apache.cxf.phase.AbstractPhaseInterceptor;
18  import org.apache.cxf.phase.Phase;
19  
20  /**
21   * Replaces the XMLStreamReader with a ReversibleXMLStreamReader which caches the xml events so 
22   * we can replay them later.
23   */
24  public class ResetStaxInterceptor extends AbstractPhaseInterceptor<Message>
25  {
26  
27      public ResetStaxInterceptor()
28      {
29          super(Phase.PRE_INVOKE);
30          getAfter().add(StaxInInterceptor.class.getName());
31      }
32  
33      public void handleMessage(Message message) throws Fault
34      {
35          ReversibleXMLStreamReader reader = message.getContent(ReversibleXMLStreamReader.class);
36          reader.reset();
37          
38          // Replace the message contents because if you're using WSS4J, it leaves the
39          // stream pointing to the body, when we want it pointing to the envelope.
40          MessageContentsList parameters = new MessageContentsList();
41          parameters.add(reader);
42          message.setContent(List.class, parameters);
43      }
44  }
45  
46