diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServerXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServerXml.java index c05fe5c4cd1..641612e0e0d 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServerXml.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/FileServerXml.java @@ -36,9 +36,8 @@ public class FileServerXml { public static void main( String[] args ) throws Exception { - Resource fileserverXml = Resource.newSystemResource("fileserver.xml"); - XmlConfiguration configuration = new XmlConfiguration( - fileserverXml.getInputStream()); + Resource fileServerXml = Resource.newSystemResource("fileserver.xml"); + XmlConfiguration configuration = new XmlConfiguration(fileServerXml); Server server = (Server) configuration.configure(); server.start(); server.join(); diff --git a/jetty-ant/src/main/java/org/eclipse/jetty/ant/AntWebAppContext.java b/jetty-ant/src/main/java/org/eclipse/jetty/ant/AntWebAppContext.java index a76d390922f..44b24e293cb 100644 --- a/jetty-ant/src/main/java/org/eclipse/jetty/ant/AntWebAppContext.java +++ b/jetty-ant/src/main/java/org/eclipse/jetty/ant/AntWebAppContext.java @@ -52,6 +52,7 @@ import org.eclipse.jetty.servlet.ServletMapping; import org.eclipse.jetty.servlet.Source; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.WebAppClassLoader; @@ -608,7 +609,7 @@ public class AntWebAppContext extends WebAppContext //apply a context xml file if one was supplied if (contextXml != null) { - XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(contextXml)); + XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(contextXml)); TaskLog.log("Applying context xml file "+contextXml); xmlConfiguration.configure(this); } diff --git a/jetty-ant/src/main/java/org/eclipse/jetty/ant/ServerProxyImpl.java b/jetty-ant/src/main/java/org/eclipse/jetty/ant/ServerProxyImpl.java index ac62bfc280a..9cc5b05c36c 100644 --- a/jetty-ant/src/main/java/org/eclipse/jetty/ant/ServerProxyImpl.java +++ b/jetty-ant/src/main/java/org/eclipse/jetty/ant/ServerProxyImpl.java @@ -41,6 +41,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; import org.xml.sax.SAXException; @@ -451,7 +452,7 @@ public class ServerProxyImpl implements ServerProxy XmlConfiguration configuration; try { - configuration = new XmlConfiguration(Resource.toURL(jettyXml)); + configuration = new XmlConfiguration(new PathResource(jettyXml)); configuration.configure(server); } catch (MalformedURLException e) diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java index 5082550159d..5b80468eba2 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBinding.java @@ -92,7 +92,7 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding if (globalContextSettings.exists()) { - XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream()); + XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings); Resource resource = Resource.newResource(app.getOriginId()); app.getDeploymentManager().scope(jettyXmlConfig,resource); WebAppClassLoader.runWithServerClassAccess(()->{jettyXmlConfig.configure(context);return null;}); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index 44de4134c56..7805d2d6bad 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -265,7 +265,7 @@ public class WebAppProvider extends ScanningAppProvider if (resource.exists() && FileID.isXmlFile(file)) { - XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL()) + XmlConfiguration xmlc = new XmlConfiguration(resource) { @Override public void initializeDefaults(Object context) diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java index db579f09088..e4f582a6046 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java @@ -18,13 +18,6 @@ package org.eclipse.jetty.deploy.test; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -53,17 +46,25 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.PathAssert; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.URIUtil; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Allows for setting up a Jetty server for testing based on XML configuration files. */ public class XmlConfiguredJetty { - private List _xmlConfigurations; + private List _xmlConfigurations; private Map _properties = new HashMap<>(); private Server _server; private int _serverPort; @@ -137,9 +138,9 @@ public class XmlConfiguredJetty setProperty(String.valueOf(key),String.valueOf(properties.get(key))); } - public void addConfiguration(File xmlConfigFile) throws MalformedURLException + public void addConfiguration(File xmlConfigFile) { - addConfiguration(Resource.toURL(xmlConfigFile)); + addConfiguration(new PathResource(xmlConfigFile)); } public void addConfiguration(String testConfigName) throws MalformedURLException @@ -147,7 +148,7 @@ public class XmlConfiguredJetty addConfiguration(MavenTestingUtils.getTestResourceFile(testConfigName)); } - public void addConfiguration(URL xmlConfig) + public void addConfiguration(Resource xmlConfig) { _xmlConfigurations.add(xmlConfig); } @@ -330,8 +331,8 @@ public class XmlConfiguredJetty // Configure everything for (int i = 0; i < this._xmlConfigurations.size(); i++) { - URL configURL = this._xmlConfigurations.get(i); - XmlConfiguration configuration = new XmlConfiguration(configURL); + Resource configResource = this._xmlConfigurations.get(i); + XmlConfiguration configuration = new XmlConfiguration(configResource); if (last != null) configuration.getIdMap().putAll(last.getIdMap()); configuration.getProperties().putAll(_properties); diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java index d33dbc10180..661b9523326 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/AbstractJettyMojo.java @@ -51,6 +51,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.util.PathWatcher; import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; @@ -556,7 +557,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo contextXml = path.toFile().getAbsolutePath(); } - XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(path.toFile())); + XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(path)); getLog().info("Applying context xml file "+contextXml); xmlConfiguration.configure(webApp); } diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java index 56da7940eb7..338427e3e90 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/ServerSupport.java @@ -33,8 +33,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.webapp.Configuration; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; @@ -194,7 +193,7 @@ public class ServerSupport PluginLog.getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() ); - XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile)); + XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(xmlFile)); //add in any properties if (properties != null) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/WebAppPropertyConverter.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/WebAppPropertyConverter.java index c8a4f71b7d1..c929fa59677 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/WebAppPropertyConverter.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/WebAppPropertyConverter.java @@ -19,13 +19,9 @@ package org.eclipse.jetty.maven.plugin; -import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStream; -import java.io.OutputStream; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -253,7 +249,7 @@ public class WebAppPropertyConverter str = props.getProperty("context.xml"); if (!StringUtil.isBlank(str)) { - XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.newResource(str).getURI().toURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.newResource(str)); xmlConfiguration.getIdMap().put("Server",server); //add in any properties if (jettyProperties != null) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java index 4505341c78b..896f6e85edf 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractContextProvider.java @@ -158,7 +158,7 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen { Thread.currentThread().setContextClassLoader(classLoader); - XmlConfiguration xmlConfiguration = new XmlConfiguration(res.getInputStream()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(res); HashMap properties = new HashMap(); //put the server instance in properties.put("Server", getServerInstanceWrapper().getServer()); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java index 8ec84811fc2..fe54fd50f51 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/AbstractWebAppProvider.java @@ -414,7 +414,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement // Apply it just as the standard jetty ContextProvider would do LOG.info("Applying " + contextXmlUri + " to " + _webApp); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUri); + XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.newResource(contextXmlUri)); WebAppClassLoader.runWithServerClassAccess(()-> { HashMap properties = new HashMap<>(); diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java index 7b6d31983fb..1862a8f51a4 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/serverfactory/ServerInstanceWrapper.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.osgi.boot.internal.serverfactory; -import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -54,6 +53,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; /** @@ -142,10 +142,10 @@ public class ServerInstanceWrapper for (URL jettyConfiguration : jettyConfigurations) { - try(InputStream in = jettyConfiguration.openStream()) + try { // Execute a Jetty configuration file - XmlConfiguration config = new XmlConfiguration(in); + XmlConfiguration config = new XmlConfiguration(Resource.newResource(jettyConfiguration)); config.getIdMap().putAll(id_map); config.getProperties().putAll(properties); diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java index 277e48e19d2..9cacc53ec55 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - import javax.naming.Binding; import javax.naming.Context; import javax.naming.InitialContext; @@ -39,6 +38,7 @@ import org.eclipse.jetty.plus.jndi.EnvEntry; import org.eclipse.jetty.plus.jndi.NamingEntryUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.FragmentConfiguration; import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; @@ -57,7 +57,7 @@ public class EnvConfiguration extends AbstractConfiguration private static final Logger LOG = Log.getLogger(EnvConfiguration.class); private static final String JETTY_ENV_BINDINGS = "org.eclipse.jetty.jndi.EnvConfiguration"; - private URL jettyEnvXmlUrl; + private Resource jettyEnvXmlResource; public EnvConfiguration() { @@ -66,9 +66,14 @@ public class EnvConfiguration extends AbstractConfiguration protectAndExpose("org.eclipse.jetty.jndi."); } + public void setJettyEnvResource(Resource resource) + { + this.jettyEnvXmlResource = resource; + } + public void setJettyEnvXml (URL url) { - this.jettyEnvXmlUrl = url; + this.jettyEnvXmlResource = Resource.newResource(url); } @Override @@ -86,7 +91,7 @@ public class EnvConfiguration extends AbstractConfiguration //check to see if an explicit file has been set, if not, //look in WEB-INF/jetty-env.xml - if (jettyEnvXmlUrl == null) + if (jettyEnvXmlResource == null) { //look for a file called WEB-INF/jetty-env.xml //and process it if it exists @@ -96,12 +101,12 @@ public class EnvConfiguration extends AbstractConfiguration org.eclipse.jetty.util.resource.Resource jettyEnv = web_inf.addPath("jetty-env.xml"); if(jettyEnv.exists()) { - jettyEnvXmlUrl = jettyEnv.getURI().toURL(); + jettyEnvXmlResource = jettyEnv; } } } - if (jettyEnvXmlUrl != null) + if (jettyEnvXmlResource != null) { synchronized (localContextRoot.getRoot()) { @@ -125,7 +130,7 @@ public class EnvConfiguration extends AbstractConfiguration try { localContextRoot.getRoot().addListener(listener); - XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlUrl); + XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource); configuration.setJettyStandardIdsAndProperties(context.getServer(), null); WebAppClassLoader.runWithServerClassAccess(()->{configuration.configure(context);return null;}); } diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java index a412cdd063f..6dd531ead1f 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/PreconfigureQuickStartWar.java @@ -105,7 +105,7 @@ public class PreconfigureQuickStartWar { if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) error("Bad context.xml: "+xml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(xml); xmlConfiguration.configure(webapp); } webapp.setResourceBase(dir.getFile().getAbsolutePath()); diff --git a/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java b/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java index 76ad8c155b2..cb28acd362d 100644 --- a/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java +++ b/jetty-runner/src/main/java/org/eclipse/jetty/runner/Runner.java @@ -327,7 +327,7 @@ public class Runner for (String cfg : _configFiles) { try (Resource resource = Resource.newResource(cfg)) { - XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(resource); xmlConfiguration.configure(_server); } } @@ -432,7 +432,7 @@ public class Runner if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) { // It is a context config file - XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx); xmlConfiguration.getIdMap().put("Server", _server); ContextHandler handler = (ContextHandler) xmlConfiguration.configure(); if (contextPathSet) diff --git a/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java b/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java index cc8a7ba7143..646e1440a0a 100644 --- a/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java +++ b/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.spring; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Map; @@ -69,18 +68,25 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor private String _main; @Override - public void init(URL url, XmlParser.Node config, XmlConfiguration configuration) + public void init(org.eclipse.jetty.util.resource.Resource jettyResource, XmlParser.Node config, XmlConfiguration configuration) { try { _configuration = configuration; - Resource resource = url != null - ? new UrlResource(url) - : new ByteArrayResource(("" + - "" + - "" + - config).getBytes(StandardCharsets.UTF_8)); + Resource springResource; + + if (jettyResource != null) + { + springResource = new UrlResource(jettyResource.getURI()); + } + else + { + springResource = new ByteArrayResource(("" + + "" + + "" + + config).getBytes(StandardCharsets.UTF_8)); + } _beanFactory = new DefaultListableBeanFactory() { @@ -92,7 +98,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor } }; - new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource); + new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource); } catch (Exception e) { diff --git a/jetty-spring/src/test/java/org/eclipse/jetty/spring/SpringXmlConfigurationTest.java b/jetty-spring/src/test/java/org/eclipse/jetty/spring/SpringXmlConfigurationTest.java index 6e7bd866c9e..40e4f4deb2e 100644 --- a/jetty-spring/src/test/java/org/eclipse/jetty/spring/SpringXmlConfigurationTest.java +++ b/jetty-spring/src/test/java/org/eclipse/jetty/spring/SpringXmlConfigurationTest.java @@ -18,9 +18,6 @@ package org.eclipse.jetty.spring; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -29,16 +26,20 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + public class SpringXmlConfigurationTest { protected String _configure="org/eclipse/jetty/spring/configure.xml"; @BeforeEach - public void init() throws Exception + public void init() { // Jetty's XML configuration will make use of java.util.ServiceLoader // to load the proper ConfigurationProcessorFactory, so these tests @@ -60,7 +61,7 @@ public class SpringXmlConfigurationTest TestConfiguration.VALUE=77; URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); - XmlConfiguration configuration = new XmlConfiguration(url); + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url)); Map properties = new HashMap<>(); properties.put("test", "xxx"); @@ -100,7 +101,7 @@ public class SpringXmlConfigurationTest URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); final AtomicInteger count = new AtomicInteger(0); - XmlConfiguration configuration = new XmlConfiguration(url) + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url)) { @Override public void initializeDefaults(Object object) @@ -147,7 +148,7 @@ public class SpringXmlConfigurationTest public void testJettyXml() throws Exception { URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource("org/eclipse/jetty/spring/jetty.xml"); - XmlConfiguration configuration = new XmlConfiguration(url); + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url)); Server server = (Server)configuration.configure(); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java index e0d5a3b14fa..a6963dddc79 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java @@ -78,7 +78,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration Object xml_attr=context.getAttribute(XML_CONFIGURATION); context.removeAttribute(XML_CONFIGURATION); - final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty.getURI().toURL()); + final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty); setupXmlConfiguration(context, jetty_config, web_inf); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java index dafd14d5bd5..e0539fc51d8 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/XmlHttpClientProvider.java @@ -18,11 +18,11 @@ package org.eclipse.jetty.websocket.core.client; -import java.io.InputStream; import java.net.URL; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; class XmlHttpClientProvider implements HttpClientProvider @@ -35,11 +35,11 @@ class XmlHttpClientProvider implements HttpClientProvider { return null; } - - try (InputStream in = resource.openStream()) + + try { - XmlConfiguration configuration = new XmlConfiguration(in); - return (HttpClient)configuration.configure(); + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(resource)); + return (HttpClient) configuration.configure(); } catch (Throwable t) { diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/ConfigurationProcessor.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/ConfigurationProcessor.java index c67b25899dc..1262e44df63 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/ConfigurationProcessor.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/ConfigurationProcessor.java @@ -18,21 +18,28 @@ package org.eclipse.jetty.xml; -import java.net.URL; +import org.eclipse.jetty.util.resource.Resource; /** * A ConfigurationProcessor for non XmlConfiguration format files. *

* A file in non-XmlConfiguration file format may be processed by a {@link ConfigurationProcessor} * instance that is returned from a {@link ConfigurationProcessorFactory} instance discovered by the - * ServiceLoader mechanism. This is used to allow spring configuration files to be used instead of - * jetty.xml - * + * {@code ServiceLoader} mechanism. This is used to allow spring configuration files to be used instead of + * {@code jetty.xml} */ public interface ConfigurationProcessor { - public void init(URL url, XmlParser.Node root, XmlConfiguration configuration); - - public Object configure( Object obj) throws Exception; - public Object configure() throws Exception; + /** + * Initialize a ConfigurationProcessor from provided Resource and XML + * + * @param resource the resource being read + * @param root the parsed XML root node for the resource + * @param configuration the configuration being used (typically for ref IDs) + */ + void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration); + + Object configure(Object obj) throws Exception; + + Object configure() throws Exception; } diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index c84df5530bf..8f35c4b343b 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.xml; import java.io.IOException; import java.io.InputStream; -import java.io.StringReader; import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Constructor; @@ -30,7 +29,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.InetAddress; import java.net.MalformedURLException; -import java.net.URI; import java.net.URL; import java.net.UnknownHostException; import java.nio.file.Path; @@ -63,7 +61,6 @@ import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** @@ -101,13 +98,13 @@ public class XmlConfiguration private static XmlParser initParser() { + ClassLoader loader = XmlConfiguration.class.getClassLoader(); XmlParser parser = new XmlParser(); - Class klass = XmlConfiguration.class; - URL config60 = klass.getResource("configure_6_0.dtd"); - URL config76 = klass.getResource("configure_7_6.dtd"); - URL config90 = klass.getResource("configure_9_0.dtd"); - URL config93 = klass.getResource("configure_9_3.dtd"); + URL config60 = loader.getResource("configure_6_0.dtd"); + URL config76 = loader.getResource("configure_7_6.dtd"); + URL config90 = loader.getResource("configure_9_0.dtd"); + URL config93 = loader.getResource("configure_9_3.dtd"); parser.redirectEntity("configure.dtd",config93); parser.redirectEntity("configure_1_0.dtd",config60); parser.redirectEntity("configure_1_1.dtd",config60); @@ -185,81 +182,38 @@ public class XmlConfiguration private final Map _idMap = new HashMap<>(); private final Map _propertyMap = new HashMap<>(); - private final URL _url; + private final Resource _location; private final String _dtd; private ConfigurationProcessor _processor; /** * Reads and parses the XML configuration file. * - * @param configuration the URL of the XML configuration + * @param resource the Resource to the XML configuration * @throws IOException if the configuration could not be read * @throws SAXException if the configuration could not be parsed */ - public XmlConfiguration(URL configuration) throws SAXException, IOException + public XmlConfiguration(Resource resource) throws SAXException, IOException { synchronized (__parser) { - _url = configuration; - setConfig(__parser.parse(configuration.toString())); + _location = resource; + try(InputStream inputStream = resource.getInputStream()) + { + setConfig(__parser.parse(inputStream)); + } _dtd = __parser.getDTD(); } } - /** - * Reads and parses the XML configuration file. - * - * @param configuration the URI of the XML configuration - * @throws IOException if the configuration could not be read - * @throws SAXException if the configuration could not be parsed - */ - public XmlConfiguration(URI configuration) throws SAXException, IOException + @Override + public String toString() { - synchronized (__parser) + if (_location == null) { - _url=configuration.toURL(); - setConfig(__parser.parse(configuration.toString())); - _dtd=__parser.getDTD(); - } - } - - /** - * Reads and parses the XML configuration string. - * - * @param configuration String of XML configuration commands excluding the normal XML preamble. - * The String should start with a "<Configure ....>" element. - * @throws IOException if the configuration could not be read - * @throws SAXException if the configuration could not be parsed - */ - public XmlConfiguration(String configuration) throws SAXException, IOException - { - configuration = "\n" - + configuration; - InputSource source = new InputSource(new StringReader(configuration)); - synchronized (__parser) - { - _url = null; - setConfig(__parser.parse(source)); - _dtd = __parser.getDTD(); - } - } - - /** - * Reads and parses the XML configuration stream. - * - * @param configuration An input stream containing a complete configuration file - * @throws IOException if the configuration could not be read - * @throws SAXException if the configuration could not be parsed - */ - public XmlConfiguration(InputStream configuration) throws SAXException, IOException - { - InputSource source = new InputSource(configuration); - synchronized (__parser) - { - _url = null; - setConfig(__parser.parse(source)); - _dtd = __parser.getDTD(); + return "UNKNOWN-LOCATION"; } + return _location.toString(); } private void setConfig(XmlParser.Node config) @@ -283,7 +237,7 @@ public class XmlConfiguration { throw new IllegalArgumentException("Unknown XML tag:" + config.getTag()); } - _processor.init(_url, config, this); + _processor.init(_location, config, this); } /** @@ -358,14 +312,12 @@ public class XmlConfiguration private static class JettyXmlConfiguration implements ConfigurationProcessor { - private String _url; XmlParser.Node _root; XmlConfiguration _configuration; @Override - public void init(URL url, XmlParser.Node root, XmlConfiguration configuration) + public void init(Resource resource, XmlParser.Node root, XmlConfiguration configuration) { - _url = url == null ? null : url.toString(); _root = root; _configuration = configuration; } @@ -378,7 +330,7 @@ public class XmlConfiguration if (oClass != null && !oClass.isInstance(obj)) { String loaders = (oClass.getClassLoader() == obj.getClass().getClassLoader()) ? "" : "Object Class and type Class are from different loaders."; - throw new IllegalArgumentException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders + " in " + _url); + throw new IllegalArgumentException("Object of class '" + obj.getClass().getCanonicalName() + "' is not of type '" + oClass.getCanonicalName() + "'. " + loaders + " in " + _configuration); } String id = _root.getAttribute("id"); if (id != null) @@ -430,7 +382,7 @@ public class XmlConfiguration } catch (NoSuchMethodException x) { - throw new IllegalStateException(String.format("No constructor %s(%s,%s) in %s", oClass, arguments, namedArgMap, _url)); + throw new IllegalStateException(String.format("No constructor %s(%s,%s) in %s", oClass, arguments, namedArgMap, _configuration)); } } if (id != null) @@ -522,12 +474,12 @@ public class XmlConfiguration envObj(node); break; default: - throw new IllegalStateException("Unknown tag: " + tag + " in " + _url); + throw new IllegalStateException("Unknown tag: " + tag + " in " + _configuration); } } catch (Exception e) { - LOG.warn("Config error at " + node, e.toString() + " in " + _url); + LOG.warn("Config error at " + node, e.toString() + " in " + _configuration); throw e; } } @@ -703,7 +655,7 @@ public class XmlConfiguration { Object result = constructor.newInstance(args); if (constructor.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated constructor {} in {}", constructor, _url); + LOG.warn("Deprecated constructor {} in {}", constructor, _configuration); return result; } @@ -711,7 +663,7 @@ public class XmlConfiguration { Object result = method.invoke(obj, args); if (method.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated method {} in {}", method, _url); + LOG.warn("Deprecated method {} in {}", method, _configuration); return result; } @@ -719,7 +671,7 @@ public class XmlConfiguration { Object result = field.get(object); if (field.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated field {} in {}", field, _url); + LOG.warn("Deprecated field {} in {}", field, _configuration); return result; } @@ -727,7 +679,7 @@ public class XmlConfiguration { field.set(obj, arg); if (field.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated field {} in {}", field, _url); + LOG.warn("Deprecated field {} in {}", field, _configuration); } /** @@ -1545,7 +1497,7 @@ public class XmlConfiguration if ("Env".equals(tag)) return envObj(node); - LOG.warn("Unknown value tag: " + node, new Throwable()); + LOG.warn("Unknown value tag: " + node + " in " + _configuration, new Throwable()); return null; } @@ -1754,7 +1706,7 @@ public class XmlConfiguration { if (!arg.toLowerCase(Locale.ENGLISH).endsWith(".properties") && (arg.indexOf('=') < 0)) { - XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(arg).getURI().toURL()); + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(arg)); if (last != null) configuration.getIdMap().putAll(last.getIdMap()); if (properties.size() > 0) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index c3e1cb5761d..70d86d773ec 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -18,12 +18,13 @@ package org.eclipse.jetty.xml; -import java.io.ByteArrayInputStream; +import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.net.URL; -import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; @@ -33,13 +34,19 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.xml.sax.SAXException; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @@ -53,8 +60,11 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +@ExtendWith(WorkDirExtension.class) public class XmlConfigurationTest { + public WorkDir workDir; + protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"}; private static final String STRING_ARRAY_XML = "String1String2"; @@ -64,7 +74,8 @@ public class XmlConfigurationTest public void testMortBay() throws Exception { URL url = XmlConfigurationTest.class.getResource("mortbay.xml"); - XmlConfiguration configuration = new XmlConfiguration(url); + Resource resource = Resource.newResource(url); + XmlConfiguration configuration = new XmlConfiguration(resource); configuration.configure(); } @@ -77,7 +88,7 @@ public class XmlConfigurationTest properties.put("whatever", "xxx"); TestConfiguration.VALUE=77; URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure); - XmlConfiguration configuration = new XmlConfiguration(url); + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url)); TestConfiguration tc = new TestConfiguration("tc"); configuration.getProperties().putAll(properties); configuration.configure(tc); @@ -156,7 +167,7 @@ public class XmlConfigurationTest URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure); final AtomicInteger count = new AtomicInteger(0); - XmlConfiguration configuration = new XmlConfiguration(url) + XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url)) { @Override public void initializeDefaults(Object object) @@ -236,18 +247,26 @@ public class XmlConfigurationTest } } + public XmlConfiguration asXmlConfiguration(String rawXml) throws IOException, SAXException + { + Path testFile = workDir.getEmptyPathDir().resolve("raw.xml"); + try(BufferedWriter writer = Files.newBufferedWriter(testFile, UTF_8)) + { + writer.write(rawXml); + } + return new XmlConfiguration(new PathResource(testFile)); + } @Test public void testGetClass() throws Exception { - XmlConfiguration configuration = - new XmlConfiguration(""); + XmlConfiguration configuration = asXmlConfiguration(""); TestConfiguration tc = new TestConfiguration(); configuration.configure(tc); assertEquals(TestConfiguration.class,tc.testObject); configuration = - new XmlConfiguration(""); + asXmlConfiguration(""); configuration.configure(tc); assertEquals(String.class,tc.testObject); assertEquals("String",configuration.getIdMap().get("simple")); @@ -256,8 +275,7 @@ public class XmlConfigurationTest @Test public void testStringConfiguration() throws Exception { - XmlConfiguration configuration = - new XmlConfiguration("SetValue2"); + XmlConfiguration configuration = asXmlConfiguration("SetValue2"); TestConfiguration tc = new TestConfiguration(); configuration.configure(tc); assertEquals("SetValue", tc.testObject, "Set String 3"); @@ -267,8 +285,7 @@ public class XmlConfigurationTest @Test public void testMeaningfullSetException() throws Exception { - XmlConfiguration configuration = - new XmlConfiguration(""); + XmlConfiguration configuration = asXmlConfiguration(""); TestConfiguration tc = new TestConfiguration(); NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> { @@ -281,7 +298,7 @@ public class XmlConfigurationTest @Test public void testListConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); @@ -294,7 +311,7 @@ public class XmlConfigurationTest @Test public void testTwoArgumentListConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + "" + STRING_ARRAY_XML + "" + "" + STRING_ARRAY_XML + "" @@ -309,7 +326,7 @@ public class XmlConfigurationTest @Test public void testListNotContainingArray() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "Some String"); TestConfiguration tc = new TestConfiguration(); @@ -321,7 +338,7 @@ public class XmlConfigurationTest @Test public void testSetConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); @@ -334,7 +351,7 @@ public class XmlConfigurationTest @Test public void testSetNotContainingArray() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "Some String"); TestConfiguration tc = new TestConfiguration(); assertThrows(IllegalArgumentException.class, ()->{ @@ -345,7 +362,7 @@ public class XmlConfigurationTest @Test public void testListSetterWithStringArray() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue())); @@ -356,7 +373,7 @@ public class XmlConfigurationTest @Test public void testListSetterWithPrimitiveArray() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue())); @@ -367,7 +384,7 @@ public class XmlConfigurationTest @Test public void testNotSupportedLinkedListSetter() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); @@ -379,7 +396,7 @@ public class XmlConfigurationTest @Test public void testArrayListSetter() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); @@ -390,7 +407,7 @@ public class XmlConfigurationTest @Test public void testSetSetter() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); @@ -401,7 +418,7 @@ public class XmlConfigurationTest @Test public void testSetSetterWithPrimitiveArray() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); @@ -412,7 +429,7 @@ public class XmlConfigurationTest @Test public void testMap() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + " " + @@ -436,7 +453,7 @@ public class XmlConfigurationTest @Test public void testConstructorNamedInjection() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -453,7 +470,7 @@ public class XmlConfigurationTest @Test public void testConstructorNamedInjectionOrdered() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -470,7 +487,7 @@ public class XmlConfigurationTest @Test public void testConstructorNamedInjectionUnOrdered() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg3 " + @@ -487,7 +504,7 @@ public class XmlConfigurationTest @Test public void testConstructorNamedInjectionOrderedMixed() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -504,7 +521,7 @@ public class XmlConfigurationTest @Test public void testConstructorNamedInjectionUnorderedMixed() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg3 " + " arg2 " + @@ -521,7 +538,7 @@ public class XmlConfigurationTest @Test public void testNestedConstructorNamedInjection() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -549,7 +566,7 @@ public class XmlConfigurationTest @Test public void testNestedConstructorNamedInjectionOrdered() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -576,7 +593,7 @@ public class XmlConfigurationTest @Test public void testNestedConstructorNamedInjectionUnOrdered() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg3 " + @@ -603,7 +620,7 @@ public class XmlConfigurationTest @Test public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -630,7 +647,7 @@ public class XmlConfigurationTest @Test public void testArgumentsGetIgnoredMissingDTD() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -642,8 +659,7 @@ public class XmlConfigurationTest " arg3\n" + " " + " " + - "").getBytes(StandardCharsets.ISO_8859_1))); -// XmlConfiguration xmlConfiguration = new XmlConfiguration(url); + ""); AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure(); @@ -658,7 +674,7 @@ public class XmlConfigurationTest @Test public void testSetGetIgnoredMissingDTD() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg1 " + " arg2 " + @@ -670,8 +686,7 @@ public class XmlConfigurationTest " arg3 " + " " + " " + - "").getBytes(StandardCharsets.UTF_8))); -// XmlConfiguration xmlConfiguration = new XmlConfiguration(url); + ""); DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure(); @@ -686,7 +701,7 @@ public class XmlConfigurationTest @Test public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " arg3 " + " arg2 " + @@ -751,7 +766,7 @@ public class XmlConfigurationTest @Test public void testSetBooleanTrue() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " true" + ""); @@ -763,7 +778,7 @@ public class XmlConfigurationTest @Test public void testSetBooleanFalse() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " false" + ""); @@ -776,7 +791,7 @@ public class XmlConfigurationTest @Disabled public void testSetBadBoolean() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " tru" + ""); @@ -788,7 +803,7 @@ public class XmlConfigurationTest @Test public void testSetBadInteger() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " bad" + ""); @@ -801,7 +816,7 @@ public class XmlConfigurationTest @Test public void testSetBadExtraInteger() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " 100 bas" + ""); @@ -814,7 +829,7 @@ public class XmlConfigurationTest @Test public void testSetBadFloatInteger() throws Exception { - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " 1.5" + ""); @@ -829,7 +844,7 @@ public class XmlConfigurationTest { // No properties String defolt = "baz"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + ""); @@ -842,7 +857,7 @@ public class XmlConfigurationTest { String name = "foo"; String value = "foo"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + ""); @@ -856,7 +871,7 @@ public class XmlConfigurationTest { String name = "bar"; String value = "bar"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + ""); @@ -870,7 +885,7 @@ public class XmlConfigurationTest { String name = "bar"; String value = "bar"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + ""); @@ -884,7 +899,7 @@ public class XmlConfigurationTest { String name = "bar"; String value = "bar"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + " " + @@ -907,7 +922,7 @@ public class XmlConfigurationTest String value = "bar"; String defaultValue = "___"; String expectedValue = "_" + value + "_" + value + "_"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + " " + @@ -925,7 +940,7 @@ public class XmlConfigurationTest public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception { String value = "bar"; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " " + " " + @@ -948,7 +963,7 @@ public class XmlConfigurationTest for(String propName: propNames) { XmlConfiguration configuration = - new XmlConfiguration("" + + asXmlConfiguration("" + "" + " " + " " + @@ -976,7 +991,7 @@ public class XmlConfigurationTest for(String propName: propNames) { XmlConfiguration configuration = - new XmlConfiguration("" + + asXmlConfiguration("" + "" + " " + " " + @@ -998,7 +1013,7 @@ public class XmlConfigurationTest { Path war = MavenTestingUtils.getTargetPath("no.war"); XmlConfiguration configuration = - new XmlConfiguration("" + + asXmlConfiguration("" + "" + " " + " " + @@ -1012,12 +1027,12 @@ public class XmlConfigurationTest assertThat("jetty.webapps.uri", tc.getTestString(), is(XmlConfiguration.normalizeURI(war.getParent().toUri().toString()))); } - + @Test public void testDeprecated() throws Exception { Class testClass = AnnotatedTestConfiguration.class; - XmlConfiguration xmlConfiguration = new XmlConfiguration("" + + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + "" + " foo" + " " + diff --git a/scripts/release-jetty.sh b/scripts/release-jetty.sh index eeddd4ab3dd..57ae4c9afbd 100755 --- a/scripts/release-jetty.sh +++ b/scripts/release-jetty.sh @@ -69,8 +69,6 @@ VER_CURRENT=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/versio echo "Current pom.xml Version: ${VER_CURRENT}" read -e -p "Release Version ? " VER_RELEASE read -e -p "Next Dev Version ? " VER_NEXT -# VER_RELEASE=9.3.5.v20151012 -# VER_NEXT=9.3.6-SNAPSHOT TAG_NAME="jetty-$VER_RELEASE" # Ensure tag doesn't exist (yet) @@ -89,9 +87,12 @@ if [ ! -d "$ALT_DEPLOY_DIR" ] ; then fi # DEPLOY_OPTS="-Dmaven.test.failure.ignore=true" -DEPLOY_OPTS="-Dtest=None" +DEPLOY_OPTS="-DskipTests -Dtest=None" # DEPLOY_OPTS="$DEPLOY_OPTS -DaltDeploymentRepository=intarget::default::file://$ALT_DEPLOY_DIR/" +# Uncomment for Java 1.7 +export MAVEN_OPTS="-Xmx1g -XX:MaxPermSize=128m" + echo "" echo "-----------------------------------------------" echo " Release Plan Review" @@ -103,6 +104,7 @@ echo "Current Version : $VER_CURRENT" echo "Release Version : $VER_RELEASE" echo "Next Dev Version : $VER_NEXT" echo "Tag name : $TAG_NAME" +echo "MAVEN_OPTS : $MAVEN_OPTS" echo "Maven Deploy Opts: $DEPLOY_OPTS" reportMavenTestFailures() { @@ -130,13 +132,20 @@ echo "" if proceedyn "Are you sure you want to release using above? (y/N)" n; then echo "" if proceedyn "Update VERSION.txt for $VER_RELEASE? (Y/n)" y; then + # Uncomment alternate JVM for jetty 9.2 builds + # JAVA_HOME_ORIG=$JAVA_HOME + # PATH_ORIG=$PATH + # JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home + # PATH=$JAVA_HOME/bin:$PATH mvn -N -Pupdate-version generate-resources cp VERSION.txt VERSION.txt.backup cat VERSION.txt.backup | sed -e "s/$VER_CURRENT/$VER_RELEASE/" > VERSION.txt rm VERSION.txt.backup + # JAVA_HOME=$JAVA_HOME_ORIG + # PATH=$PATH_ORIG echo "VERIFY the following files (in a different console window) before continuing." echo " VERSION.txt - top section" - echo " target/vers-tag.txt - for the tag commit message" + echo " target/version-tag.txt - for the tag commit message" fi # This is equivalent to 'mvn release:prepare' @@ -151,8 +160,8 @@ if proceedyn "Are you sure you want to release using above? (y/N)" n; then fi if proceedyn "Create Tag $TAG_NAME? (Y/n)" y; then echo "TODO: Sign tags with GIT_USER_EMAIL=$GIT_USER_EMAIL" - echo "Using target/vers-tag.txt as tag text" - git tag --file=target/vers-tag.txt $TAG_NAME + echo "Using target/version-tag.txt as tag text" + git tag --file=target/version-tag.txt $TAG_NAME fi # This is equivalent to 'mvn release:perform' @@ -170,9 +179,10 @@ if proceedyn "Are you sure you want to release using above? (y/N)" n; then echo "" >> VERSION.txt cat VERSION.txt.backup >> VERSION.txt echo "Update project.versions for $VER_NEXT" - mvn org.codehaus.mojo:versions-maven-plugin:2.1:set \ + mvn org.codehaus.mojo:versions-maven-plugin:2.7:set \ -DoldVersion="$VER_RELEASE" \ - -DnewVersion="$VER_NEXT" + -DnewVersion="$VER_NEXT" \ + -DprocessAllModules=true echo "Commit $VER_NEXT" if proceedyn "Commit updates in working directory for $VER_NEXT? (Y/n)" y; then git commit -a -m "Updating to version $VER_NEXT" diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java index a857b21e7c6..1b471ec48ca 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/XmlBasedJettyServer.java @@ -18,17 +18,12 @@ package org.eclipse.jetty.test.support; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; @@ -41,15 +36,21 @@ import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +import org.eclipse.jetty.util.resource.PathResource; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Allows for setting up a Jetty server for testing based on XML configuration files. */ public class XmlBasedJettyServer { private static final Logger LOG = Log.getLogger(XmlBasedJettyServer.class); - private List _xmlConfigurations; + private List _xmlConfigurations; private final Map _properties = new HashMap<>(); private Server _server; private int _serverPort; @@ -94,14 +95,14 @@ public class XmlBasedJettyServer _properties.put(String.valueOf(key),String.valueOf(properties.get(key))); } - public void addXmlConfiguration(URL xmlConfig) + public void addXmlConfiguration(Resource xmlConfig) { _xmlConfigurations.add(xmlConfig); } - public void addXmlConfiguration(File xmlConfigFile) throws MalformedURLException + public void addXmlConfiguration(File xmlConfigFile) { - _xmlConfigurations.add(xmlConfigFile.toURI().toURL()); + _xmlConfigurations.add(new PathResource(xmlConfigFile)); } public void addXmlConfiguration(String testConfigName) throws MalformedURLException @@ -122,9 +123,9 @@ public class XmlBasedJettyServer // Configure everything for (int i = 0; i < this._xmlConfigurations.size(); i++) { - URL configURL = this._xmlConfigurations.get(i); - LOG.debug("configuring: "+configURL); - XmlConfiguration configuration = new XmlConfiguration(configURL); + Resource configResource = this._xmlConfigurations.get(i); + LOG.debug("configuring: "+configResource); + XmlConfiguration configuration = new XmlConfiguration(configResource); if (last != null) { configuration.getIdMap().putAll(last.getIdMap()); diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java index b5d378ad0f3..971662cc225 100644 --- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java +++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java @@ -74,7 +74,7 @@ public class QuickStartTest if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml); xmlConfiguration.configure(webapp); } @@ -123,7 +123,7 @@ public class QuickStartTest if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml); xmlConfiguration.configure(webapp); } @@ -169,7 +169,7 @@ public class QuickStartTest if (contextXml != null) { // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI().toURL()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml); xmlConfiguration.configure(webapp); } diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java index c6c2a0a22fe..7b8cfcb6ac2 100644 --- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java +++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/Quickstart.java @@ -48,8 +48,7 @@ public class Quickstart //apply context xml file if (contextXml != null) { - // System.err.println("Applying "+contextXml); - XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); + XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml); xmlConfiguration.configure(webapp); }