1 10 11 package org.mule.providers.soap.glue; 12 13 import electric.glue.context.ApplicationContext; 14 import electric.glue.context.ServiceContext; 15 import electric.registry.Registry; 16 import electric.registry.RegistryException; 17 import electric.server.http.HTTP; 18 import electric.service.virtual.VirtualService; 19 import electric.util.Context; 20 import electric.util.interceptor.ReceiveThreadContext; 21 import electric.util.interceptor.SendThreadContext; 22 23 import org.mule.config.MuleProperties; 24 import org.mule.config.i18n.Message; 25 import org.mule.config.i18n.Messages; 26 import org.mule.impl.MuleDescriptor; 27 import org.mule.providers.AbstractMessageReceiver; 28 import org.mule.providers.ConnectException; 29 import org.mule.providers.soap.ServiceProxy; 30 import org.mule.umo.UMOComponent; 31 import org.mule.umo.UMOException; 32 import org.mule.umo.endpoint.UMOEndpoint; 33 import org.mule.umo.lifecycle.InitialisationException; 34 import org.mule.umo.provider.UMOConnector; 35 36 import java.io.IOException ; 37 import java.util.Iterator ; 38 import java.util.Map ; 39 40 48 49 public class GlueMessageReceiver extends AbstractMessageReceiver 50 { 51 private boolean createServer = false; 52 53 public GlueMessageReceiver(UMOConnector connector, 54 UMOComponent component, 55 UMOEndpoint endpoint, 56 Boolean createServer) throws InitialisationException 57 { 58 super(connector, component, endpoint); 59 this.createServer = createServer.booleanValue(); 60 } 61 62 public void doConnect() throws Exception 63 { 64 try 65 { 66 Class [] interfaces = ServiceProxy.getInterfacesForComponent(component); 67 if (interfaces.length == 0) 68 { 69 throw new InitialisationException( 70 new Message("soap", 2, component.getDescriptor().getName()), this); 71 } 72 73 if (!endpoint.isSynchronousSet() && !endpoint.isSynchronous()) 79 { 80 logger.debug("overriding endpoint synchronicity and setting it to true. Web service requests are executed in a single thread"); 81 endpoint.setSynchronous(true); 82 } 83 84 if (createServer) 85 { 86 HTTP.startup(getEndpointURI().getScheme() + "://" + getEndpointURI().getHost() + ":" 87 + getEndpointURI().getPort()); 88 registerContextHeaders(); 89 } 90 91 VirtualService.enable(); 92 VirtualService vService = new VirtualService(interfaces, GlueServiceProxy.createServiceHandler( 93 this, endpoint.isSynchronous())); 94 95 MuleDescriptor desc = (MuleDescriptor)component.getDescriptor(); 98 String serviceName = getEndpointURI().getPath(); 99 if (!serviceName.endsWith("/")) 100 { 101 serviceName += "/"; 102 } 103 serviceName += component.getDescriptor().getName(); 104 desc.addInitialisationCallback(new GlueInitialisationCallback(vService, serviceName, 105 new ServiceContext())); 106 107 } 108 catch (ClassNotFoundException e) 109 { 110 throw new InitialisationException(new Message(Messages.CLASS_X_NOT_FOUND, e.getMessage()), e, 111 this); 112 } 113 catch (UMOException e) 114 { 115 throw new InitialisationException(new Message("soap", 3, component.getDescriptor().getName()), e, 116 this); 117 } 118 catch (Exception e) 119 { 120 throw new InitialisationException(new Message(Messages.FAILED_TO_START_X, "Soap Server"), e, this); 121 } 122 } 123 124 public void doDisconnect() throws Exception 125 { 126 if (createServer) 127 { 128 try 129 { 130 HTTP.shutdown(getEndpointURI().getScheme() + "://" + getEndpointURI().getHost() + ":" 131 + getEndpointURI().getPort()); 132 } 133 catch (IOException e) 134 { 135 throw new ConnectException(e, this); 136 } 137 } 138 } 139 140 protected void registerContextHeaders() 141 { 142 ApplicationContext.addOutboundSoapRequestInterceptor(new SendThreadContext( 143 MuleProperties.MULE_CORRELATION_ID_PROPERTY)); 144 ApplicationContext.addOutboundSoapRequestInterceptor(new SendThreadContext( 145 MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY)); 146 ApplicationContext.addOutboundSoapRequestInterceptor(new SendThreadContext( 147 MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY)); 148 ApplicationContext.addOutboundSoapRequestInterceptor(new SendThreadContext( 149 MuleProperties.MULE_REPLY_TO_PROPERTY, true)); 150 151 ApplicationContext.addInboundSoapRequestInterceptor(new ReceiveThreadContext( 152 MuleProperties.MULE_CORRELATION_ID_PROPERTY)); 153 ApplicationContext.addInboundSoapRequestInterceptor(new ReceiveThreadContext( 154 MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY)); 155 ApplicationContext.addInboundSoapRequestInterceptor(new ReceiveThreadContext( 156 MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY)); 157 ApplicationContext.addInboundSoapRequestInterceptor(new ReceiveThreadContext( 158 MuleProperties.MULE_REPLY_TO_PROPERTY, true)); 159 } 160 161 165 protected void doDispose() 166 { 167 try 168 { 169 Registry.unpublish(component.getDescriptor().getName()); 170 } 171 catch (RegistryException e) 172 { 173 logger.error(new Message(Messages.FAILED_TO_UNREGISTER_X_ON_ENDPOINT_X, component.getDescriptor() 174 .getName(), endpoint.getEndpointURI()), e); 175 } 176 } 177 178 protected Context getContext() 179 { 180 Context c = null; 181 if (endpoint.getProperties() != null) 182 { 183 c = (Context)endpoint.getProperties().get("glueContext"); 184 if (c == null && endpoint.getProperties().size() > 0) 185 { 186 c = new Context(); 187 for (Iterator iterator = endpoint.getProperties().entrySet().iterator(); iterator.hasNext();) 188 { 189 Map.Entry entry = (Map.Entry )iterator.next(); 190 c.addProperty(entry.getKey().toString(), entry.getValue()); 191 } 192 } 193 } 194 return c; 195 } 196 } 197 | Popular Tags |