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); } } }
protected void updateSchemaImports( Schema schema, Map<String, SchemaReference> doneSchemas, String base) { OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus); Collection<List<?>> imports = CastUtils.cast((Collection<?>) schema.getImports().values()); for (List<?> lst : imports) { List<SchemaImport> impLst = CastUtils.cast(lst); for (SchemaImport imp : impLst) { String start = imp.getSchemaLocationURI(); if (start != null) { String decodedStart = null; // Always use the URL decoded version to ensure that we have a // canonical representation of the import URL for lookup. try { decodedStart = URLDecoder.decode(start, "utf-8"); } catch (UnsupportedEncodingException e) { throw new WSDLQueryException( new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e); } if (!doneSchemas.containsKey(decodedStart)) { String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { try { checkSchemaUrl(doneSchemas, start, decodedStart, imp); } catch (MalformedURLException e) { if (doneSchemas.put(decodedStart, imp) == null) { updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base); } } } else { if (doneSchemas.put(decodedStart, imp) == null) { doneSchemas.put(resolvedSchemaLocation, imp); updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base); } } } } } } List<SchemaReference> includes = CastUtils.cast(schema.getIncludes()); for (SchemaReference included : includes) { String start = included.getSchemaLocationURI(); if (start != null) { String decodedStart = null; // Always use the URL decoded version to ensure that we have a // canonical representation of the import URL for lookup. try { decodedStart = URLDecoder.decode(start, "utf-8"); } catch (UnsupportedEncodingException e) { /*throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e); */ } String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { if (!doneSchemas.containsKey(decodedStart)) { try { checkSchemaUrl(doneSchemas, start, decodedStart, included); } catch (MalformedURLException e) { if (doneSchemas.put(decodedStart, included) == null) { updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } } else if (!doneSchemas.containsKey(decodedStart) || !doneSchemas.containsKey(resolvedSchemaLocation)) { doneSchemas.put(decodedStart, included); doneSchemas.put(resolvedSchemaLocation, included); updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } List<SchemaReference> redefines = CastUtils.cast(schema.getRedefines()); for (SchemaReference included : redefines) { String start = included.getSchemaLocationURI(); if (start != null) { String decodedStart = null; // Always use the URL decoded version to ensure that we have a // canonical representation of the import URL for lookup. try { decodedStart = URLDecoder.decode(start, "utf-8"); } catch (UnsupportedEncodingException e) { throw new WSDLQueryException( new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e); } String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { if (!doneSchemas.containsKey(decodedStart)) { try { checkSchemaUrl(doneSchemas, start, decodedStart, included); } catch (MalformedURLException e) { if (doneSchemas.put(decodedStart, included) == null) { updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } } else if (!doneSchemas.containsKey(decodedStart) || !doneSchemas.containsKey(resolvedSchemaLocation)) { doneSchemas.put(decodedStart, included); doneSchemas.put(resolvedSchemaLocation, included); updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } }