/** * Loads nested schema type definitions from wsdl. * * @throws IOException * @throws WSDLException * @throws TransformerFactoryConfigurationError * @throws TransformerException * @throws TransformerConfigurationException */ private void loadSchemas() throws WSDLException, IOException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError { Definition definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getFile().getAbsolutePath()); Types types = definition.getTypes(); List<?> schemaTypes = types.getExtensibilityElements(); for (Object schemaObject : schemaTypes) { if (schemaObject instanceof SchemaImpl) { SchemaImpl schema = (SchemaImpl) schemaObject; inheritNamespaces(schema, definition); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Source source = new DOMSource(schema.getElement()); Result result = new StreamResult(bos); TransformerFactory.newInstance().newTransformer().transform(source, result); Resource schemaResource = new ByteArrayResource(bos.toByteArray()); schemas.add(schemaResource); if (definition .getTargetNamespace() .equals(schema.getElement().getAttribute("targetNamespace"))) { setXsd(schemaResource); } } else { log.warn("Found unsupported schema type implementation " + schemaObject.getClass()); } } }
/** {@inheritDoc} */ @Override public void createServiceImplementationFromWSDL( Role role, java.util.List<Role> refRoles, ProtocolModel behaviour, String wsdlPath, String wsdlLocation, java.util.List<String> refWsdlPaths, String srcFolder, ResourceLocator locator) throws Exception { super.createServiceImplementationFromWSDL( role, refRoles, behaviour, wsdlPath, wsdlLocation, refWsdlPaths, srcFolder, locator); // Process the service implementation class javax.wsdl.Definition defn = getWSDLReader().readWSDL(wsdlPath); if (defn != null) { // Use the namespace to obtain a Java package String pack = JavaGeneratorUtil.getJavaPackage(defn.getTargetNamespace()); String folder = pack.replace('.', java.io.File.separatorChar); @SuppressWarnings("unchecked") java.util.Iterator<PortType> portTypes = defn.getPortTypes().values().iterator(); while (portTypes.hasNext()) { PortType portType = portTypes.next(); java.io.File f = new java.io.File( srcFolder + java.io.File.separatorChar + folder + java.io.File.separatorChar + portType.getQName().getLocalPart() + "Impl.java"); if (f.exists()) { makeSwitchyardService(f, portType, srcFolder); addServiceReferencesToImplementation(f, role, refRoles, refWsdlPaths, srcFolder); addServiceBehaviour(f, role, refRoles, behaviour, srcFolder, locator); } else { logger.severe("Service file '" + f.getAbsolutePath() + "' does not exist"); } } removeWebServiceAndClientAnnotations(wsdlPath, srcFolder); } else { logger.severe("Failed to retrieve WSDL definition '" + wsdlPath + "'"); } }
public FWSDL(File wsdlFile) throws MalformedURLException, Exception { log.info("Reading WSDL definition from " + wsdlFile); Definition wsdlDef = new WSDLReaderImpl().readWSDL(wsdlFile.getAbsolutePath()); Map<?, ?> wsdlNamespaces = wsdlDef.getNamespaces(); if (wsdlDef.getTypes() != null) { List<?> exEls = wsdlDef.getTypes().getExtensibilityElements(); for (int i = 0; i < exEls.size(); i++) { Object a = exEls.get(i); /* Ignore Types != an XML Schema */ if (javax.wsdl.extensions.schema.Schema.class.isAssignableFrom(a.getClass())) { javax.wsdl.extensions.schema.Schema containedSchema = (javax.wsdl.extensions.schema.Schema) a; log.debug("Found XMLSchema in WSDL: " + containedSchema); /* This is the root node of the XML Schema tree */ Element schemaElement = containedSchema.getElement(); /* * Go through all parent namespace declarations and copy * them into the tree of the XMLSchema. * (probably a little hacky) */ for (Object key : wsdlNamespaces.keySet()) { String nsShort = (String) key; String nsLong = (String) wsdlNamespaces.get(key); if (schemaElement.getAttribute("xmlns:" + nsShort).length() == 0) { schemaElement.setAttribute("xmlns:" + nsShort, nsLong); } } /* Fall back on global defininiton */ if (schemaElement.getAttribute("targetNamespace").length() == 0) { schemaElement.setAttribute("targetNamespace", wsdlDef.getTargetNamespace()); } /* * TODO: more things to take care of when cutting out the * schema? */ Schema schemaDocument = SchemaDocument.Factory.parse(schemaElement).getSchema(); log.debug("Adding schema to FSchema: " + schemaDocument); schema.addSchema(schemaDocument, wsdlFile.toURI()); } // log.debug("Ignoring unknown ExtensibilityElement in WSDL (type: " + a.getClass() + ") --> // " + a); } } }
public static EprMetaData getBindingForTypeId(String repId, Definition wsdlDef) { LOG.log( Level.FINE, "RepositoryId " + repId + ", wsdl namespace " + wsdlDef.getTargetNamespace()); EprMetaData ret = new EprMetaData(); Collection<Binding> bindings = CastUtils.cast(wsdlDef.getBindings().values()); for (Binding b : bindings) { List<?> extElements = b.getExtensibilityElements(); // Get the list of all extensibility elements for (Iterator<?> extIter = extElements.iterator(); extIter.hasNext(); ) { java.lang.Object element = extIter.next(); // Find a binding type so we can check against its repository ID if (element instanceof BindingType) { BindingType type = (BindingType) element; if (repId.equals(type.getRepositoryID())) { ret.setCandidateWsdlDef(wsdlDef); ret.setBinding(b); return ret; } } } } if (!ret.isValid()) { // recursivly check imports Iterator<?> importLists = wsdlDef.getImports().values().iterator(); while (importLists.hasNext()) { List<?> imports = (List<?>) importLists.next(); for (java.lang.Object imp : imports) { if (imp instanceof Import) { Definition importDef = ((Import) imp).getDefinition(); LOG.log(Level.INFO, "Following import " + importDef.getDocumentBaseURI()); ret = getBindingForTypeId(repId, importDef); if (ret.isValid()) { return ret; } } } } } return ret; }
public void testCompare() throws WSDLException, ComparisonException { Comparator<Definition> comparator = new WSDLDeclarationComparator(); Definition originalWSDL = WSDLTestUtils.getWSDLDefinition(); Definition changedWSDL = WSDLTestUtils.getWSDLDefinitionWithDetails(); // originalWSDL.setExtensionAttribute(); // originalWSDL.setTypes(); // originalWSDL.addBinding(); // originalWSDL.addImport(); // originalWSDL.addMessage(); // originalWSDL.addBinding(); // originalWSDL.addPortType(); // originalWSDL.addService(); // originalWSDL.addExtensibilityElement(); originalWSDL.getAllBindings(); originalWSDL.getAllPortTypes(); originalWSDL.getAllServices(); originalWSDL.getDocumentBaseURI(); originalWSDL.getImports(); originalWSDL.getMessages(); originalWSDL.getNamespaces(); originalWSDL.getPortTypes(); originalWSDL.getQName(); originalWSDL.getTargetNamespace(); originalWSDL.getTypes(); originalWSDL.getDocumentationElement(); originalWSDL.getExtensibilityElements(); // TODO Fix me originalWSDL.getExtensionAttributes(); Comparison defaultComparison = new DefaultComparison(); comparator.compare(originalWSDL, changedWSDL, defaultComparison); System.out.println(defaultComparison); assertNotNull(defaultComparison); }
protected static void initializeService( org.w3c.dom.Element service, TProcess bpelProcess, TPartnerLink pl, java.util.Collection<javax.wsdl.Definition> wsdls, org.w3c.dom.Element partnerLinkTypes, java.util.Map<String, String> nsMap) { QName serviceName = null; String servicePort = null; // Get partner link type details QName partnerLinkType = pl.getPartnerLinkType(); org.w3c.dom.NodeList nl = partnerLinkTypes.getChildNodes(); String portType = null; for (int i = 0; portType == null && i < nl.getLength(); i++) { org.w3c.dom.Node n = nl.item(i); if (n instanceof org.w3c.dom.Element && XMLUtils.getLocalname(n.getNodeName()).equals(PARTNER_LINK_TYPE)) { org.w3c.dom.Element plt = (org.w3c.dom.Element) nl.item(i); String name = plt.getAttribute("name"); if (name != null && name.equals(partnerLinkType.getLocalPart())) { org.w3c.dom.NodeList nl2 = plt.getChildNodes(); for (int j = 0; portType == null && j < nl2.getLength(); j++) { org.w3c.dom.Node n2 = nl2.item(j); if (n2 instanceof org.w3c.dom.Element && XMLUtils.getLocalname(n2.getNodeName()).equals("role")) { org.w3c.dom.Element role = (org.w3c.dom.Element) n2; String roleName = role.getAttribute("name"); if ((pl.getMyRole() != null && pl.getMyRole().equals(roleName)) || (pl.getPartnerRole() != null && pl.getPartnerRole().equals(roleName))) { portType = role.getAttribute("portType"); String ptprefix = XMLUtils.getPrefix(portType); String ptns = partnerLinkTypes.getAttribute("xmlns:" + ptprefix); String newprefix = XMLUtils.getPrefixForNamespace(ptns, nsMap); portType = newprefix + ":" + XMLUtils.getLocalname(portType); } } } } } } if (portType != null) { String portTypePrefix = XMLUtils.getPrefix(portType); String portTypeNS = XMLUtils.getNamespaceForPrefix(portTypePrefix, nsMap); QName ptQName = new QName(portTypeNS, XMLUtils.getLocalname(portType)); for (javax.wsdl.Definition wsdl : wsdls) { if (wsdl.getTargetNamespace().equals(portTypeNS)) { @SuppressWarnings("unchecked") java.util.Collection<javax.wsdl.Service> services = wsdl.getServices().values(); for (javax.wsdl.Service s : services) { @SuppressWarnings("unchecked") java.util.Collection<javax.wsdl.Port> ports = s.getPorts().values(); for (javax.wsdl.Port p : ports) { if (p.getBinding() != null && p.getBinding().getPortType() != null && p.getBinding().getPortType().getQName().equals(ptQName)) { serviceName = s.getQName(); servicePort = p.getName(); } } } } } if (serviceName != null) { String prefix = XMLUtils.getPrefixForNamespace(serviceName.getNamespaceURI(), nsMap); service.setAttribute("name", prefix + ":" + serviceName.getLocalPart()); } if (servicePort != null) { service.setAttribute("port", servicePort); } } }
public void createServiceComposite( Role role, java.util.List<Role> refRoles, String wsdlPath, java.util.List<String> refWsdlPaths, String resourceFolder, String srcFolder) throws Exception { javax.wsdl.Definition defn = getWSDLReader().readWSDL(wsdlPath); if (defn != null) { java.io.File wsdlFile = new java.io.File(wsdlPath); if (!wsdlFile.exists()) { java.net.URL url = ClassLoader.getSystemResource(wsdlPath); wsdlFile = new java.io.File(url.getFile()); if (!wsdlFile.exists()) { logger.severe("Failed to find WSDL file '" + wsdlPath + "'"); } } ResourceLocator locator = new DefaultResourceLocator(wsdlFile.getParentFile()); StringBuffer composite = new StringBuffer(); StringBuffer transformers = new StringBuffer(); StringBuffer component = new StringBuffer(); String targetNamespace = defn.getTargetNamespace(); String name = role.getName(); composite.append("<switchyard xmlns=\"urn:switchyard-config:switchyard:1.0\"\r\n"); // TODO: May need to add other namespaces here composite.append("\t\ttargetNamespace=\"" + targetNamespace + "\"\r\n"); composite.append("\t\tname=\"" + name + "\">\r\n"); composite.append( "\t<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\"\r\n"); composite.append("\t\t\ttargetNamespace=\""); composite.append(targetNamespace); composite.append("\"\r\n\t\t\tname=\""); composite.append(name); composite.append("\" >\r\n"); @SuppressWarnings("unchecked") java.util.Iterator<PortType> portTypes = defn.getPortTypes().values().iterator(); while (portTypes.hasNext()) { PortType portType = portTypes.next(); // Define transformers addPortTypeTransformers(portType, true, transformers, defn, locator, srcFolder); String wsdlName = wsdlPath; int ind = wsdlName.lastIndexOf('/'); String wsdlLocation = wsdlName; if (ind != -1) { wsdlLocation = wsdlName.substring(ind + 1); wsdlName = wsdlName.substring(ind + 1) + "#wsdl.porttype(" + portType.getQName().getLocalPart() + ")"; } composite.append( "\t\t<service name=\"" + portType.getQName().getLocalPart() + "\" promote=\"" + portType.getQName().getLocalPart() + "Component/" + portType.getQName().getLocalPart() + "\">\r\n"); composite.append("\t\t\t<interface.wsdl interface=\"wsdl/" + wsdlName + "\" />\r\n"); composite.append( "\t\t\t<binding.soap xmlns=\"urn:switchyard-component-soap:config:1.0\">\r\n"); composite.append("\t\t\t\t<wsdl>wsdl/" + wsdlLocation + "</wsdl>\r\n"); composite.append("\t\t\t\t<socketAddr>:18001</socketAddr>\r\n"); composite.append("\t\t\t</binding.soap>\r\n"); composite.append("\t\t</service>\r\n"); String pack = JavaGeneratorUtil.getJavaPackage(defn.getTargetNamespace()); component.append( "\t\t<component name=\"" + portType.getQName().getLocalPart() + "Component\">\r\n"); component.append( "\t\t\t<implementation.bean xmlns=\"urn:switchyard-component-bean:config:1.0\" " + "class=\"" + pack + "." + portType.getQName().getLocalPart() + "Impl\"/>\r\n"); component.append( "\t\t\t<service name=\"" + portType.getQName().getLocalPart() + "\" >\r\n"); component.append( "\t\t\t\t<interface.java interface=\"" + pack + "." + portType.getQName().getLocalPart() + "\"/>\r\n"); component.append("\t\t\t</service>\r\n"); for (int i = 0; i < refWsdlPaths.size(); i++) { String refWsdlPath = refWsdlPaths.get(i); javax.wsdl.Definition refDefn = getWSDLReader().readWSDL(refWsdlPath); java.io.File refWsdlFile = new java.io.File(refWsdlPath); if (!refWsdlFile.exists()) { java.net.URL url = ClassLoader.getSystemResource(refWsdlPath); refWsdlFile = new java.io.File(url.getFile()); if (!refWsdlFile.exists()) { logger.severe("Failed to find ref WSDL file '" + refWsdlPath + "'"); } } ResourceLocator refLocator = new DefaultResourceLocator(refWsdlFile.getParentFile()); if (refDefn != null) { @SuppressWarnings("unchecked") java.util.Iterator<PortType> refPortTypes = refDefn.getPortTypes().values().iterator(); while (refPortTypes.hasNext()) { PortType refPortType = refPortTypes.next(); // Define transformers addPortTypeTransformers( refPortType, false, transformers, refDefn, refLocator, srcFolder); String refWsdlName = refWsdlPath; wsdlLocation = refWsdlName; ind = refWsdlName.lastIndexOf('/'); if (ind != -1) { wsdlLocation = refWsdlName.substring(ind + 1); refWsdlName = refWsdlName.substring(ind + 1) + "#wsdl.porttype(" + refPortType.getQName().getLocalPart() + ")"; } composite.append( "\t\t<reference name=\"" + refPortType.getQName().getLocalPart() + "\" promote=\"" + portType.getQName().getLocalPart() + "Component/" + refPortType.getQName().getLocalPart() + "\" multiplicity=\"1..1\" >\r\n"); composite.append( "\t\t\t<interface.wsdl interface=\"wsdl/" + refWsdlName + "\" />\r\n"); composite.append( "\t\t\t<binding.soap xmlns=\"urn:switchyard-component-soap:config:1.0\">\r\n"); composite.append("\t\t\t\t<wsdl>wsdl/" + wsdlLocation + "</wsdl>\r\n"); composite.append("\t\t\t\t<socketAddr>:18001</socketAddr>\r\n"); composite.append("\t\t\t</binding.soap>\r\n"); composite.append("\t\t</reference>\r\n"); String refPack = JavaGeneratorUtil.getJavaPackage(refDefn.getTargetNamespace()); component.append( "\t\t\t<reference name=\"" + refPortType.getQName().getLocalPart() + "\" >\r\n"); component.append( "\t\t\t\t<interface.java interface=\"" + refPack + "." + refPortType.getQName().getLocalPart() + "\"/>\r\n"); component.append("\t\t\t</reference>\r\n"); } } } component.append("\t\t</component>\r\n"); composite.append(component.toString()); } composite.append("\t</composite>\r\n"); if (transformers.length() > 0) { composite.append("\t<transforms xmlns:xform=\"urn:switchyard-config:transform:1.0\">\r\n"); composite.append(transformers.toString()); composite.append("\t</transforms>\r\n"); } composite.append("</switchyard>\r\n"); java.io.FileOutputStream fos = new java.io.FileOutputStream( resourceFolder + java.io.File.separatorChar + "switchyard.xml"); fos.write(composite.toString().getBytes()); fos.close(); } }
protected void addServiceReferencesToImplementation( java.io.File implFile, Role role, java.util.List<Role> refRoles, java.util.List<String> refWsdlPaths, String srcFolder) throws Exception { // Check that the number of reference roles and wsdl paths are the same if (refRoles.size() != refWsdlPaths.size()) { throw new IllegalArgumentException( "The number of reference roles and wsdl paths are not consistent"); } java.io.FileInputStream fis = new java.io.FileInputStream(implFile); byte[] b = new byte[fis.available()]; fis.read(b); StringBuffer text = new StringBuffer(); text.append(new String(b)); fis.close(); int index = text.indexOf("private static final Logger"); if (index != -1) { for (int i = 0; i < refRoles.size(); i++) { javax.wsdl.Definition refDefn = getWSDLReader().readWSDL(refWsdlPaths.get(i)); if (refDefn != null) { // Use the namespace to obtain a Java package String refPack = JavaGeneratorUtil.getJavaPackage(refDefn.getTargetNamespace()); @SuppressWarnings("unchecked") java.util.Iterator<PortType> refPortTypes = refDefn.getPortTypes().values().iterator(); int refPortCount = 1; while (refPortTypes.hasNext()) { PortType refPortType = refPortTypes.next(); String name = JavaBehaviourGenerator.getVariableName(refRoles.get(i).getName()); if (refDefn.getPortTypes().size() > 1) { name += refPortCount; } text.insert( index, "@javax.inject.Inject @org.switchyard.component.bean.Reference\r\n " + refPack + "." + refPortType.getQName().getLocalPart() + " _" + name + ";\r\n\r\n "); } } } java.io.FileOutputStream fos = new java.io.FileOutputStream(implFile); fos.write(text.toString().getBytes()); fos.close(); } else { logger.severe( "Service implementation file '" + implFile.getAbsolutePath() + "' does not have 'private static final Logger' as location to insert references"); } }