Author: dvaleri Date: Mon Oct 25 21:08:16 2010 New Revision: 1027270 URL: http://svn.apache.org/viewvc?rev=1027270&view=rev Log: Merged revisions 1027256 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes
................ r1027256 | dvaleri | 2010-10-25 16:20:38 -0400 (Mon, 25 Oct 2010) | 9 lines Merged revisions 1027244 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1027244 | dvaleri | 2010-10-25 15:41:28 -0400 (Mon, 25 Oct 2010) | 1 line [CXF-3091] Added support to URL decode URL parameters encountered during WSDL lookup. ........ ................ Modified: cxf/branches/2.2.x-fixes/ (props changed) cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Propchange: cxf/branches/2.2.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Mon Oct 25 21:08:16 2010 @@ -0,0 +1,2 @@ +/cxf/branches/2.3.x-fixes:1027256 +/cxf/trunk:1027244 Propchange: cxf/branches/2.2.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=1027270&r1=1027269&r2=1027270&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original) +++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Mon Oct 25 21:08:16 2010 @@ -20,8 +20,10 @@ package org.apache.cxf.transport.http; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLDecoder; import java.util.Collection; import java.util.List; import java.util.Map; @@ -120,12 +122,16 @@ public class WSDLQueryHandler implements String wsdl = params.get("wsdl"); if (wsdl != null) { - wsdl = wsdl.replace("%20", " "); + // Always use the URL decoded version to ensure that we have a + // canonical representation of the import URL for lookup. + wsdl = URLDecoder.decode(wsdl, "utf-8"); } String xsd = params.get("xsd"); if (xsd != null) { - xsd = xsd.replace("%20", " "); + // Always use the URL decoded version to ensure that we have a + // canonical representation of the import URL for lookup. + xsd = URLDecoder.decode(xsd, "utf-8"); } Map<String, Definition> mp = CastUtils.cast((Map)endpointInfo.getService() @@ -242,42 +248,51 @@ public class WSDLQueryHandler implements Map<String, Definition> mp, Map<String, SchemaReference> smp, EndpointInfo ei) { - List<Element> elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), - "http://www.w3.org/2001/XMLSchema", - "import"); - for (Element el : elementList) { - String sl = el.getAttribute("schemaLocation"); - if (smp.containsKey(sl)) { - el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); - } - } + List<Element> elementList = null; - elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), - "http://www.w3.org/2001/XMLSchema", - "include"); - for (Element el : elementList) { - String sl = el.getAttribute("schemaLocation"); - if (smp.containsKey(sl)) { - el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); - } - } - elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), - "http://www.w3.org/2001/XMLSchema", - "redefine"); - for (Element el : elementList) { - String sl = el.getAttribute("schemaLocation"); - if (smp.containsKey(sl)) { - el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); - } - } - elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), - "http://schemas.xmlsoap.org/wsdl/", - "import"); - for (Element el : elementList) { - String sl = el.getAttribute("location"); - if (mp.containsKey(sl)) { - el.setAttribute("location", base + "?wsdl=" + sl.replace(" ", "%20")); + + try { + elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), + "http://www.w3.org/2001/XMLSchema", + "import"); + for (Element el : elementList) { + String sl = el.getAttribute("schemaLocation"); + if (smp.containsKey(URLDecoder.decode(sl, "utf-8"))) { + el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); + } + } + + elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), + "http://www.w3.org/2001/XMLSchema", + "include"); + for (Element el : elementList) { + String sl = el.getAttribute("schemaLocation"); + if (smp.containsKey(URLDecoder.decode(sl, "utf-8"))) { + el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); + } + } + elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), + "http://www.w3.org/2001/XMLSchema", + "redefine"); + for (Element el : elementList) { + String sl = el.getAttribute("schemaLocation"); + if (smp.containsKey(URLDecoder.decode(sl, "utf-8"))) { + el.setAttribute("schemaLocation", base + "?xsd=" + sl.replace(" ", "%20")); + } + } + elementList = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), + "http://schemas.xmlsoap.org/wsdl/", + "import"); + for (Element el : elementList) { + String sl = el.getAttribute("location"); + if (mp.containsKey(URLDecoder.decode(sl, "utf-8"))) { + el.setAttribute("location", base + "?wsdl=" + sl.replace(" ", "%20")); + } } + } catch (UnsupportedEncodingException e) { + throw new WSDLQueryException(new Message("COULD_NOT_PROVIDE_WSDL", + LOG, + base), e); } Boolean rewriteSoapAddress = ei.getProperty("autoRewriteSoapAddress", Boolean.class); @@ -336,11 +351,23 @@ public class WSDLQueryHandler implements String base, EndpointInfo ei) { OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus); - Collection<List> imports = CastUtils.cast((Collection<?>)def.getImports().values()); - for (List lst : imports) { + Collection<List<?>> imports = CastUtils.cast((Collection<?>)def.getImports().values()); + for (List<?> lst : imports) { List<Import> impLst = CastUtils.cast(lst); for (Import imp : impLst) { + String start = imp.getLocationURI(); + 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 Message("COULD_NOT_PROVIDE_WSDL", + LOG, + start), e); + } + String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { @@ -348,12 +375,12 @@ public class WSDLQueryHandler implements //check to see if it's already in a URL format. If so, leave it. new URL(start); } catch (MalformedURLException e) { - if (done.put(start, imp.getDefinition()) == null) { + if (done.put(decodedStart, imp.getDefinition()) == null) { updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei); } } } else { - if (done.put(start, imp.getDefinition()) == null) { + if (done.put(decodedStart, imp.getDefinition()) == null) { done.put(resolvedSchemaLocation, imp.getDefinition()); updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei); } @@ -399,7 +426,7 @@ public class WSDLQueryHandler implements } private void setSoapAddressLocationOn(Port port, String url) { - List extensions = port.getExtensibilityElements(); + List<?> extensions = port.getExtensibilityElements(); for (Object extension : extensions) { if (extension instanceof SOAP12Address) { ((SOAP12Address)extension).setLocationURI(url); @@ -413,51 +440,77 @@ public class WSDLQueryHandler implements Map<String, SchemaReference> doneSchemas, String base) { OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus); - Collection<List> imports = CastUtils.cast((Collection<?>)schema.getImports().values()); - for (List lst : imports) { + 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 && !doneSchemas.containsKey(start)) { - String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); - if (resolvedSchemaLocation == null) { - try { - //check to see if it's already in a URL format. If so, leave it. - new URL(start); - } catch (MalformedURLException e) { - if (doneSchemas.put(start, imp) == null) { + + 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 Message("COULD_NOT_PROVIDE_WSDL", + LOG, + start), e); + } + + if (!doneSchemas.containsKey(decodedStart)) { + String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); + if (resolvedSchemaLocation == null) { + try { + //check to see if it's already in a URL format. If so, leave it. + new URL(start); + } 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); } } - } else { - if (doneSchemas.put(start, 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 Message("COULD_NOT_PROVIDE_WSDL", + LOG, + start), e); + } + String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { - if (!doneSchemas.containsKey(start)) { + if (!doneSchemas.containsKey(decodedStart)) { try { //check to see if it's aleady in a URL format. If so, leave it. new URL(start); } catch (MalformedURLException e) { - if (doneSchemas.put(start, included) == null) { + if (doneSchemas.put(decodedStart, included) == null) { updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } - } else if (!doneSchemas.containsKey(start) + } else if (!doneSchemas.containsKey(decodedStart) || !doneSchemas.containsKey(resolvedSchemaLocation)) { - doneSchemas.put(start, included); + doneSchemas.put(decodedStart, included); doneSchemas.put(resolvedSchemaLocation, included); updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } @@ -468,21 +521,32 @@ public class WSDLQueryHandler implements 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 Message("COULD_NOT_PROVIDE_WSDL", + LOG, + start), e); + } + String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base); if (resolvedSchemaLocation == null) { - if (!doneSchemas.containsKey(start)) { + if (!doneSchemas.containsKey(decodedStart)) { try { //check to see if it's aleady in a URL format. If so, leave it. new URL(start); } catch (MalformedURLException e) { - if (doneSchemas.put(start, included) == null) { + if (doneSchemas.put(decodedStart, included) == null) { updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); } } } - } else if (!doneSchemas.containsKey(start) + } else if (!doneSchemas.containsKey(decodedStart) || !doneSchemas.containsKey(resolvedSchemaLocation)) { - doneSchemas.put(start, included); + doneSchemas.put(decodedStart, included); doneSchemas.put(resolvedSchemaLocation, included); updateSchemaImports(included.getReferencedSchema(), doneSchemas, base); }
