View Javadoc

1   /*
2    * $Id: WebServiceWrapperComponent.java 20320 2010-11-24 15:03:31Z 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.transport.soap.axis.component;
12  
13  import org.mule.DefaultMuleEvent;
14  import org.mule.MessageExchangePattern;
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.endpoint.EndpointURIEndpointBuilder;
21  import org.mule.module.cxf.component.AbstractWebServiceWrapperComponent;
22  import org.mule.transport.soap.axis.AxisConnector;
23  
24  import java.util.Map;
25  
26  public class WebServiceWrapperComponent extends AbstractWebServiceWrapperComponent
27  {
28  
29      private String use;
30      private String style;
31      private Map properties;
32  
33      @Override
34      protected Object doInvoke(MuleEvent event) throws Exception
35      {
36          String tempUrl;
37          if (addressFromMessage)
38          {
39              tempUrl = event.getMessage().getInboundProperty(WS_SERVICE_URL);
40              if (tempUrl == null)
41              {
42                  throw new IllegalArgumentException(CoreMessages.propertyIsNotSetOnEvent(WS_SERVICE_URL)
43                      .toString());
44              }
45          }
46          else
47          {
48              tempUrl = address;
49          }
50          MuleMessage message = event.getMessage();
51  
52          if (properties != null && properties.get(AxisConnector.SOAP_METHODS) != null)
53          {
54              message.addProperties((Map) properties.get(AxisConnector.SOAP_METHODS));
55          }
56  
57          EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder("axis:" + tempUrl, muleContext);
58          if (use != null)
59          {
60              endpointBuilder.setProperty(AxisConnector.USE, use);
61          }
62          if (style != null)
63          {
64              endpointBuilder.setProperty(AxisConnector.STYLE, style);
65  
66          }
67          //TODO MULE-4952 what is the strategy here for proxy components?
68          endpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
69  
70          OutboundEndpoint endpoint = endpointBuilder.buildOutboundEndpoint();
71  
72          MuleEvent responseEvent = endpoint.process(new DefaultMuleEvent(event.getMessage(), endpoint,
73              event.getSession()));
74  
75          if (responseEvent != null)
76          {
77              return responseEvent.getMessage();
78          }
79          else
80          {
81              return null;
82          }
83      }
84  
85      public String getUse()
86      {
87          return use;
88      }
89  
90      public void setUse(String use)
91      {
92          this.use = use;
93      }
94  
95      public String getStyle()
96      {
97          return style;
98      }
99  
100     public void setStyle(String style)
101     {
102         this.style = style;
103     }
104 
105     public Map getProperties()
106     {
107         return properties;
108     }
109 
110     public void setProperties(Map properties)
111     {
112         this.properties = properties;
113     }
114 
115 }