View Javadoc

1   /*
2    * $Id: AxisWsdlMessageDispatcher.java 19191 2010-08-25 21:05:23Z tcarlson $
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.wsdl;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.endpoint.OutboundEndpoint;
15  import org.mule.module.cxf.SoapConstants;
16  import org.mule.transport.soap.axis.AxisMessageDispatcher;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Vector;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.apache.axis.client.AxisClient;
27  import org.apache.axis.client.Service;
28  import org.apache.axis.wsdl.gen.Parser;
29  import org.apache.axis.wsdl.symbolTable.ServiceEntry;
30  import org.apache.axis.wsdl.symbolTable.SymTabEntry;
31  
32  /**
33   * Creates and Axis client services from WSDL and invokes it.
34   */
35  public class AxisWsdlMessageDispatcher extends AxisMessageDispatcher
36  {
37  
38      public AxisWsdlMessageDispatcher(OutboundEndpoint endpoint)
39      {
40          super(endpoint);
41      }
42  
43      protected Service createService(MuleEvent event) throws Exception
44      {
45          String wsdlUrl = event.getEndpoint().getEndpointURI().getAddress();
46          // Parse the wsdl
47          Parser parser = new Parser();
48          if (event.getEndpoint().getEndpointURI().getUserInfo() != null)
49          {
50              parser.setUsername(event.getEndpoint().getEndpointURI().getUser());
51              parser.setPassword(event.getEndpoint().getEndpointURI().getPassword());
52          }
53          parser.run(wsdlUrl);
54          // Retrieves the defined services
55          Map map = parser.getSymbolTable().getHashMap();
56          List entries = new ArrayList();
57          for (Iterator it = map.entrySet().iterator(); it.hasNext();)
58          {
59              Map.Entry entry = (Map.Entry)it.next();
60              Vector v = (Vector)entry.getValue();
61              for (Iterator it2 = v.iterator(); it2.hasNext();)
62              {
63                  SymTabEntry e = (SymTabEntry)it2.next();
64                  if (ServiceEntry.class.isInstance(e))
65                  {
66                      entries.add(entry.getKey());
67                  }
68              }
69          }
70          // Currently, only one service should be defined
71          if (entries.size() != 1)
72          {
73              throw new Exception("Need one and only one service entry, found " + entries.size());
74          }
75          // Create the axis service
76          Service service = new Service(parser, (QName)entries.get(0));
77  
78          service.setEngineConfiguration(clientConfig);
79          service.setEngine(new AxisClient(clientConfig));
80  
81          // Really the Axis Client service should set this stuff
82          event.getMessage().setOutboundProperty(SoapConstants.METHOD_NAMESPACE_PROPERTY,
83                                                 parser.getCurrentDefinition().getTargetNamespace());
84          // Todo how can we autogenerate the named params from the WSDL?
85          return service;
86      }
87  }