1 10 11 package org.mule.providers.soap.xfire; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import javax.xml.namespace.QName ; 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 38 public class XFireMessageReceiver extends AbstractMessageReceiver 39 { 40 41 protected XFireConnector connector; 42 protected Service service; 43 44 protected List 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 props = new HashMap (component.getDescriptor().getProperties()); 60 props.putAll(endpoint.getProperties()); 61 62 String namespace = (String )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 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 )component.getDescriptor().getProperties().get( 89 "serviceInterfaces"); 90 Class exposedInterface; 91 92 if (serviceInterfaces == null) 93 exposedInterface = component.getDescriptor().getImplementationClass(); 94 95 else 96 { 97 String className = (String )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 wsdlUrl = (String )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 (namespace, component.getDescriptor().getName()), new URL (wsdlUrl), 119 props); 120 } 121 122 boolean sync = endpoint.isSynchronous(); 123 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 e) 137 { 138 throw new InitialisationException(e, this); 141 } 142 catch (MalformedURLException e) 143 { 144 throw new InitialisationException(e, this); 145 } 146 147 } 148 149 protected void rewriteProperty(Map props, String name) 150 { 151 Object 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 160 { 161 connector.getXfire().getServiceRegistry().register(service); 163 connector.registerReceiverWithMuleService(this, endpoint.getEndpointURI()); 164 } 165 166 public void doDisconnect() throws Exception 167 { 168 connector.getXfire().getServiceRegistry().unregister(service); 169 } 170 } 171 | Popular Tags |