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 | 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 | |
|