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 javax.xml.stream.XMLStreamReader;
12  
13  import org.apache.cxf.interceptor.Fault;
14  import org.apache.cxf.message.Message;
15  import org.apache.cxf.phase.AbstractPhaseInterceptor;
16  
17  /**
18   * Creates a ReversibleXMLStreamReader to be able to track and replay events from the XMLStreamReader.
19   */
20  public abstract class ReversibleStaxInterceptor extends AbstractPhaseInterceptor<Message>
21  {
22      public ReversibleStaxInterceptor(String phase)
23      {
24          super(phase);
25      }
26  
27      public void handleMessage(Message message) throws Fault
28      {
29          XMLStreamReader reader = message.getContent(XMLStreamReader.class);
30  
31          if (reader != null)
32          {
33              ReversibleXMLStreamReader reversible = new ReversibleXMLStreamReader(reader);
34              reversible.setTracking(true);
35              message.setContent(XMLStreamReader.class, reversible);
36              message.setContent(ReversibleXMLStreamReader.class, reversible);
37          }
38      }
39  
40  }