Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to load wsdl and schema files from multiple jars #681 #685

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target/
# eclipse
.project
.classpath
.factorypath
.settings/
.wtpmodules

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -60,62 +65,79 @@ public URL getCatalogFile() throws MalformedURLException {

@Override
public Set<String> 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<String> r = new HashSet<>();
FileSystem jarFS = null;
try {
URL rootUrl = getResource(path);
if (rootUrl == null) {
//no wsdls found
return r;
Collection<URL> 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<String> loadResources(String path, URL rootUrl, Set<String> 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<Path>() {
//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<Path>() {

@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;
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<HelidonAdapter> 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);
Expand Down Expand Up @@ -161,6 +160,7 @@ public static MetroSupport create(Config config) {
public static final class Builder implements io.helidon.common.Builder<MetroSupport> {

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 = "";
Expand Down Expand Up @@ -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) -> {
Expand Down Expand Up @@ -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.
*
Expand Down
Loading