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