1
2
3
4
5
6
7
8
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
29
30
31 public class StreamClosingInterceptor extends AbstractPhaseInterceptor<Message>
32 {
33 public StreamClosingInterceptor()
34 {
35 super(Phase.POST_STREAM);
36 addAfter(StaxInInterceptor.class.getName());
37 }
38
39 public void handleMessage(final Message message) throws Fault
40 {
41 XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
42 final InputStream is = message.getContent(InputStream.class);
43 DelegateXMLStreamReader xsr2 = new DelegateXMLStreamReader(xsr) {
44
45 @Override
46 public void close() throws XMLStreamException
47 {
48 super.close();
49 try
50 {
51 is.close();
52 }
53 catch (IOException e)
54 {
55 throw new XMLStreamException(e);
56 }
57 }
58 };
59 message.setContent(XMLStreamReader.class, xsr2);
60 }
61 }
62