Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 41D5E200C47 for ; Thu, 30 Mar 2017 20:47:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4045C160B8B; Thu, 30 Mar 2017 18:47:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 626F0160B7E for ; Thu, 30 Mar 2017 20:47:15 +0200 (CEST) Received: (qmail 62543 invoked by uid 500); 30 Mar 2017 18:47:14 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 62534 invoked by uid 99); 30 Mar 2017 18:47:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Mar 2017 18:47:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6768ADFBED; Thu, 30 Mar 2017 18:47:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@cxf.apache.org Message-Id: <6f08cd5e412d4202890ec9779d0cfdc2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6717] Fix problem with schemaLocation not getting properly updated to resolvable schema Date: Thu, 30 Mar 2017 18:47:14 +0000 (UTC) archived-at: Thu, 30 Mar 2017 18:47:16 -0000 Repository: cxf Updated Branches: refs/heads/master 1cf17867a -> 28a092319 [CXF-6717] Fix problem with schemaLocation not getting properly updated to resolvable schema Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/28a09231 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/28a09231 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/28a09231 Branch: refs/heads/master Commit: 28a092319a9223d93bcbd94abd3e9c0a8a54ac09 Parents: 1cf1786 Author: Daniel Kulp Authored: Thu Mar 30 14:46:38 2017 -0400 Committer: Daniel Kulp Committed: Thu Mar 30 14:46:38 2017 -0400 ---------------------------------------------------------------------- .../org/apache/cxf/frontend/WSDLGetUtils.java | 44 +++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/28a09231/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java b/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java index bf0ee17..ff1b254 100644 --- a/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java +++ b/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java @@ -163,7 +163,8 @@ public class WSDLGetUtils { return doc; } - protected String mapUri(Bus bus, String base, Map smp, String loc, String xsd) + protected String mapUri(Bus bus, String base, Map smp, + String loc, String xsd, String resolvedXsd) throws UnsupportedEncodingException { String key = loc; try { @@ -172,7 +173,8 @@ public class WSDLGetUtils { // resolve requested location with relative import path key = new URI(xsd).resolve(loc).toString(); - if (!smp.containsKey(URLDecoder.decode(key, "utf-8"))) { + SchemaReference ref = smp.get(URLDecoder.decode(key, "utf-8")); + if (ref == null) { // if the result is not known, check if we can resolve it into something known String resolved = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), key, base); if (resolved != null && smp.containsKey(URLDecoder.decode(resolved, "utf-8"))) { @@ -187,6 +189,34 @@ public class WSDLGetUtils { //ignore } SchemaReference ref = smp.get(URLDecoder.decode(key, "utf-8")); + if (ref == null && resolvedXsd != null) { + try { + String key2 = new URI(resolvedXsd).resolve(loc).toString(); + SchemaReference ref2 = smp.get(URLDecoder.decode(key2, "utf-8")); + if (ref2 == null) { + // if the result is not known, check if we can resolve it into something known + String resolved = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), key2, base); + if (resolved != null && smp.containsKey(URLDecoder.decode(resolved, "utf-8"))) { + // if it is resolvable, we can use it + ref = smp.get(URLDecoder.decode(resolved, "utf-8")); + } + } else { + ref = smp.get(URLDecoder.decode(key2, "utf-8")); + } + } catch (URISyntaxException e) { + //ignore, ref can remain null + } + if (ref != null) { + // we are able to map this, but for some reason the default key passed in cannot + // be used for a direct lookup, we need to create a unique import key + int count = 1; + while (smp.containsKey("_import" + count + ".xsd")) { + count++; + } + key = "_import" + count + ".xsd"; + smp.put(key, ref); + } + } if (ref != null) { return base + "?xsd=" + key.replace(" ", "%20"); } @@ -218,7 +248,7 @@ public class WSDLGetUtils { "http://www.w3.org/2001/XMLSchema", "import"); for (Element el : elementList) { String sl = el.getAttribute("schemaLocation"); - sl = mapUri(bus, base, smp, sl, xsdWsdlPar); + sl = mapUri(bus, base, smp, sl, xsdWsdlPar, doc.getDocumentURI()); if (sl != null) { el.setAttribute("schemaLocation", sl); } @@ -229,7 +259,7 @@ public class WSDLGetUtils { "include"); for (Element el : elementList) { String sl = el.getAttribute("schemaLocation"); - sl = mapUri(bus, base, smp, sl, xsdWsdlPar); + sl = mapUri(bus, base, smp, sl, xsdWsdlPar, doc.getDocumentURI()); if (sl != null) { el.setAttribute("schemaLocation", sl); } @@ -239,7 +269,7 @@ public class WSDLGetUtils { "redefine"); for (Element el : elementList) { String sl = el.getAttribute("schemaLocation"); - sl = mapUri(bus, base, smp, sl, xsdWsdlPar); + sl = mapUri(bus, base, smp, sl, xsdWsdlPar, doc.getDocumentURI()); if (sl != null) { el.setAttribute("schemaLocation", sl); } @@ -534,8 +564,12 @@ public class WSDLGetUtils { //check to see if it's already in a URL format. If so, leave it. new URL(start); } catch (MalformedURLException e) { + doneSchemas.put(decodedStart, schemaReference); doneSchemas.put(schemaReference.getReferencedSchema().getDocumentBaseURI(), schemaReference); + if (!doneSchemas.containsKey(decodedOrigLocation)) { + doneSchemas.put(decodedOrigLocation, schemaReference); + } try { if (!(new URI(origLocation).isAbsolute()) && parentResolved != null) { resolvedSchemaLocation = resolveRelativePath(parentResolved, decodedOrigLocation);