1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.soap.xfire; |
12 | |
|
13 | |
import org.mule.config.converters.QNameConverter; |
14 | |
import org.mule.providers.AbstractMessageReceiver; |
15 | |
import org.mule.providers.soap.SoapConstants; |
16 | |
import org.mule.umo.UMOComponent; |
17 | |
import org.mule.umo.UMOException; |
18 | |
import org.mule.umo.endpoint.UMOEndpoint; |
19 | |
import org.mule.umo.lifecycle.InitialisationException; |
20 | |
import org.mule.umo.provider.UMOConnector; |
21 | |
import org.mule.util.ClassUtils; |
22 | |
import org.mule.util.MapUtils; |
23 | |
import org.mule.util.StringUtils; |
24 | |
|
25 | |
import java.net.MalformedURLException; |
26 | |
import java.net.URL; |
27 | |
import java.util.HashMap; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
import javax.xml.namespace.QName; |
32 | |
|
33 | |
import org.codehaus.xfire.annotations.WebAnnotations; |
34 | |
import org.codehaus.xfire.annotations.WebServiceAnnotation; |
35 | |
import org.codehaus.xfire.handler.Handler; |
36 | |
import org.codehaus.xfire.service.Service; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class XFireMessageReceiver extends AbstractMessageReceiver |
45 | |
{ |
46 | |
private static final String PORT_TYPE = "portType"; |
47 | |
|
48 | |
protected XFireConnector connector; |
49 | |
protected Service service; |
50 | |
|
51 | |
protected List serviceInterfaces; |
52 | |
|
53 | |
public XFireMessageReceiver(UMOConnector umoConnector, |
54 | |
UMOComponent component, |
55 | |
UMOEndpoint umoEndpoint) throws InitialisationException |
56 | |
{ |
57 | 86 | super(umoConnector, component, umoEndpoint); |
58 | 86 | connector = (XFireConnector) umoConnector; |
59 | 86 | init(); |
60 | 86 | } |
61 | |
|
62 | |
protected void init() throws InitialisationException |
63 | |
{ |
64 | |
try |
65 | |
{ |
66 | 86 | Map props = new HashMap(component.getDescriptor().getProperties()); |
67 | 86 | props.putAll(endpoint.getProperties()); |
68 | |
|
69 | |
|
70 | 86 | if (props.containsKey(PORT_TYPE)) |
71 | |
{ |
72 | 4 | Object value = props.get(PORT_TYPE); |
73 | 4 | QNameConverter converter = new QNameConverter(true); |
74 | 6 | QName portTypeQName = (QName) converter.convert(QName.class, value); |
75 | 4 | props.put(PORT_TYPE, portTypeQName); |
76 | |
} |
77 | |
|
78 | |
|
79 | 86 | String namespace = (String) component.getDescriptor().getProperties().get( |
80 | |
SoapConstants.SOAP_NAMESPACE_PROPERTY); |
81 | |
|
82 | |
|
83 | 86 | if (connector.isEnableJSR181Annotations()) |
84 | |
{ |
85 | 0 | WebAnnotations wa = (WebAnnotations) ClassUtils.instanciateClass( |
86 | |
XFireConnector.CLASSNAME_ANNOTATIONS, null, this.getClass()); |
87 | 0 | WebServiceAnnotation webServiceAnnotation = wa.getWebServiceAnnotation(component |
88 | |
.getDescriptor().getImplementationClass()); |
89 | 0 | namespace = webServiceAnnotation.getTargetNamespace(); |
90 | |
} |
91 | |
|
92 | 86 | if ((namespace == null) || (namespace.equalsIgnoreCase(""))) |
93 | |
{ |
94 | 86 | namespace = MapUtils.getString(props, "namespace", |
95 | |
XFireConnector.DEFAULT_MULE_NAMESPACE_URI); |
96 | |
} |
97 | |
|
98 | |
|
99 | 86 | if (props.get("createDefaultBindings") != null) |
100 | |
{ |
101 | 8 | props.put("createDefaultBindings", Boolean.valueOf((String) props.get("createDefaultBindings"))); |
102 | |
} |
103 | |
|
104 | 86 | if (props.size() == 0) |
105 | |
{ |
106 | |
|
107 | 66 | props = null; |
108 | |
} |
109 | |
else |
110 | |
{ |
111 | 20 | rewriteProperty(props, PORT_TYPE); |
112 | 20 | rewriteProperty(props, "style"); |
113 | 20 | rewriteProperty(props, "use"); |
114 | 20 | rewriteProperty(props, "createDefaultBindings"); |
115 | 20 | rewriteProperty(props, "soap12Transports"); |
116 | 20 | rewriteProperty(props, "soap11Transports"); |
117 | 20 | rewriteProperty(props, "scope"); |
118 | 20 | rewriteProperty(props, "schemas"); |
119 | |
} |
120 | |
|
121 | 86 | serviceInterfaces = (List) component.getDescriptor().getProperties().get("serviceInterfaces"); |
122 | |
Class exposedInterface; |
123 | |
|
124 | 86 | if (serviceInterfaces == null) |
125 | |
{ |
126 | 86 | exposedInterface = component.getDescriptor().getImplementationClass(); |
127 | |
} |
128 | |
|
129 | |
else |
130 | |
{ |
131 | 0 | String className = (String) serviceInterfaces.get(0); |
132 | 0 | exposedInterface = ClassUtils.loadClass(className, this.getClass()); |
133 | 0 | logger.info(className + " class was used to expose your service"); |
134 | |
|
135 | 0 | if (serviceInterfaces.size() > 1) |
136 | |
{ |
137 | 0 | logger.info("Only the first class was used to expose your method"); |
138 | |
} |
139 | |
} |
140 | |
|
141 | 86 | String wsdlUrl = (String) component.getDescriptor().getProperties().get( |
142 | |
SoapConstants.WSDL_URL_PROPERTY); |
143 | |
|
144 | 86 | if (StringUtils.isBlank(wsdlUrl)) |
145 | |
{ |
146 | 86 | service = connector.getServiceFactory().create(exposedInterface, |
147 | |
component.getDescriptor().getName(), namespace, props); |
148 | |
} |
149 | |
else |
150 | |
{ |
151 | 0 | service = connector.getServiceFactory().create(exposedInterface, |
152 | |
new QName(namespace, component.getDescriptor().getName()), new URL(wsdlUrl), |
153 | |
props); |
154 | |
} |
155 | |
|
156 | 86 | List inList = connector.getServerInHandlers(); |
157 | 86 | if (inList != null) |
158 | |
{ |
159 | 0 | for (int i = 0; i < inList.size(); i++) |
160 | |
{ |
161 | 0 | Class clazz = ClassUtils.loadClass(inList.get(i).toString(), this.getClass()); |
162 | 0 | Handler handler = (Handler) clazz.getConstructor(null).newInstance(null); |
163 | 0 | service.addInHandler(handler); |
164 | |
} |
165 | |
} |
166 | |
|
167 | 86 | boolean sync = endpoint.isSynchronous(); |
168 | |
|
169 | 86 | if (endpoint.getEndpointURI().getScheme().startsWith("http") |
170 | |
|| endpoint.getEndpointURI().getScheme().startsWith("servlet")) |
171 | |
{ |
172 | 86 | sync = true; |
173 | |
} |
174 | 86 | service.setInvoker(new MuleInvoker(this, sync)); |
175 | |
|
176 | |
} |
177 | 0 | catch (UMOException e) |
178 | |
{ |
179 | 0 | throw new InitialisationException(e, this); |
180 | |
} |
181 | 0 | catch (ClassNotFoundException e) |
182 | |
{ |
183 | |
|
184 | |
|
185 | 0 | throw new InitialisationException(e, this); |
186 | |
} |
187 | 0 | catch (MalformedURLException e) |
188 | |
{ |
189 | 0 | throw new InitialisationException(e, this); |
190 | |
} |
191 | 0 | catch (Exception e) |
192 | |
{ |
193 | 0 | throw new InitialisationException(e, this); |
194 | 86 | } |
195 | 86 | } |
196 | |
|
197 | |
protected void doDispose() |
198 | |
{ |
199 | |
|
200 | 86 | } |
201 | |
|
202 | |
public void doConnect() throws Exception |
203 | |
{ |
204 | |
|
205 | 84 | connector.getXfire().getServiceRegistry().register(service); |
206 | 84 | connector.registerReceiverWithMuleService(this, endpoint.getEndpointURI()); |
207 | 84 | } |
208 | |
|
209 | |
public void doDisconnect() throws Exception |
210 | |
{ |
211 | 84 | connector.getXfire().getServiceRegistry().unregister(service); |
212 | 84 | } |
213 | |
|
214 | |
public void doStart() throws UMOException |
215 | |
{ |
216 | |
|
217 | 84 | } |
218 | |
|
219 | |
public void doStop() throws UMOException |
220 | |
{ |
221 | |
|
222 | 84 | } |
223 | |
|
224 | |
protected void rewriteProperty(Map props, String name) |
225 | |
{ |
226 | 160 | if (props.containsKey(name)) |
227 | |
{ |
228 | 20 | Object temp = props.remove(name); |
229 | 20 | props.put("objectServiceFactory." + name, temp); |
230 | |
} |
231 | 160 | } |
232 | |
|
233 | |
} |