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