View Javadoc

1   /*
2    * $Id: WebServiceWrapperComponent.java 12228 2008-07-03 00:26:59Z aguenther $
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.DefaultMuleEvent;
14  import org.mule.MessageExchangePattern;
15  import org.mule.api.MuleContext;
16  import org.mule.api.MuleEvent;
17  import org.mule.api.MuleMessage;
18  import org.mule.api.endpoint.EndpointBuilder;
19  import org.mule.api.endpoint.OutboundEndpoint;
20  import org.mule.config.i18n.CoreMessages;
21  import org.mule.module.cxf.endpoint.CxfEndpointBuilder;
22  
23  public class WebServiceWrapperComponent extends AbstractWebServiceWrapperComponent
24  {
25      private String wsdlPort;
26      private String operation;
27  
28      protected MuleMessage doInvoke(MuleEvent event) throws Exception
29      {
30          MuleContext muleContext = event.getMuleContext();
31  
32          String tempUrl;
33          if (addressFromMessage)
34          {
35              tempUrl = event.getMessage().getInboundProperty(WS_SERVICE_URL);
36              if (tempUrl == null)
37              {
38                  throw new IllegalArgumentException(CoreMessages.propertyIsNotSetOnEvent(WS_SERVICE_URL)
39                      .toString());
40              }
41          }
42          else
43          {
44              tempUrl = address;
45          }
46  
47          EndpointBuilder endpointBuilder = new CxfEndpointBuilder("cxf:" + tempUrl, muleContext);
48          if (wsdlPort != null)
49          {
50              endpointBuilder.setProperty("port", wsdlPort);
51          }
52          if (operation != null)
53          {
54              endpointBuilder.setProperty("operation", operation);
55  
56          }
57  
58          //TODO MULE-4952 what is the strategy here for proxy components?
59          endpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
60          OutboundEndpoint endpoint = endpointBuilder.buildOutboundEndpoint();
61          
62          MuleEvent responseEvent = endpoint.process(new DefaultMuleEvent(event.getMessage(), endpoint,
63              event.getSession()));
64  
65          if (responseEvent != null)
66          {
67              return responseEvent.getMessage();
68          }
69          else
70          {
71              return null;
72          }
73      }
74  
75      public String getWsdlPort()
76      {
77          return wsdlPort;
78      }
79  
80      public void setWsdlPort(String wsdlPort)
81      {
82          this.wsdlPort = wsdlPort;
83      }
84  
85      public String getOperation()
86      {
87          return operation;
88      }
89  
90      public void setOperation(String operation)
91      {
92          this.operation = operation;
93      }
94  
95  }