1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.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 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 Service service = client.getEndpoint().getService();
37
38 setProperties(service);
39 }
40
41 private void setProperties(Service service) {
42 if (xmlInputFactory != null) {
43 service.put(XMLInputFactory.class.getName(), xmlInputFactory);
44 }
45
46 if (xmlOutputFactory != null) {
47 service.put(XMLOutputFactory.class.getName(), xmlOutputFactory);
48 }
49 }
50
51 @Override
52 public void initialize(Server server, Bus bus) {
53 Service service = server.getEndpoint().getService();
54
55 setProperties(service);
56 }
57
58 @Override
59 public void initialize(Bus bus) {
60 AbstractPhaseInterceptor<Message> in = new AbstractPhaseInterceptor<Message>(Phase.RECEIVE) {
61 public void handleMessage(Message message) throws Fault {
62 if (xmlInputFactory != null) {
63 message.put(XMLInputFactory.class.getName(), xmlInputFactory);
64 }
65 }
66 };
67
68 bus.getInInterceptors().add(in);
69 bus.getInFaultInterceptors().add(in);
70
71 AbstractPhaseInterceptor<Message> out = new AbstractPhaseInterceptor<Message>(Phase.SETUP) {
72 public void handleMessage(Message message) throws Fault {
73 if (xmlOutputFactory != null) {
74 message.put(XMLOutputFactory.class.getName(), xmlOutputFactory);
75 }
76 }
77 };
78
79 bus.getOutInterceptors().add(out);
80 bus.getOutFaultInterceptors().add(out);
81 }
82
83 public String getXmlInputFactory() {
84 return xmlInputFactory;
85 }
86
87 public void setXmlInputFactory(String xmlInputFactory) {
88 this.xmlInputFactory = xmlInputFactory;
89 }
90
91 public String getXmlOutputFactory() {
92 return xmlOutputFactory;
93 }
94
95 public void setXmlOutputFactory(String xmlOutputFactory) {
96 this.xmlOutputFactory = xmlOutputFactory;
97 }
98
99 }