KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > axis > wsdl > AxisWsdlMessageDispatcher


1 /*
2  * $Id: AxisWsdlMessageDispatcher.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.soap.axis.wsdl;
12
13 import org.apache.axis.client.AxisClient;
14 import org.apache.axis.client.Service;
15 import org.apache.axis.wsdl.gen.Parser;
16 import org.apache.axis.wsdl.symbolTable.ServiceEntry;
17 import org.apache.axis.wsdl.symbolTable.SymTabEntry;
18 import org.mule.providers.soap.SoapConstants;
19 import org.mule.providers.soap.axis.AxisMessageDispatcher;
20 import org.mule.umo.UMOEvent;
21 import org.mule.umo.endpoint.UMOImmutableEndpoint;
22
23 import javax.xml.namespace.QName JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 /**
31  * Creates and Axis client services from WSDL and invokes it
32  *
33  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
34  * @version $Revision: 3798 $
35  */

36 public class AxisWsdlMessageDispatcher extends AxisMessageDispatcher
37 {
38
39     public AxisWsdlMessageDispatcher(UMOImmutableEndpoint endpoint)
40     {
41         super(endpoint);
42     }
43
44     protected Service createService(UMOEvent event) throws Exception JavaDoc
45     {
46         String JavaDoc wsdlUrl = event.getEndpoint().getEndpointURI().getAddress();
47         // Parse the wsdl
48
Parser parser = new Parser();
49         if (event.getEndpoint().getEndpointURI().getUserInfo() != null)
50         {
51             parser.setUsername(event.getEndpoint().getEndpointURI().getUsername());
52             parser.setPassword(event.getEndpoint().getEndpointURI().getPassword());
53         }
54         parser.run(wsdlUrl);
55         // Retrieves the defined services
56
Map JavaDoc map = parser.getSymbolTable().getHashMap();
57         List JavaDoc entries = new ArrayList JavaDoc();
58         for (Iterator JavaDoc it = map.entrySet().iterator(); it.hasNext();)
59         {
60             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
61             Vector JavaDoc v = (Vector JavaDoc)entry.getValue();
62             for (Iterator JavaDoc it2 = v.iterator(); it2.hasNext();)
63             {
64                 SymTabEntry e = (SymTabEntry)it2.next();
65                 if (ServiceEntry.class.isInstance(e))
66                 {
67                     entries.add(entry.getKey());
68                 }
69             }
70         }
71         // Currently, only one service should be defined
72
if (entries.size() != 1)
73         {
74             throw new Exception JavaDoc("Need one and only one service entry, found " + entries.size());
75         }
76         // Create the axis service
77
Service service = new Service(parser, (QName JavaDoc)entries.get(0));
78
79         service.setEngineConfiguration(clientConfig);
80         service.setEngine(new AxisClient(clientConfig));
81
82         // Really the Axis Client service should set this stuff
83
event.getMessage().setProperty(SoapConstants.METHOD_NAMESPACE_PROPERTY,
84             parser.getCurrentDefinition().getTargetNamespace());
85         // Todo how can we autogenerate the named params from the WSDL?
86
return service;
87     }
88 }
89
Popular Tags