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  
  * 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.DelegateXMLStreamReader;
 10  
 
 11  
 import java.io.IOException;
 12  
 import java.io.InputStream;
 13  
 
 14  
 import javax.xml.stream.XMLStreamException;
 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  
  * Replaces the original XMLStreamReader with another one which
 25  
  * closes the underlying InputStream.
 26  
  */
 27  
 public class StreamClosingInterceptor extends AbstractPhaseInterceptor<Message>
 28  
 {
 29  
     public StreamClosingInterceptor()
 30  
     {
 31  0
         super(Phase.POST_STREAM);
 32  0
         addAfter(StaxInInterceptor.class.getName());
 33  0
     }
 34  
 
 35  
     public void handleMessage(final Message message) throws Fault
 36  
     {
 37  0
         XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
 38  0
         final InputStream is = message.getContent(InputStream.class);
 39  0
         DelegateXMLStreamReader xsr2 = new DelegateXMLStreamReader(xsr) {
 40  
 
 41  
             @Override
 42  
             public void close() throws XMLStreamException
 43  
             {
 44  0
                 super.close();
 45  
                 try
 46  
                 {
 47  0
                     is.close();
 48  
                 }
 49  0
                 catch (IOException e)
 50  
                 {
 51  0
                     throw new XMLStreamException(e);
 52  0
                 }
 53  0
             }
 54  
         };
 55  0
         message.setContent(XMLStreamReader.class, xsr2);
 56  0
     }
 57  
 }
 58