From e72999c71eef4d6bf828c67a7d7a402e371c4c8e Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Tue, 30 Apr 2024 15:37:37 +0200 Subject: [PATCH] Switch to load wsdl and schema files from multiple jars #681 Signed-off-by: Jorge Bescos Gascon --- .gitignore | 1 + .../metro/helidon/HelidonResourceLoader.java | 114 +++++++++++------- .../eclipse/metro/helidon/MetroSupport.java | 18 ++- 3 files changed, 84 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 46dacbc63..372d0f72c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ # eclipse .project .classpath +.factorypath .settings/ .wtpmodules diff --git a/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/HelidonResourceLoader.java b/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/HelidonResourceLoader.java index e10be1d00..d1f1298e3 100644 --- a/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/HelidonResourceLoader.java +++ b/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/HelidonResourceLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,10 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.Enumeration; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; @@ -38,13 +41,15 @@ class HelidonResourceLoader implements ResourceLoader { private final String catalog; + private final boolean loadCustomSchemaEnabled; private static final String DD_DIR = DeploymentDescriptorParser.JAXWS_WSDL_DD_DIR + "/"; private static final Logger LOGGER = Logger.getLogger(HelidonResourceLoader.class.getName()); - public HelidonResourceLoader(String catalog) { + HelidonResourceLoader(String catalog, boolean loadCustomSchemaEnabled) { this.catalog = catalog; + this.loadCustomSchemaEnabled = loadCustomSchemaEnabled; } @Override @@ -60,62 +65,79 @@ public URL getCatalogFile() throws MalformedURLException { @Override public Set getResourcePaths(String path) { - //should be always true, warn if not - if (("/" + DD_DIR).equals(path)) { + // should be always true, warn if not + if (("/" + DD_DIR).equals(path)) { Set r = new HashSet<>(); - FileSystem jarFS = null; try { - URL rootUrl = getResource(path); - if (rootUrl == null) { - //no wsdls found - return r; + Collection resources; + String res = path.substring(1); + if (loadCustomSchemaEnabled) { + resources = Collections.list(Thread.currentThread().getContextClassLoader().getResources(res)); + } else { + resources = Arrays.asList(getResource(res)); } - Path wsdlDir = null; - switch (rootUrl.getProtocol()) { - case "file": - wsdlDir = Paths.get(rootUrl.toURI()); - break; - case "jar": - jarFS = FileSystems.newFileSystem(rootUrl.toURI(), Collections.emptyMap()); - wsdlDir = jarFS.getPath(path); - break; - default: - LOGGER.log(Level.WARNING, "Unsupported protocol: {0}", rootUrl.getProtocol()); - LOGGER.log(Level.WARNING, "Empty set for {0}", rootUrl); - return Collections.EMPTY_SET; + for (URL rootUrl : resources) { + loadResources(path, rootUrl, r); } + return r; + } catch (IOException e) { + LOGGER.log(Level.FINE, null, e); + } + } + LOGGER.log(Level.WARNING, "Empty set for {0}", path); + return Collections.EMPTY_SET; + } + + private Set loadResources(String path, URL rootUrl, Set r) { + FileSystem jarFS = null; + try { + if (rootUrl == null) { + // no wsdls found + return r; + } + Path wsdlDir = null; + switch (rootUrl.getProtocol()) { + case "file": + wsdlDir = Paths.get(rootUrl.toURI()); + break; + case "jar": + jarFS = FileSystems.newFileSystem(rootUrl.toURI(), Collections.emptyMap()); + wsdlDir = jarFS.getPath(path); + break; + default: + LOGGER.log(Level.WARNING, "Unsupported protocol: {0}", rootUrl.getProtocol()); + LOGGER.log(Level.WARNING, "Empty set for {0}", rootUrl); + return Collections.EMPTY_SET; + } - //since we don't know exact file extension (can be .wsdl, .xml, .asmx,...) - //nor whether the file is used or not (we are not processing wsdl/xsd imports here) - //simply return all found files - Files.walkFileTree(wsdlDir, new SimpleFileVisitor() { + //since we don't know exact file extension (can be .wsdl, .xml, .asmx,...) + //nor whether the file is used or not (we are not processing wsdl/xsd imports here) + //simply return all found files + Files.walkFileTree(wsdlDir, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - try { - String p = DD_DIR + Paths.get(rootUrl.toURI()).relativize(file).toString(); - r.add(p); - } catch (URISyntaxException ex) { - LOGGER.log(Level.FINE, null, ex); - } - return FileVisitResult.CONTINUE; - } - }); - } catch (IOException | URISyntaxException ex) { - LOGGER.log(Level.FINE, null, ex); - } finally { - if (jarFS != null) { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try { - jarFS.close(); - } catch (IOException ex) { + String p = DD_DIR + Paths.get(rootUrl.toURI()).relativize(file).toString(); + r.add(p); + } catch (URISyntaxException ex) { LOGGER.log(Level.FINE, null, ex); } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException | URISyntaxException ex) { + LOGGER.log(Level.FINE, null, ex); + } finally { + if (jarFS != null) { + try { + jarFS.close(); + } catch (IOException ex) { + LOGGER.log(Level.FINE, null, ex); } } - return r; } - LOGGER.log(Level.WARNING, "Empty set for {0}", path); - return Collections.EMPTY_SET; + return r; } } diff --git a/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/MetroSupport.java b/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/MetroSupport.java index 353297812..1399c44fa 100644 --- a/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/MetroSupport.java +++ b/jaxws-ri/extras/helidon-integration/se/src/main/java/org/eclipse/metro/helidon/MetroSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,12 +67,11 @@ private MetroSupport(Builder builder) { HttpTransportPipe.setDump(builder.dumpClient); // 3.0.0 does not have this method HttpAdapter.setDumpTreshold(builder.dumpTreshold); - List e = Collections.EMPTY_LIST; container = new HelidonContainer(builder.webContext); try { e = parseEndpoints(builder.dd, - new HelidonResourceLoader(builder.catalog), + new HelidonResourceLoader(builder.catalog, builder.loadcustomschema), container); } catch (IOException ioe) { LOGGER.log(Level.SEVERE, null, ioe); @@ -161,6 +160,7 @@ public static MetroSupport create(Config config) { public static final class Builder implements io.helidon.common.Builder { private String dd = "sun-jaxws.xml"; + private boolean loadcustomschema = false; private String wsdlRoot = "WEB-INF/wsdl"; private String catalog = "metro-catalog.xml"; private String webContext = ""; @@ -193,6 +193,7 @@ public Builder catalog(String catalog) { public Builder config(Config config) { config.get("catalog").asString().ifPresent(this::catalog); config.get("descriptor").asString().ifPresent(this::descriptor); + config.get("loadcustomschema").asBoolean().ifPresent(this::loadcustomschema); // config.get("dump-client").asBoolean().ifPresent(this::dumpClient); // config.get("dump-service").asBoolean().ifPresent(this::dumpService); config.get("dump").asString().ifPresent((value) -> { @@ -288,6 +289,17 @@ public Builder publishStatusPage(boolean enabled) { return this; } + /** + * It will load every schema found in the resource path. + * + * @param enabled whether it should search for all resources (defaults to {@code false}) + * @return updated builder instance + */ + public Builder loadcustomschema(boolean enabled) { + loadcustomschema = enabled; + return this; + } + /** * Path under which to register metro services on the web server. *