1 17 package org.apache.servicemix.bpe; 18 19 import java.io.File ; 20 import java.io.FilenameFilter ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.jbi.management.DeploymentException; 26 import javax.wsdl.BindingFault; 27 import javax.wsdl.BindingInput; 28 import javax.wsdl.BindingOperation; 29 import javax.wsdl.BindingOutput; 30 import javax.wsdl.Definition; 31 import javax.wsdl.Import; 32 import javax.wsdl.Message; 33 import javax.wsdl.Port; 34 import javax.wsdl.Service; 35 import javax.wsdl.WSDLException; 36 import javax.wsdl.extensions.ExtensionRegistry; 37 import javax.wsdl.factory.WSDLFactory; 38 import javax.wsdl.xml.WSDLReader; 39 import javax.wsdl.xml.WSDLWriter; 40 41 import org.apache.ode.bpe.bped.DeployTypeEnum; 42 import org.apache.ode.bpe.bped.EventDirector; 43 import org.apache.ode.bpe.bped.IDeployer; 44 import org.apache.ode.bpe.wsdl.extensions.BPEAction; 45 import org.apache.ode.bpe.wsdl.extensions.BPEActionSerializer; 46 import org.apache.ode.bpe.wsdl.extensions.BPEFault; 47 import org.apache.ode.bpe.wsdl.extensions.BPEFaultSerializer; 48 import org.apache.ode.bpe.wsdl.extensions.BPEInput; 49 import org.apache.ode.bpe.wsdl.extensions.BPEInputSerializer; 50 import org.apache.ode.bpe.wsdl.extensions.BPELProperty; 51 import org.apache.ode.bpe.wsdl.extensions.BPELPropertyAlias; 52 import org.apache.ode.bpe.wsdl.extensions.BPELPropertyAliasSerializer; 53 import org.apache.ode.bpe.wsdl.extensions.BPELPropertySerializer; 54 import org.apache.ode.bpe.wsdl.extensions.BPEOutput; 55 import org.apache.ode.bpe.wsdl.extensions.BPEOutputSerializer; 56 import org.apache.ode.bpe.wsdl.extensions.BPEVariableMap; 57 import org.apache.ode.bpe.wsdl.extensions.BPEVariableMapSerializer; 58 import org.apache.ode.bpe.wsdl.extensions.ExtentionConstants; 59 import org.apache.ode.bpe.deployment.bpel.BPELDefinitionKey; 60 import org.apache.servicemix.bpe.util.FileSystemJarInputStream; 61 import org.apache.servicemix.common.AbstractDeployer; 62 import org.apache.servicemix.common.ServiceUnit; 63 import org.apache.servicemix.common.tools.wsdl.WSDLFlattener; 64 import org.w3c.dom.Document ; 65 66 import com.ibm.wsdl.Constants; 67 68 public class BPEDeployer extends AbstractDeployer { 69 70 protected FilenameFilter filter; 71 72 public BPEDeployer(BPEComponent component) { 73 super(component); 74 filter = new BpelFilter(); 75 } 76 77 public boolean canDeploy(String serviceUnitName, String serviceUnitRootPath) { 78 File [] bpels = new File (serviceUnitRootPath).listFiles(filter); 79 return bpels != null && bpels.length == 1; 80 } 81 82 public ServiceUnit deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException { 83 try { 84 EventDirector ed = ((BPEComponent) component).getEventDirector(); 85 IDeployer deployer = ed.getDeployer(DeployTypeEnum.BPEL); 86 Collection defKeys = deployer.loadDefinition(new FileSystemJarInputStream(new File (serviceUnitRootPath)), false); 87 BPEServiceUnit su = new BPEServiceUnit(); 89 su.setComponent(component); 90 su.setName(serviceUnitName); 91 su.setRootPath(serviceUnitRootPath); 92 su.setDefinitionKeys(defKeys); 93 Definition rootDef = loadMainWsdl(serviceUnitRootPath); 94 checkDefinition(rootDef, true); 95 su.setDefinition(rootDef); 96 WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter(); 97 WSDLFlattener flattener = new WSDLFlattener(rootDef); 98 for (Iterator it = rootDef.getServices().values().iterator(); it.hasNext();) { 99 Service svc = (Service) it.next(); 100 for (Iterator it2 = svc.getPorts().values().iterator(); it2.hasNext();) { 101 Port pt = (Port) it2.next(); 102 BPEEndpoint ep = new BPEEndpoint(); 103 ep.setServiceUnit(su); 104 ep.setInterfaceName(pt.getBinding().getPortType().getQName()); 105 ep.setService(svc.getQName()); 106 ep.setEndpoint(pt.getName()); 107 Definition def = flattener.getDefinition(ep.getInterfaceName()); 108 Document desc = writer.getDocument(def); 109 ep.setDefinition(def); 110 ep.setDescription(desc); 111 su.addEndpoint(ep); 113 } 114 } 115 return su; 116 } catch (DeploymentException e) { 117 throw e; 118 } catch (Exception e) { 119 throw new DeploymentException(e); 120 } 121 } 122 123 public void undeploy(ServiceUnit su) throws DeploymentException { 124 try { 125 BPEServiceUnit bpeSU = (BPEServiceUnit)su; 126 EventDirector ed = ((BPEComponent) component).getEventDirector(); 127 IDeployer deployer = ed.getDeployer(DeployTypeEnum.BPEL); 128 for (Iterator i = bpeSU.getDefinitionKeys().iterator(); i.hasNext(); ) { 129 deployer.removeDefinition(((BPELDefinitionKey)i.next()).getKey()); 130 } 131 su.shutDown(); 132 } catch (DeploymentException e) { 133 throw e; 134 } catch (Exception e) { 135 throw new DeploymentException(e); 136 } 137 } 138 139 protected void checkDefinition(Definition rootDef, boolean main) throws DeploymentException { 140 Collection msgs = rootDef.getMessages().values(); 142 for (Iterator iter = msgs.iterator(); iter.hasNext();) { 143 Message msg = (Message) iter.next(); 144 if (msg.isUndefined()) { 145 throw failure("deploy", 146 "WSDL Message '" + msg.getQName() + "' is undefined. Check namespaces.", null); 147 } 148 if (msg.getParts().size() > 1) { 149 throw failure("deploy", 150 "WSDL Message '" + msg.getQName() + "' has more than one part", null); 151 } 152 } 153 Collection imports = rootDef.getImports().values(); 155 for (Iterator iter = imports.iterator(); iter.hasNext();) { 156 List imps = (List ) iter.next(); 157 for (Iterator iterator = imps.iterator(); iterator.hasNext();) { 158 Import imp = (Import) iterator.next(); 159 checkDefinition(imp.getDefinition(), false); 160 } 161 } 162 } 163 164 private Definition loadMainWsdl(String serviceUnitRootPath) throws WSDLException { 165 File [] bpels = new File (serviceUnitRootPath).listFiles(filter); 166 String bpel = bpels[0].getAbsoluteFile().toURI().toString(); 167 String wsdl = bpel.substring(0, bpel.length() - 4) + "wsdl"; 168 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); 169 reader.setFeature(Constants.FEATURE_VERBOSE, false); 170 reader.setExtensionRegistry(getExtentionRegistry()); 171 Definition ret = reader.readWSDL(null, wsdl); 173 return ret; 174 } 175 176 private ExtensionRegistry getExtentionRegistry() { 177 178 ExtensionRegistry er = new com.ibm.wsdl.extensions.PopulatedExtensionRegistry(); 182 183 BPELPropertySerializer bpelPropSerializer = new BPELPropertySerializer(); 184 BPELPropertyAliasSerializer bpelPropAliasSerializer = new BPELPropertyAliasSerializer(); 185 BPEActionSerializer bpeActionSerializer = new BPEActionSerializer(); 186 BPEInputSerializer bpeInputSerializer = new BPEInputSerializer(); 187 BPEOutputSerializer bpeOutputSerializer = new BPEOutputSerializer(); 188 BPEFaultSerializer bpeFaultSerializer = new BPEFaultSerializer(); 189 BPEVariableMapSerializer bpeVariableSerializer = new BPEVariableMapSerializer(); 190 191 er.registerSerializer(Definition.class, 193 ExtentionConstants.Q_ELEM_BPEL_PROPERTY, 194 bpelPropSerializer); 195 er.registerDeserializer(Definition.class, 196 ExtentionConstants.Q_ELEM_BPEL_PROPERTY, 197 bpelPropSerializer); 198 er.mapExtensionTypes(Definition.class, 199 ExtentionConstants.Q_ELEM_BPEL_PROPERTY, 200 BPELProperty.class); 201 er.registerSerializer(Definition.class, 202 ExtentionConstants.Q_ELEM_BPEL_PROPERTY_ALIAS, 203 bpelPropAliasSerializer); 204 er.registerDeserializer(Definition.class, 205 ExtentionConstants.Q_ELEM_BPEL_PROPERTY_ALIAS, 206 bpelPropAliasSerializer); 207 er.mapExtensionTypes(Definition.class, 208 ExtentionConstants.Q_ELEM_BPEL_PROPERTY_ALIAS, 209 BPELPropertyAlias.class); 210 211 er.registerSerializer(BindingOperation.class, 213 ExtentionConstants.Q_ELEM_BPE_ACTION, 214 bpeActionSerializer); 215 er.registerDeserializer(BindingOperation.class, 216 ExtentionConstants.Q_ELEM_BPE_ACTION, 217 bpeActionSerializer); 218 er.mapExtensionTypes(BindingOperation.class, 219 ExtentionConstants.Q_ELEM_BPE_ACTION, 220 BPEAction.class); 221 er.registerSerializer(BindingInput.class, 222 ExtentionConstants.Q_ELEM_BPE_INPUT, 223 bpeInputSerializer); 224 er.registerDeserializer(BindingInput.class, 225 ExtentionConstants.Q_ELEM_BPE_INPUT, 226 bpeInputSerializer); 227 er.mapExtensionTypes(BindingInput.class, 228 ExtentionConstants.Q_ELEM_BPE_INPUT, 229 BPEInput.class); 230 er.registerSerializer(BindingOutput.class, 231 ExtentionConstants.Q_ELEM_BPE_OUTPUT, 232 bpeOutputSerializer); 233 er.registerDeserializer(BindingOutput.class, 234 ExtentionConstants.Q_ELEM_BPE_OUTPUT, 235 bpeOutputSerializer); 236 er.mapExtensionTypes(BindingOutput.class, 237 ExtentionConstants.Q_ELEM_BPE_OUTPUT, 238 BPEOutput.class); 239 240 er.registerSerializer(BindingFault.class, 241 ExtentionConstants.Q_ELEM_BPE_FAULT, 242 bpeFaultSerializer); 243 er.registerDeserializer(BindingFault.class, 244 ExtentionConstants.Q_ELEM_BPE_FAULT, 245 bpeFaultSerializer); 246 er.mapExtensionTypes(BindingFault.class, 247 ExtentionConstants.Q_ELEM_BPE_FAULT, 248 BPEFault.class); 249 250 er.registerSerializer(Definition.class, 251 ExtentionConstants.Q_ELEM_BPE_VAR, 252 bpeVariableSerializer); 253 er.registerDeserializer(Definition.class, 254 ExtentionConstants.Q_ELEM_BPE_VAR, 255 bpeVariableSerializer); 256 er.mapExtensionTypes(Definition.class, 257 ExtentionConstants.Q_ELEM_BPE_VAR, 258 BPEVariableMap.class); 259 260 return er; 261 } 262 263 public static class BpelFilter implements FilenameFilter { 264 265 public boolean accept(File dir, String name) { 266 return name.endsWith(".bpel"); 267 } 268 269 } 270 } 271 | Popular Tags |