Coverage Report - org.mule.module.cxf.support.StreamClosingInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamClosingInterceptor
0%
0/8
N/A
0
StreamClosingInterceptor$1
0%
0/7
N/A
0
 
 1  
 /*
 2  
  * $Id: StreamClosingInterceptor.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.DelegateXMLStreamReader;
 14  
 
 15  
 import java.io.IOException;
 16  
 import java.io.InputStream;
 17  
 
 18  
 import javax.xml.stream.XMLStreamException;
 19  
 import javax.xml.stream.XMLStreamReader;
 20  
 
 21  
 import org.apache.cxf.interceptor.Fault;
 22  
 import org.apache.cxf.interceptor.StaxInInterceptor;
 23  
 import org.apache.cxf.message.Message;
 24  
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 25  
 import org.apache.cxf.phase.Phase;
 26  
 
 27  
 /**
 28  
  * Replaces the original XMLStreamReader with another one which
 29  
  * closes the underlying InputStream.
 30  
  */
 31  
 public class StreamClosingInterceptor extends AbstractPhaseInterceptor<Message>
 32  
 {
 33  
     public StreamClosingInterceptor()
 34  
     {
 35  0
         super(Phase.POST_STREAM);
 36  0
         addAfter(StaxInInterceptor.class.getName());
 37  0
     }
 38  
 
 39  
     public void handleMessage(final Message message) throws Fault
 40  
     {
 41  0
         XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
 42  0
         final InputStream is = message.getContent(InputStream.class);
 43  0
         DelegateXMLStreamReader xsr2 = new DelegateXMLStreamReader(xsr) {
 44  
 
 45  
             @Override
 46  
             public void close() throws XMLStreamException
 47  
             {
 48  0
                 super.close();
 49  
                 try
 50  
                 {
 51  0
                     is.close();
 52  
                 }
 53  0
                 catch (IOException e)
 54  
                 {
 55  0
                     throw new XMLStreamException(e);
 56  0
                 }
 57  0
             }
 58  
         };
 59  0
         message.setContent(XMLStreamReader.class, xsr2);
 60  0
     }
 61  
 }
 62