1
2
3
4
5
6
7 package org.mule.module.cxf.component;
8
9 import org.mule.DefaultMuleEvent;
10 import org.mule.MessageExchangePattern;
11 import org.mule.api.MuleContext;
12 import org.mule.api.MuleEvent;
13 import org.mule.api.MuleMessage;
14 import org.mule.api.endpoint.EndpointBuilder;
15 import org.mule.api.endpoint.OutboundEndpoint;
16 import org.mule.config.i18n.CoreMessages;
17 import org.mule.module.cxf.endpoint.CxfEndpointBuilder;
18
19 public class WebServiceWrapperComponent extends AbstractWebServiceWrapperComponent
20 {
21 private String wsdlPort;
22 private String operation;
23
24 protected MuleMessage doInvoke(MuleEvent event) throws Exception
25 {
26 MuleContext muleContext = event.getMuleContext();
27
28 String tempUrl;
29 if (addressFromMessage)
30 {
31 tempUrl = event.getMessage().getInboundProperty(WS_SERVICE_URL);
32 if (tempUrl == null)
33 {
34 throw new IllegalArgumentException(CoreMessages.propertyIsNotSetOnEvent(WS_SERVICE_URL)
35 .toString());
36 }
37 }
38 else
39 {
40 tempUrl = address;
41 }
42
43 EndpointBuilder endpointBuilder = new CxfEndpointBuilder("cxf:" + tempUrl, muleContext);
44 if (wsdlPort != null)
45 {
46 endpointBuilder.setProperty("port", wsdlPort);
47 }
48 if (operation != null)
49 {
50 endpointBuilder.setProperty("operation", operation);
51
52 }
53
54
55 endpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
56 OutboundEndpoint endpoint = endpointBuilder.buildOutboundEndpoint();
57
58 MuleEvent responseEvent = endpoint.process(new DefaultMuleEvent(event.getMessage(), endpoint,
59 event.getSession()));
60
61 if (responseEvent != null)
62 {
63 return responseEvent.getMessage();
64 }
65 else
66 {
67 return null;
68 }
69 }
70
71 public String getWsdlPort()
72 {
73 return wsdlPort;
74 }
75
76 public void setWsdlPort(String wsdlPort)
77 {
78 this.wsdlPort = wsdlPort;
79 }
80
81 public String getOperation()
82 {
83 return operation;
84 }
85
86 public void setOperation(String operation)
87 {
88 this.operation = operation;
89 }
90
91 }