View Javadoc

1   /*
2    * $Id: WebServiceWrapperComponent.java 22156 2011-06-08 21:36:30Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf.component;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleContext;
15  import org.mule.api.MuleEvent;
16  import org.mule.api.MuleMessage;
17  import org.mule.api.endpoint.EndpointBuilder;
18  import org.mule.api.endpoint.OutboundEndpoint;
19  import org.mule.config.i18n.CoreMessages;
20  import org.mule.module.cxf.endpoint.CxfEndpointBuilder;
21  
22  public class WebServiceWrapperComponent extends AbstractWebServiceWrapperComponent
23  {
24      private String wsdlPort;
25      private String operation;
26  
27      protected MuleMessage doInvoke(MuleEvent event) throws Exception
28      {
29          MuleContext muleContext = event.getMuleContext();
30  
31          String tempUrl;
32          if (addressFromMessage)
33          {
34              tempUrl = event.getMessage().getInboundProperty(WS_SERVICE_URL);
35              if (tempUrl == null)
36              {
37                  throw new IllegalArgumentException(CoreMessages.propertyIsNotSetOnEvent(WS_SERVICE_URL)
38                      .toString());
39              }
40          }
41          else
42          {
43              tempUrl = address;
44          }
45  
46          EndpointBuilder endpointBuilder = new CxfEndpointBuilder("cxf:" + tempUrl, muleContext);
47          if (wsdlPort != null)
48          {
49              endpointBuilder.setProperty("port", wsdlPort);
50          }
51          if (operation != null)
52          {
53              endpointBuilder.setProperty("operation", operation);
54  
55          }
56  
57          //TODO MULE-4952 what is the strategy here for proxy components?
58          endpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
59          OutboundEndpoint endpoint = endpointBuilder.buildOutboundEndpoint();
60          
61          MuleEvent responseEvent = endpoint.process(event);
62  
63          if (responseEvent != null)
64          {
65              return responseEvent.getMessage();
66          }
67          else
68          {
69              return null;
70          }
71      }
72  
73      public String getWsdlPort()
74      {
75          return wsdlPort;
76      }
77  
78      public void setWsdlPort(String wsdlPort)
79      {
80          this.wsdlPort = wsdlPort;
81      }
82  
83      public String getOperation()
84      {
85          return operation;
86      }
87  
88      public void setOperation(String operation)
89      {
90          this.operation = operation;
91      }
92  
93  }