1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.cxf; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.MuleException; |
15 | |
import org.mule.api.context.MuleContextAware; |
16 | |
import org.mule.api.lifecycle.Disposable; |
17 | |
import org.mule.api.lifecycle.Initialisable; |
18 | |
import org.mule.api.lifecycle.InitialisationException; |
19 | |
import org.mule.config.spring.SpringRegistry; |
20 | |
import org.mule.module.cxf.transport.MuleUniversalTransport; |
21 | |
|
22 | |
import java.lang.reflect.Field; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
import org.apache.cxf.Bus; |
28 | |
import org.apache.cxf.BusException; |
29 | |
import org.apache.cxf.BusFactory; |
30 | |
import org.apache.cxf.bus.spring.SpringBusFactory; |
31 | |
import org.apache.cxf.common.util.ASMHelper; |
32 | |
import org.apache.cxf.jaxb.JAXBDataBinding; |
33 | |
import org.apache.cxf.transport.ConduitInitiatorManager; |
34 | |
import org.apache.cxf.transport.DestinationFactoryManager; |
35 | |
import org.springframework.context.ApplicationContext; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class CxfConfiguration implements Initialisable, Disposable, MuleContextAware |
41 | |
{ |
42 | |
public static final String CXF = "cxf"; |
43 | |
public static final String CONFIGURATION_LOCATION = "configurationLocation"; |
44 | |
public static final String DEFAULT_MULE_NAMESPACE_URI = "http://www.muleumo.org"; |
45 | |
public static final String BUS_PROPERTY = CXF; |
46 | |
|
47 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
48 | |
|
49 | |
|
50 | |
private Bus bus; |
51 | |
private String configurationLocation; |
52 | 0 | private boolean initializeStaticBusInstance = true; |
53 | |
private MuleContext muleContext; |
54 | |
|
55 | |
public void initialise() throws InitialisationException |
56 | |
{ |
57 | 0 | BusFactory.setDefaultBus(null); |
58 | 0 | ApplicationContext context = (ApplicationContext) muleContext.getRegistry().lookupObject(SpringRegistry.SPRING_APPLICATION_CONTEXT); |
59 | |
|
60 | 0 | if (configurationLocation != null) |
61 | |
{ |
62 | 0 | bus = new SpringBusFactory(context).createBus(configurationLocation, true); |
63 | |
} |
64 | |
else |
65 | |
{ |
66 | 0 | bus = new SpringBusFactory().createBus((String) null, true); |
67 | |
} |
68 | |
|
69 | 0 | if (!initializeStaticBusInstance) |
70 | |
{ |
71 | 0 | BusFactory.setDefaultBus(null); |
72 | |
} |
73 | |
|
74 | 0 | MuleUniversalTransport transport = new MuleUniversalTransport(this); |
75 | 0 | DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); |
76 | 0 | dfm.registerDestinationFactory("http://schemas.xmlsoap.org/soap/http", transport); |
77 | 0 | dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http", transport); |
78 | 0 | dfm.registerDestinationFactory("http://cxf.apache.org/transports/http/configuration", transport); |
79 | 0 | dfm.registerDestinationFactory("http://schemas.xmlsoap.org/wsdl/http/", transport); |
80 | 0 | dfm.registerDestinationFactory("http://www.w3.org/2003/05/soap/bindings/HTTP/", transport); |
81 | 0 | dfm.registerDestinationFactory("http://cxf.apache.org/transports/jms", transport); |
82 | 0 | dfm.registerDestinationFactory(MuleUniversalTransport.TRANSPORT_ID, transport); |
83 | |
|
84 | 0 | ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class); |
85 | |
try |
86 | |
{ |
87 | |
|
88 | |
|
89 | 0 | extension.getConduitInitiator("http://schemas.xmlsoap.org/soap/http"); |
90 | |
} |
91 | 0 | catch (BusException e1) |
92 | |
{ |
93 | |
|
94 | 0 | } |
95 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", transport); |
96 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", transport); |
97 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http/", transport); |
98 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http", transport); |
99 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/http/", transport); |
100 | 0 | extension.registerConduitInitiator("http://www.w3.org/2003/05/soap/bindings/HTTP/", transport); |
101 | 0 | extension.registerConduitInitiator("http://cxf.apache.org/transports/http/configuration", transport); |
102 | 0 | extension.registerConduitInitiator("http://cxf.apache.org/bindings/xformat", transport); |
103 | 0 | extension.registerConduitInitiator("http://cxf.apache.org/transports/jms", transport); |
104 | 0 | extension.registerConduitInitiator(MuleUniversalTransport.TRANSPORT_ID, transport); |
105 | 0 | } |
106 | |
|
107 | |
public void dispose() |
108 | |
{ |
109 | 0 | bus.shutdown(true); |
110 | |
|
111 | |
|
112 | 0 | JAXBDataBinding.clearCaches(); |
113 | |
try |
114 | |
{ |
115 | |
|
116 | 0 | final Field cacheField = ASMHelper.class.getDeclaredField("LOADER_MAP"); |
117 | 0 | cacheField.setAccessible(true); |
118 | |
|
119 | 0 | final Map cache = (Map) cacheField.get(null); |
120 | 0 | cache.clear(); |
121 | |
} |
122 | 0 | catch (Throwable t) |
123 | |
{ |
124 | 0 | logger.warn("Error disposing CxfConfiguration, this may cause a memory leak", t); |
125 | 0 | } |
126 | 0 | } |
127 | |
|
128 | |
public Bus getCxfBus() |
129 | |
{ |
130 | 0 | return bus; |
131 | |
} |
132 | |
|
133 | |
public void setCxfBus(Bus bus) |
134 | |
{ |
135 | 0 | this.bus = bus; |
136 | 0 | } |
137 | |
|
138 | |
public String getConfigurationLocation() |
139 | |
{ |
140 | 0 | return configurationLocation; |
141 | |
} |
142 | |
|
143 | |
public void setConfigurationLocation(String configurationLocation) |
144 | |
{ |
145 | 0 | this.configurationLocation = configurationLocation; |
146 | 0 | } |
147 | |
|
148 | |
public boolean isInitializeStaticBusInstance() |
149 | |
{ |
150 | 0 | return initializeStaticBusInstance; |
151 | |
} |
152 | |
|
153 | |
public void setInitializeStaticBusInstance(boolean initializeStaticBusInstance) |
154 | |
{ |
155 | 0 | this.initializeStaticBusInstance = initializeStaticBusInstance; |
156 | 0 | } |
157 | |
|
158 | |
public void setMuleContext(MuleContext context) |
159 | |
{ |
160 | 0 | this.muleContext = context; |
161 | 0 | } |
162 | |
|
163 | |
public MuleContext getMuleContext() |
164 | |
{ |
165 | 0 | return muleContext; |
166 | |
} |
167 | |
|
168 | |
public static CxfConfiguration getConfiguration(MuleContext muleContext) throws MuleException |
169 | |
{ |
170 | 0 | CxfConfiguration configuration = muleContext.getRegistry().get(CxfConstants.DEFAULT_CXF_CONFIGURATION); |
171 | 0 | if (configuration == null) |
172 | |
{ |
173 | 0 | configuration = new CxfConfiguration(); |
174 | 0 | configuration.setMuleContext(muleContext); |
175 | 0 | configuration.initialise(); |
176 | 0 | muleContext.getRegistry().registerObject(CxfConstants.DEFAULT_CXF_CONFIGURATION, configuration); |
177 | |
} |
178 | 0 | return configuration; |
179 | |
} |
180 | |
|
181 | |
} |