KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > xfire > XFireMessageReceiver


1 /*
2  * $Id: XFireMessageReceiver.java 4323 2006-12-19 15:55:15Z lajos $
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.xfire;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import javax.xml.namespace.QName JavaDoc;
20
21 import org.codehaus.xfire.service.Service;
22 import org.mule.providers.AbstractMessageReceiver;
23 import org.mule.providers.soap.SoapConstants;
24 import org.mule.umo.UMOComponent;
25 import org.mule.umo.UMOException;
26 import org.mule.umo.endpoint.UMOEndpoint;
27 import org.mule.umo.lifecycle.InitialisationException;
28 import org.mule.umo.provider.UMOConnector;
29 import org.mule.util.MapUtils;
30 import org.mule.util.StringUtils;
31
32 /**
33  * Used to register an Xfire endpoint registered with Mule and associated with a
34  * component This receiver is responsible or registering the transport endpoint i.e.
35  * http:// as well as managing the association of this transport endpoint with the
36  * Xfire service.
37  */

38 public class XFireMessageReceiver extends AbstractMessageReceiver
39 {
40
41     protected XFireConnector connector;
42     protected Service service;
43
44     protected List JavaDoc serviceInterfaces;
45
46     public XFireMessageReceiver(UMOConnector umoConnector,
47                                 UMOComponent component,
48                                 UMOEndpoint umoEndpoint) throws InitialisationException
49     {
50         super(umoConnector, component, umoEndpoint);
51         connector = (XFireConnector)umoConnector;
52         init();
53     }
54
55     protected void init() throws InitialisationException
56     {
57         try
58         {
59             Map JavaDoc props = new HashMap JavaDoc(component.getDescriptor().getProperties());
60             props.putAll(endpoint.getProperties());
61
62             // check if there is the namespace property on the component
63
String JavaDoc namespace = (String JavaDoc)component.getDescriptor().getProperties().get(
64                 SoapConstants.SOAP_NAMESPACE_PROPERTY);
65             if (namespace == null)
66             {
67                 namespace = MapUtils.getString(props, "namespace",
68                     XFireConnector.DEFAULT_MULE_NAMESPACE_URI);
69             }
70
71             if (props.size() == 0)
72             {
73                 // Xfire checks that properties are null rather than empty
74
props = null;
75             }
76             else
77             {
78                 rewriteProperty(props, "portType");
79                 rewriteProperty(props, "style");
80                 rewriteProperty(props, "use");
81                 rewriteProperty(props, "createDefaultBindings");
82                 rewriteProperty(props, "soap12Transports");
83                 rewriteProperty(props, "soap11Transports");
84                 rewriteProperty(props, "scope");
85                 rewriteProperty(props, "schemas");
86             }
87
88             serviceInterfaces = (List JavaDoc)component.getDescriptor().getProperties().get(
89                 "serviceInterfaces");
90             Class JavaDoc exposedInterface;
91
92             if (serviceInterfaces == null)
93                 exposedInterface = component.getDescriptor().getImplementationClass();
94
95             else
96             {
97                 String JavaDoc className = (String JavaDoc)serviceInterfaces.get(0);
98                 exposedInterface = Class.forName(className);
99                 logger.info(className + " class was used to expose your service");
100
101                 if (serviceInterfaces.size() > 1)
102                 {
103                     logger.info("Only the first class was used to expose your method");
104                 }
105             }
106
107             String JavaDoc wsdlUrl = (String JavaDoc)component.getDescriptor().getProperties().get(
108                 SoapConstants.WSDL_URL_PROPERTY);
109
110             if (StringUtils.isBlank(wsdlUrl))
111             {
112                 service = connector.getServiceFactory().create(exposedInterface,
113                     component.getDescriptor().getName(), namespace, props);
114             }
115             else
116             {
117                 service = connector.getServiceFactory().create(exposedInterface,
118                     new QName JavaDoc(namespace, component.getDescriptor().getName()), new URL JavaDoc(wsdlUrl),
119                     props);
120             }
121
122             boolean sync = endpoint.isSynchronous();
123             // default to synchronous if using http
124
if (endpoint.getEndpointURI().getScheme().startsWith("http")
125                 || endpoint.getEndpointURI().getScheme().startsWith("servlet"))
126             {
127                 sync = true;
128             }
129             service.setInvoker(new MuleInvoker(this, sync));
130
131         }
132         catch (UMOException e)
133         {
134             throw new InitialisationException(e, this);
135         }
136         catch (ClassNotFoundException JavaDoc e)
137         {
138             // will be thrown in the case that the forName() does
139
// not find the class to load
140
throw new InitialisationException(e, this);
141         }
142         catch (MalformedURLException JavaDoc e)
143         {
144             throw new InitialisationException(e, this);
145         }
146
147     }
148
149     protected void rewriteProperty(Map JavaDoc props, String JavaDoc name)
150     {
151         Object JavaDoc temp = null;
152         if (props.containsKey(name))
153         {
154             temp = props.remove(name);
155             props.put("objectServiceFactory." + name, temp);
156         }
157     }
158
159     public void doConnect() throws Exception JavaDoc
160     {
161         // Tell the Xfire registry about our new service.
162
connector.getXfire().getServiceRegistry().register(service);
163         connector.registerReceiverWithMuleService(this, endpoint.getEndpointURI());
164     }
165
166     public void doDisconnect() throws Exception JavaDoc
167     {
168         connector.getXfire().getServiceRegistry().unregister(service);
169     }
170 }
171
Popular Tags