1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.cxf.support; |
12 | |
|
13 | |
import javax.xml.stream.XMLInputFactory; |
14 | |
import javax.xml.stream.XMLOutputFactory; |
15 | |
|
16 | |
import org.apache.cxf.Bus; |
17 | |
import org.apache.cxf.endpoint.Client; |
18 | |
import org.apache.cxf.endpoint.Server; |
19 | |
import org.apache.cxf.feature.AbstractFeature; |
20 | |
import org.apache.cxf.interceptor.Fault; |
21 | |
import org.apache.cxf.message.Message; |
22 | |
import org.apache.cxf.phase.AbstractPhaseInterceptor; |
23 | |
import org.apache.cxf.phase.Phase; |
24 | |
import org.apache.cxf.service.Service; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 6 | public class StaxFeature extends AbstractFeature { |
31 | |
private String xmlInputFactory; |
32 | |
private String xmlOutputFactory; |
33 | |
|
34 | |
@Override |
35 | |
public void initialize(Client client, Bus bus) { |
36 | 0 | Service service = client.getEndpoint().getService(); |
37 | |
|
38 | 0 | setProperties(service); |
39 | 0 | } |
40 | |
|
41 | |
private void setProperties(Service service) { |
42 | 0 | if (xmlInputFactory != null) { |
43 | 0 | service.put(XMLInputFactory.class.getName(), xmlInputFactory); |
44 | |
} |
45 | |
|
46 | 0 | if (xmlOutputFactory != null) { |
47 | 0 | service.put(XMLOutputFactory.class.getName(), xmlOutputFactory); |
48 | |
} |
49 | 0 | } |
50 | |
|
51 | |
@Override |
52 | |
public void initialize(Server server, Bus bus) { |
53 | 0 | Service service = server.getEndpoint().getService(); |
54 | |
|
55 | 0 | setProperties(service); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public void initialize(Bus bus) { |
60 | 0 | AbstractPhaseInterceptor<Message> in = new AbstractPhaseInterceptor<Message>(Phase.RECEIVE) { |
61 | 0 | public void handleMessage(Message message) throws Fault { |
62 | 0 | if (xmlInputFactory != null) { |
63 | 0 | message.put(XMLInputFactory.class.getName(), xmlInputFactory); |
64 | |
} |
65 | 0 | } |
66 | |
}; |
67 | |
|
68 | 0 | bus.getInInterceptors().add(in); |
69 | 0 | bus.getInFaultInterceptors().add(in); |
70 | |
|
71 | 0 | AbstractPhaseInterceptor<Message> out = new AbstractPhaseInterceptor<Message>(Phase.SETUP) { |
72 | 0 | public void handleMessage(Message message) throws Fault { |
73 | 0 | if (xmlOutputFactory != null) { |
74 | 0 | message.put(XMLOutputFactory.class.getName(), xmlOutputFactory); |
75 | |
} |
76 | 0 | } |
77 | |
}; |
78 | |
|
79 | 0 | bus.getOutInterceptors().add(out); |
80 | 0 | bus.getOutFaultInterceptors().add(out); |
81 | 0 | } |
82 | |
|
83 | |
public String getXmlInputFactory() { |
84 | 0 | return xmlInputFactory; |
85 | |
} |
86 | |
|
87 | |
public void setXmlInputFactory(String xmlInputFactory) { |
88 | 6 | this.xmlInputFactory = xmlInputFactory; |
89 | 6 | } |
90 | |
|
91 | |
public String getXmlOutputFactory() { |
92 | 0 | return xmlOutputFactory; |
93 | |
} |
94 | |
|
95 | |
public void setXmlOutputFactory(String xmlOutputFactory) { |
96 | 6 | this.xmlOutputFactory = xmlOutputFactory; |
97 | 6 | } |
98 | |
|
99 | |
} |