View Javadoc

1   /*
2    * $Id: ReversibleStaxInInterceptor.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 javax.xml.stream.XMLStreamReader;
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.phase.AbstractPhaseInterceptor;
21  import org.apache.cxf.phase.Phase;
22  
23  /**
24   * Resets the ReversibleXMLStreamReader so the person receiving it can start back
25   * at the beginning of the stream.
26   */
27  public class ReversibleStaxInInterceptor extends AbstractPhaseInterceptor<Message>
28  {
29  
30      public ReversibleStaxInInterceptor()
31      {
32          super(Phase.POST_STREAM);
33          getAfter().add(StreamClosingInterceptor.class.getName());
34          getAfter().add(StaxInInterceptor.class.getName());
35      }
36  
37      public void handleMessage(Message message) throws Fault
38      {
39          XMLStreamReader reader = message.getContent(XMLStreamReader.class);
40          
41          if (reader != null) 
42          {
43              ReversibleXMLStreamReader reversible = new ReversibleXMLStreamReader(reader);
44              reversible.setTracking(true);
45              message.setContent(XMLStreamReader.class, reversible);
46              message.setContent(ReversibleXMLStreamReader.class, reversible);
47          }
48      }
49  
50  
51  }
52  
53