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(MuleUniversalTransport.TRANSPORT_ID, transport); |
82 | |
|
83 | 0 | ConduitInitiatorManager extension = bus.getExtension(ConduitInitiatorManager.class); |
84 | |
try |
85 | |
{ |
86 | |
|
87 | |
|
88 | 0 | extension.getConduitInitiator("http://schemas.xmlsoap.org/soap/http"); |
89 | |
} |
90 | 0 | catch (BusException e1) |
91 | |
{ |
92 | |
|
93 | 0 | } |
94 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/", transport); |
95 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", transport); |
96 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http/", transport); |
97 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http", transport); |
98 | 0 | extension.registerConduitInitiator("http://schemas.xmlsoap.org/wsdl/http/", transport); |
99 | 0 | extension.registerConduitInitiator("http://www.w3.org/2003/05/soap/bindings/HTTP/", transport); |
100 | 0 | extension.registerConduitInitiator("http://cxf.apache.org/transports/http/configuration", transport); |
101 | 0 | extension.registerConduitInitiator("http://cxf.apache.org/bindings/xformat", transport); |
102 | 0 | extension.registerConduitInitiator(MuleUniversalTransport.TRANSPORT_ID, transport); |
103 | 0 | } |
104 | |
|
105 | |
public void dispose() |
106 | |
{ |
107 | 0 | bus.shutdown(true); |
108 | |
|
109 | |
|
110 | 0 | JAXBDataBinding.clearCaches(); |
111 | |
try |
112 | |
{ |
113 | |
|
114 | 0 | final Field cacheField = ASMHelper.class.getDeclaredField("LOADER_MAP"); |
115 | 0 | cacheField.setAccessible(true); |
116 | |
|
117 | 0 | final Map cache = (Map) cacheField.get(null); |
118 | 0 | cache.clear(); |
119 | |
} |
120 | 0 | catch (Throwable t) |
121 | |
{ |
122 | 0 | logger.warn("Error disposing CxfConfiguration, this may cause a memory leak", t); |
123 | 0 | } |
124 | 0 | } |
125 | |
|
126 | |
public Bus getCxfBus() |
127 | |
{ |
128 | 0 | return bus; |
129 | |
} |
130 | |
|
131 | |
public void setCxfBus(Bus bus) |
132 | |
{ |
133 | 0 | this.bus = bus; |
134 | 0 | } |
135 | |
|
136 | |
public String getConfigurationLocation() |
137 | |
{ |
138 | 0 | return configurationLocation; |
139 | |
} |
140 | |
|
141 | |
public void setConfigurationLocation(String configurationLocation) |
142 | |
{ |
143 | 0 | this.configurationLocation = configurationLocation; |
144 | 0 | } |
145 | |
|
146 | |
public boolean isInitializeStaticBusInstance() |
147 | |
{ |
148 | 0 | return initializeStaticBusInstance; |
149 | |
} |
150 | |
|
151 | |
public void setInitializeStaticBusInstance(boolean initializeStaticBusInstance) |
152 | |
{ |
153 | 0 | this.initializeStaticBusInstance = initializeStaticBusInstance; |
154 | 0 | } |
155 | |
|
156 | |
public void setMuleContext(MuleContext context) |
157 | |
{ |
158 | 0 | this.muleContext = context; |
159 | 0 | } |
160 | |
|
161 | |
public MuleContext getMuleContext() |
162 | |
{ |
163 | 0 | return muleContext; |
164 | |
} |
165 | |
|
166 | |
public static CxfConfiguration getConfiguration(MuleContext muleContext) throws MuleException |
167 | |
{ |
168 | 0 | CxfConfiguration configuration = muleContext.getRegistry().get(CxfConstants.DEFAULT_CXF_CONFIGURATION); |
169 | 0 | if (configuration == null) |
170 | |
{ |
171 | 0 | configuration = new CxfConfiguration(); |
172 | 0 | configuration.setMuleContext(muleContext); |
173 | 0 | configuration.initialise(); |
174 | 0 | muleContext.getRegistry().registerObject(CxfConstants.DEFAULT_CXF_CONFIGURATION, configuration); |
175 | |
} |
176 | 0 | return configuration; |
177 | |
} |
178 | |
|
179 | |
} |