View Javadoc

1   /*
2    * $Id: XFireWsdlMessageDispatcher.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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 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.providers.soap.xfire.wsdl;
12  
13  import org.mule.providers.soap.xfire.XFireMessageDispatcher;
14  import org.mule.umo.endpoint.UMOEndpointURI;
15  import org.mule.umo.endpoint.UMOImmutableEndpoint;
16  import org.mule.util.StringUtils;
17  
18  import java.net.URL;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.codehaus.xfire.XFire;
23  import org.codehaus.xfire.client.Client;
24  import org.codehaus.xfire.service.Service;
25  
26  /**
27   * TODO document
28   */
29  public class XFireWsdlMessageDispatcher extends XFireMessageDispatcher
30  {
31      public static final String DEFAULT_WSDL_TRANSPORT = "org.codehaus.xfire.transport.http.SoapHttpTransport";
32  
33      public XFireWsdlMessageDispatcher(UMOImmutableEndpoint endpoint)
34      {
35          super(endpoint);
36      }
37  
38      // @Override
39      protected void doConnect() throws Exception
40      {
41          try
42          {
43              XFire xfire = connector.getXfire();
44              String wsdlUrl = endpoint.getEndpointURI().getAddress();
45              String serviceName = endpoint.getEndpointURI().getAddress();
46  
47              // If the property specified an alternative WSDL url, use it
48              if (endpoint.getProperty("wsdlUrl") != null && StringUtils.isNotBlank(endpoint.getProperty("wsdlUrl").toString()))
49              {
50                  wsdlUrl = (String) endpoint.getProperty("wsdlUrl");
51              }
52  
53              if (serviceName.indexOf("?") > -1)
54              {
55                  serviceName = serviceName.substring(0, serviceName.lastIndexOf('?'));
56              }
57  
58              Service service = xfire.getServiceRegistry().getService(new QName(serviceName));
59  
60              if (service == null)
61              {
62                  service = new Client(new URL(wsdlUrl)).getService();
63                  service.setName(new QName(serviceName));
64                  xfire.getServiceRegistry().register(service);
65              }
66  
67              try
68              {
69                  this.client = createXFireWsdlClient(endpoint, service, xfire, wsdlUrl);
70              }
71              catch (Exception ex)
72              {
73                  disconnect();
74                  throw ex;
75              }
76          }
77          catch (Exception ex)
78          {
79              disconnect();
80              throw ex;
81          }
82      }
83  
84      protected Client createXFireWsdlClient(UMOImmutableEndpoint endpoint, Service service, XFire xfire, String wsdlUrl) throws Exception
85      {
86          UMOEndpointURI uri = endpoint.getEndpointURI();
87          Client client = new Client(new URL(wsdlUrl));
88          client.setXFire(xfire);
89          client.setEndpointUri(uri.toString());
90          return configureXFireClient(client);
91      }
92  }