View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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          //TODO MULE-4952 what is the strategy here for proxy components?
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  }