1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
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 | |
|
25 | |
|
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 | |
|