1 22 package org.objectweb.petals.binding.axis2; 23 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 30 import javax.jbi.component.ComponentContext; 31 import javax.jbi.servicedesc.ServiceEndpoint; 32 import javax.xml.namespace.QName ; 33 34 import org.apache.axis2.AxisFault; 35 import org.apache.axis2.Constants; 36 import org.apache.axis2.context.ConfigurationContext; 37 import org.apache.axis2.description.AxisService; 38 import org.apache.axis2.description.Parameter; 39 import org.apache.axis2.engine.AxisConfiguration; 40 import org.objectweb.petals.binding.axis2.listener.soap.PetalsAxisService; 41 import org.objectweb.petals.component.common.PEtALSComponentSDKException; 42 import org.objectweb.petals.component.common.su.ServiceUnitListener; 43 import org.objectweb.petals.component.common.util.PetalsExtensionsUtil; 44 import org.objectweb.petals.tools.jbicommon.descriptor.Consumes; 45 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor; 46 47 54 public class Axis2BCSUListener implements ServiceUnitListener { 55 56 private ConfigurationContext axisConfigurationContext; 57 58 private ComponentContext componentContext; 59 60 private Logger logger; 61 62 private Map <String , JBIDescriptor> descriptors; 63 64 69 public Axis2BCSUListener(ConfigurationContext axisConfigurationContext, 70 ComponentContext componentContext, Logger logger) { 71 this.axisConfigurationContext = axisConfigurationContext; 72 this.componentContext = componentContext; 73 this.logger = logger; 74 this.descriptors = new HashMap <String , JBIDescriptor>(); 75 } 76 77 84 public void onSUDeployed(String serviceUnitName, String suRootPath, 85 JBIDescriptor descriptor) throws PEtALSComponentSDKException { 86 logger.log(Level.FINE, "Deploying a new AxisService for SU " 87 + serviceUnitName); 88 89 descriptors.put(serviceUnitName, descriptor); 90 } 91 92 97 public void onSUStarted(String serviceUnitName) 98 throws PEtALSComponentSDKException { 99 100 JBIDescriptor descriptor = descriptors.get(serviceUnitName); 101 if (descriptor != null) { 102 List <Consumes> consumesList = descriptor.getServices() 103 .getConsumes(); 104 for (Consumes consumes : consumesList) { 105 registerAxisService(consumes); 106 } 107 } 108 } 109 110 115 public void onSUStopped(String serviceUnitName) 116 throws PEtALSComponentSDKException { 117 118 JBIDescriptor descriptor = descriptors.get(serviceUnitName); 119 if (descriptor != null) { 120 List <Consumes> consumesList = descriptor.getServices() 122 .getConsumes(); 123 for (Consumes consumes : consumesList) { 124 unregisterAxisService(consumes); 125 } 126 } 127 } 128 129 136 public void onSUUndeployed(String serviceUnitName, String suRootPath, 137 JBIDescriptor descriptor) throws PEtALSComponentSDKException { 138 139 descriptors.remove(serviceUnitName); 140 } 141 142 147 private void registerAxisService(Consumes consumes) 148 throws PEtALSComponentSDKException { 149 150 QName serviceQName = consumes.getServiceName(); 151 String endPointName = PetalsExtensionsUtil 152 .extractValueFromKeyValueExtension(consumes.getExtensions(), 153 PetalsExtensionsUtil.ADDRESS); 154 155 logger.log(Level.INFO, "Registering Axis Service : " + endPointName); 156 157 AxisConfiguration axisConfig = axisConfigurationContext 158 .getAxisConfiguration(); 159 160 try { 161 AxisService axisService = null; 162 String consumedEndpoint = consumes.getEndpointName(); 163 164 axisService = axisConfig.getService(endPointName); 166 167 if (axisService == null) { 168 ServiceEndpoint endpoint = componentContext.getEndpoint( 174 serviceQName, consumedEndpoint); 175 176 axisService = new PetalsAxisService(endPointName, 177 componentContext, endpoint); 178 axisService.setTargetNamespace(serviceQName.getNamespaceURI()); 179 axisService.setEndpoint(consumedEndpoint); 180 181 axisService.addParameter(new Parameter(Constants.SERVICE_CLASS, 182 "PetalsReceiver")); 183 184 axisConfig.addService(axisService); 186 } else { 187 logger.log(Level.WARNING, 188 "This service is already registered in Axis : " 189 + axisService.getName()); 190 } 191 } catch (AxisFault e) { 192 throw new PEtALSComponentSDKException( 193 "Can not register Service into Axis context", e); 194 } 195 } 196 197 203 private void unregisterAxisService(Consumes consumes) 204 throws PEtALSComponentSDKException { 205 206 String endPointName = PetalsExtensionsUtil 208 .extractValueFromKeyValueExtension(consumes.getExtensions(), 209 PetalsExtensionsUtil.ADDRESS); 210 211 logger.log(Level.INFO, "Removing Axis service from list : " 212 + endPointName); 213 214 try { 215 AxisService axisService = axisConfigurationContext 217 .getAxisConfiguration().getService(endPointName); 218 219 if (axisService != null) { 220 axisConfigurationContext.getAxisConfiguration().removeService( 221 axisService.getName()); 222 } 223 224 } catch (AxisFault e) { 225 throw new PEtALSComponentSDKException( 226 "Can not remove service from Axis context", e); 227 } 228 } 229 230 } 231 | Popular Tags |