Merge branch `jetty-9.4.x` into `jetty-10.0.x`

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-06-10 11:51:55 -05:00
commit 68a9498092
26 changed files with 229 additions and 235 deletions

View File

@ -36,9 +36,8 @@ public class FileServerXml
{ {
public static void main( String[] args ) throws Exception public static void main( String[] args ) throws Exception
{ {
Resource fileserverXml = Resource.newSystemResource("fileserver.xml"); Resource fileServerXml = Resource.newSystemResource("fileserver.xml");
XmlConfiguration configuration = new XmlConfiguration( XmlConfiguration configuration = new XmlConfiguration(fileServerXml);
fileserverXml.getInputStream());
Server server = (Server) configuration.configure(); Server server = (Server) configuration.configure();
server.start(); server.start();
server.join(); server.join();

View File

@ -52,6 +52,7 @@ import org.eclipse.jetty.servlet.ServletMapping;
import org.eclipse.jetty.servlet.Source; import org.eclipse.jetty.servlet.Source;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; 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.util.resource.Resource;
import org.eclipse.jetty.webapp.MetaInfConfiguration; import org.eclipse.jetty.webapp.MetaInfConfiguration;
import org.eclipse.jetty.webapp.WebAppClassLoader; import org.eclipse.jetty.webapp.WebAppClassLoader;
@ -608,7 +609,7 @@ public class AntWebAppContext extends WebAppContext
//apply a context xml file if one was supplied //apply a context xml file if one was supplied
if (contextXml != null) if (contextXml != null)
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(contextXml)); XmlConfiguration xmlConfiguration = new XmlConfiguration(new PathResource(contextXml));
TaskLog.log("Applying context xml file "+contextXml); TaskLog.log("Applying context xml file "+contextXml);
xmlConfiguration.configure(this); xmlConfiguration.configure(this);
} }

View File

@ -41,6 +41,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -451,7 +452,7 @@ public class ServerProxyImpl implements ServerProxy
XmlConfiguration configuration; XmlConfiguration configuration;
try try
{ {
configuration = new XmlConfiguration(Resource.toURL(jettyXml)); configuration = new XmlConfiguration(new PathResource(jettyXml));
configuration.configure(server); configuration.configure(server);
} }
catch (MalformedURLException e) catch (MalformedURLException e)

View File

@ -92,7 +92,7 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
if (globalContextSettings.exists()) if (globalContextSettings.exists())
{ {
XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream()); XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings);
Resource resource = Resource.newResource(app.getOriginId()); Resource resource = Resource.newResource(app.getOriginId());
app.getDeploymentManager().scope(jettyXmlConfig,resource); app.getDeploymentManager().scope(jettyXmlConfig,resource);
WebAppClassLoader.runWithServerClassAccess(()->{jettyXmlConfig.configure(context);return null;}); WebAppClassLoader.runWithServerClassAccess(()->{jettyXmlConfig.configure(context);return null;});

View File

@ -265,7 +265,7 @@ public class WebAppProvider extends ScanningAppProvider
if (resource.exists() && FileID.isXmlFile(file)) if (resource.exists() && FileID.isXmlFile(file))
{ {
XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL()) XmlConfiguration xmlc = new XmlConfiguration(resource)
{ {
@Override @Override
public void initializeDefaults(Object context) public void initializeDefaults(Object context)

View File

@ -18,13 +18,6 @@
package org.eclipse.jetty.deploy.test; 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.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; 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.toolchain.test.PathAssert;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration; 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. * Allows for setting up a Jetty server for testing based on XML configuration files.
*/ */
public class XmlConfiguredJetty public class XmlConfiguredJetty
{ {
private List<URL> _xmlConfigurations; private List<Resource> _xmlConfigurations;
private Map<String,String> _properties = new HashMap<>(); private Map<String,String> _properties = new HashMap<>();
private Server _server; private Server _server;
private int _serverPort; private int _serverPort;
@ -137,9 +138,9 @@ public class XmlConfiguredJetty
setProperty(String.valueOf(key),String.valueOf(properties.get(key))); 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 public void addConfiguration(String testConfigName) throws MalformedURLException
@ -147,7 +148,7 @@ public class XmlConfiguredJetty
addConfiguration(MavenTestingUtils.getTestResourceFile(testConfigName)); addConfiguration(MavenTestingUtils.getTestResourceFile(testConfigName));
} }
public void addConfiguration(URL xmlConfig) public void addConfiguration(Resource xmlConfig)
{ {
_xmlConfigurations.add(xmlConfig); _xmlConfigurations.add(xmlConfig);
} }
@ -330,8 +331,8 @@ public class XmlConfiguredJetty
// Configure everything // Configure everything
for (int i = 0; i < this._xmlConfigurations.size(); i++) for (int i = 0; i < this._xmlConfigurations.size(); i++)
{ {
URL configURL = this._xmlConfigurations.get(i); Resource configResource = this._xmlConfigurations.get(i);
XmlConfiguration configuration = new XmlConfiguration(configURL); XmlConfiguration configuration = new XmlConfiguration(configResource);
if (last != null) if (last != null)
configuration.getIdMap().putAll(last.getIdMap()); configuration.getIdMap().putAll(last.getIdMap());
configuration.getProperties().putAll(_properties); configuration.getProperties().putAll(_properties);

View File

@ -51,6 +51,7 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.PathWatcher; import org.eclipse.jetty.util.PathWatcher;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
@ -556,7 +557,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
contextXml = path.toFile().getAbsolutePath(); 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); getLog().info("Applying context xml file "+contextXml);
xmlConfiguration.configure(webApp); xmlConfiguration.configure(webApp);
} }

View File

@ -33,8 +33,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.Configurations;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
@ -194,7 +193,7 @@ public class ServerSupport
PluginLog.getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() ); 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 //add in any properties
if (properties != null) if (properties != null)

View File

@ -19,13 +19,9 @@
package org.eclipse.jetty.maven.plugin; package org.eclipse.jetty.maven.plugin;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -253,7 +249,7 @@ public class WebAppPropertyConverter
str = props.getProperty("context.xml"); str = props.getProperty("context.xml");
if (!StringUtil.isBlank(str)) 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); xmlConfiguration.getIdMap().put("Server",server);
//add in any properties //add in any properties
if (jettyProperties != null) if (jettyProperties != null)

View File

@ -158,7 +158,7 @@ public abstract class AbstractContextProvider extends AbstractLifeCycle implemen
{ {
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);
XmlConfiguration xmlConfiguration = new XmlConfiguration(res.getInputStream()); XmlConfiguration xmlConfiguration = new XmlConfiguration(res);
HashMap properties = new HashMap(); HashMap properties = new HashMap();
//put the server instance in //put the server instance in
properties.put("Server", getServerInstanceWrapper().getServer()); properties.put("Server", getServerInstanceWrapper().getServer());

View File

@ -414,7 +414,7 @@ public abstract class AbstractWebAppProvider extends AbstractLifeCycle implement
// Apply it just as the standard jetty ContextProvider would do // Apply it just as the standard jetty ContextProvider would do
LOG.info("Applying " + contextXmlUri + " to " + _webApp); LOG.info("Applying " + contextXmlUri + " to " + _webApp);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXmlUri); XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.newResource(contextXmlUri));
WebAppClassLoader.runWithServerClassAccess(()-> WebAppClassLoader.runWithServerClassAccess(()->
{ {
HashMap<String,String> properties = new HashMap<>(); HashMap<String,String> properties = new HashMap<>();

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.osgi.boot.internal.serverfactory; package org.eclipse.jetty.osgi.boot.internal.serverfactory;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; 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.StringUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
/** /**
@ -142,10 +142,10 @@ public class ServerInstanceWrapper
for (URL jettyConfiguration : jettyConfigurations) for (URL jettyConfiguration : jettyConfigurations)
{ {
try(InputStream in = jettyConfiguration.openStream()) try
{ {
// Execute a Jetty configuration file // Execute a Jetty configuration file
XmlConfiguration config = new XmlConfiguration(in); XmlConfiguration config = new XmlConfiguration(Resource.newResource(jettyConfiguration));
config.getIdMap().putAll(id_map); config.getIdMap().putAll(id_map);
config.getProperties().putAll(properties); config.getProperties().putAll(properties);

View File

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.naming.Binding; import javax.naming.Binding;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; 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.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; 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.AbstractConfiguration;
import org.eclipse.jetty.webapp.FragmentConfiguration; import org.eclipse.jetty.webapp.FragmentConfiguration;
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration; 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 Logger LOG = Log.getLogger(EnvConfiguration.class);
private static final String JETTY_ENV_BINDINGS = "org.eclipse.jetty.jndi.EnvConfiguration"; private static final String JETTY_ENV_BINDINGS = "org.eclipse.jetty.jndi.EnvConfiguration";
private URL jettyEnvXmlUrl; private Resource jettyEnvXmlResource;
public EnvConfiguration() public EnvConfiguration()
{ {
@ -66,9 +66,14 @@ public class EnvConfiguration extends AbstractConfiguration
protectAndExpose("org.eclipse.jetty.jndi."); protectAndExpose("org.eclipse.jetty.jndi.");
} }
public void setJettyEnvResource(Resource resource)
{
this.jettyEnvXmlResource = resource;
}
public void setJettyEnvXml (URL url) public void setJettyEnvXml (URL url)
{ {
this.jettyEnvXmlUrl = url; this.jettyEnvXmlResource = Resource.newResource(url);
} }
@Override @Override
@ -86,7 +91,7 @@ public class EnvConfiguration extends AbstractConfiguration
//check to see if an explicit file has been set, if not, //check to see if an explicit file has been set, if not,
//look in WEB-INF/jetty-env.xml //look in WEB-INF/jetty-env.xml
if (jettyEnvXmlUrl == null) if (jettyEnvXmlResource == null)
{ {
//look for a file called WEB-INF/jetty-env.xml //look for a file called WEB-INF/jetty-env.xml
//and process it if it exists //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"); org.eclipse.jetty.util.resource.Resource jettyEnv = web_inf.addPath("jetty-env.xml");
if(jettyEnv.exists()) if(jettyEnv.exists())
{ {
jettyEnvXmlUrl = jettyEnv.getURI().toURL(); jettyEnvXmlResource = jettyEnv;
} }
} }
} }
if (jettyEnvXmlUrl != null) if (jettyEnvXmlResource != null)
{ {
synchronized (localContextRoot.getRoot()) synchronized (localContextRoot.getRoot())
{ {
@ -125,7 +130,7 @@ public class EnvConfiguration extends AbstractConfiguration
try try
{ {
localContextRoot.getRoot().addListener(listener); localContextRoot.getRoot().addListener(listener);
XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlUrl); XmlConfiguration configuration = new XmlConfiguration(jettyEnvXmlResource);
configuration.setJettyStandardIdsAndProperties(context.getServer(), null); configuration.setJettyStandardIdsAndProperties(context.getServer(), null);
WebAppClassLoader.runWithServerClassAccess(()->{configuration.configure(context);return null;}); WebAppClassLoader.runWithServerClassAccess(()->{configuration.configure(context);return null;});
} }

View File

@ -105,7 +105,7 @@ public class PreconfigureQuickStartWar
{ {
if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
error("Bad context.xml: "+xml); error("Bad context.xml: "+xml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(xml.getURI()); XmlConfiguration xmlConfiguration = new XmlConfiguration(xml);
xmlConfiguration.configure(webapp); xmlConfiguration.configure(webapp);
} }
webapp.setResourceBase(dir.getFile().getAbsolutePath()); webapp.setResourceBase(dir.getFile().getAbsolutePath());

View File

@ -327,7 +327,7 @@ public class Runner
for (String cfg : _configFiles) for (String cfg : _configFiles)
{ {
try (Resource resource = Resource.newResource(cfg)) { try (Resource resource = Resource.newResource(cfg)) {
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURI()); XmlConfiguration xmlConfiguration = new XmlConfiguration(resource);
xmlConfiguration.configure(_server); xmlConfiguration.configure(_server);
} }
} }
@ -432,7 +432,7 @@ public class Runner
if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml")) if (!ctx.isDirectory() && ctx.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))
{ {
// It is a context config file // It is a context config file
XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx.getURI()); XmlConfiguration xmlConfiguration = new XmlConfiguration(ctx);
xmlConfiguration.getIdMap().put("Server", _server); xmlConfiguration.getIdMap().put("Server", _server);
ContextHandler handler = (ContextHandler) xmlConfiguration.configure(); ContextHandler handler = (ContextHandler) xmlConfiguration.configure();
if (contextPathSet) if (contextPathSet)

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.spring; package org.eclipse.jetty.spring;
import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
@ -69,18 +68,25 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
private String _main; private String _main;
@Override @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 try
{ {
_configuration = configuration; _configuration = configuration;
Resource resource = url != null Resource springResource;
? new UrlResource(url)
: new ByteArrayResource(("" + if (jettyResource != null)
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + {
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" + springResource = new UrlResource(jettyResource.getURI());
config).getBytes(StandardCharsets.UTF_8)); }
else
{
springResource = new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
config).getBytes(StandardCharsets.UTF_8));
}
_beanFactory = new DefaultListableBeanFactory() _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) catch (Exception e)
{ {

View File

@ -18,9 +18,6 @@
package org.eclipse.jetty.spring; 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.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -29,16 +26,20 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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 public class SpringXmlConfigurationTest
{ {
protected String _configure="org/eclipse/jetty/spring/configure.xml"; protected String _configure="org/eclipse/jetty/spring/configure.xml";
@BeforeEach @BeforeEach
public void init() throws Exception public void init()
{ {
// Jetty's XML configuration will make use of java.util.ServiceLoader // Jetty's XML configuration will make use of java.util.ServiceLoader
// to load the proper ConfigurationProcessorFactory, so these tests // to load the proper ConfigurationProcessorFactory, so these tests
@ -60,7 +61,7 @@ public class SpringXmlConfigurationTest
TestConfiguration.VALUE=77; TestConfiguration.VALUE=77;
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
XmlConfiguration configuration = new XmlConfiguration(url); XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url));
Map<String,String> properties = new HashMap<>(); Map<String,String> properties = new HashMap<>();
properties.put("test", "xxx"); properties.put("test", "xxx");
@ -100,7 +101,7 @@ public class SpringXmlConfigurationTest
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure); URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
XmlConfiguration configuration = new XmlConfiguration(url) XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url))
{ {
@Override @Override
public void initializeDefaults(Object object) public void initializeDefaults(Object object)
@ -147,7 +148,7 @@ public class SpringXmlConfigurationTest
public void testJettyXml() throws Exception public void testJettyXml() throws Exception
{ {
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource("org/eclipse/jetty/spring/jetty.xml"); 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(); Server server = (Server)configuration.configure();

View File

@ -78,7 +78,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
Object xml_attr=context.getAttribute(XML_CONFIGURATION); Object xml_attr=context.getAttribute(XML_CONFIGURATION);
context.removeAttribute(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); setupXmlConfiguration(context, jetty_config, web_inf);

View File

@ -18,11 +18,11 @@
package org.eclipse.jetty.websocket.core.client; package org.eclipse.jetty.websocket.core.client;
import java.io.InputStream;
import java.net.URL; import java.net.URL;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
class XmlHttpClientProvider implements HttpClientProvider class XmlHttpClientProvider implements HttpClientProvider
@ -35,11 +35,11 @@ class XmlHttpClientProvider implements HttpClientProvider
{ {
return null; return null;
} }
try (InputStream in = resource.openStream()) try
{ {
XmlConfiguration configuration = new XmlConfiguration(in); XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(resource));
return (HttpClient)configuration.configure(); return (HttpClient) configuration.configure();
} }
catch (Throwable t) catch (Throwable t)
{ {

View File

@ -18,21 +18,28 @@
package org.eclipse.jetty.xml; package org.eclipse.jetty.xml;
import java.net.URL; import org.eclipse.jetty.util.resource.Resource;
/** /**
* A ConfigurationProcessor for non XmlConfiguration format files. * A ConfigurationProcessor for non XmlConfiguration format files.
* <p> * <p>
* A file in non-XmlConfiguration file format may be processed by a {@link ConfigurationProcessor} * 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 * instance that is returned from a {@link ConfigurationProcessorFactory} instance discovered by the
* <code>ServiceLoader</code> mechanism. This is used to allow spring configuration files to be used instead of * {@code ServiceLoader} mechanism. This is used to allow spring configuration files to be used instead of
* jetty.xml * {@code jetty.xml}
*
*/ */
public interface ConfigurationProcessor public interface ConfigurationProcessor
{ {
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration); /**
* Initialize a ConfigurationProcessor from provided Resource and XML
public Object configure( Object obj) throws Exception; *
public Object configure() throws Exception; * @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;
} }

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.xml;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -30,7 +29,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.file.Path; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
@ -101,13 +98,13 @@ public class XmlConfiguration
private static XmlParser initParser() private static XmlParser initParser()
{ {
ClassLoader loader = XmlConfiguration.class.getClassLoader();
XmlParser parser = new XmlParser(); XmlParser parser = new XmlParser();
Class<?> klass = XmlConfiguration.class; URL config60 = loader.getResource("configure_6_0.dtd");
URL config60 = klass.getResource("configure_6_0.dtd"); URL config76 = loader.getResource("configure_7_6.dtd");
URL config76 = klass.getResource("configure_7_6.dtd"); URL config90 = loader.getResource("configure_9_0.dtd");
URL config90 = klass.getResource("configure_9_0.dtd"); URL config93 = loader.getResource("configure_9_3.dtd");
URL config93 = klass.getResource("configure_9_3.dtd");
parser.redirectEntity("configure.dtd",config93); parser.redirectEntity("configure.dtd",config93);
parser.redirectEntity("configure_1_0.dtd",config60); parser.redirectEntity("configure_1_0.dtd",config60);
parser.redirectEntity("configure_1_1.dtd",config60); parser.redirectEntity("configure_1_1.dtd",config60);
@ -185,81 +182,38 @@ public class XmlConfiguration
private final Map<String, Object> _idMap = new HashMap<>(); private final Map<String, Object> _idMap = new HashMap<>();
private final Map<String, String> _propertyMap = new HashMap<>(); private final Map<String, String> _propertyMap = new HashMap<>();
private final URL _url; private final Resource _location;
private final String _dtd; private final String _dtd;
private ConfigurationProcessor _processor; private ConfigurationProcessor _processor;
/** /**
* Reads and parses the XML configuration file. * 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 IOException if the configuration could not be read
* @throws SAXException if the configuration could not be parsed * @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) synchronized (__parser)
{ {
_url = configuration; _location = resource;
setConfig(__parser.parse(configuration.toString())); try(InputStream inputStream = resource.getInputStream())
{
setConfig(__parser.parse(inputStream));
}
_dtd = __parser.getDTD(); _dtd = __parser.getDTD();
} }
} }
/** @Override
* Reads and parses the XML configuration file. public String toString()
*
* @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
{ {
synchronized (__parser) if (_location == null)
{ {
_url=configuration.toURL(); return "UNKNOWN-LOCATION";
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 "&lt;Configure ....&gt;" 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 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE Configure PUBLIC \"-//Jetty//Configure//EN\" \"https://www.eclipse.org/jetty/configure.dtd\">"
+ 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 _location.toString();
} }
private void setConfig(XmlParser.Node config) private void setConfig(XmlParser.Node config)
@ -283,7 +237,7 @@ public class XmlConfiguration
{ {
throw new IllegalArgumentException("Unknown XML tag:" + config.getTag()); 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 static class JettyXmlConfiguration implements ConfigurationProcessor
{ {
private String _url;
XmlParser.Node _root; XmlParser.Node _root;
XmlConfiguration _configuration; XmlConfiguration _configuration;
@Override @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; _root = root;
_configuration = configuration; _configuration = configuration;
} }
@ -378,7 +330,7 @@ public class XmlConfiguration
if (oClass != null && !oClass.isInstance(obj)) if (oClass != null && !oClass.isInstance(obj))
{ {
String loaders = (oClass.getClassLoader() == obj.getClass().getClassLoader()) ? "" : "Object Class and type Class are from different loaders."; 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"); String id = _root.getAttribute("id");
if (id != null) if (id != null)
@ -430,7 +382,7 @@ public class XmlConfiguration
} }
catch (NoSuchMethodException x) 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) if (id != null)
@ -522,12 +474,12 @@ public class XmlConfiguration
envObj(node); envObj(node);
break; break;
default: default:
throw new IllegalStateException("Unknown tag: " + tag + " in " + _url); throw new IllegalStateException("Unknown tag: " + tag + " in " + _configuration);
} }
} }
catch (Exception e) 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; throw e;
} }
} }
@ -703,7 +655,7 @@ public class XmlConfiguration
{ {
Object result = constructor.newInstance(args); Object result = constructor.newInstance(args);
if (constructor.getAnnotation(Deprecated.class) != null) if (constructor.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated constructor {} in {}", constructor, _url); LOG.warn("Deprecated constructor {} in {}", constructor, _configuration);
return result; return result;
} }
@ -711,7 +663,7 @@ public class XmlConfiguration
{ {
Object result = method.invoke(obj, args); Object result = method.invoke(obj, args);
if (method.getAnnotation(Deprecated.class) != null) if (method.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated method {} in {}", method, _url); LOG.warn("Deprecated method {} in {}", method, _configuration);
return result; return result;
} }
@ -719,7 +671,7 @@ public class XmlConfiguration
{ {
Object result = field.get(object); Object result = field.get(object);
if (field.getAnnotation(Deprecated.class) != null) if (field.getAnnotation(Deprecated.class) != null)
LOG.warn("Deprecated field {} in {}", field, _url); LOG.warn("Deprecated field {} in {}", field, _configuration);
return result; return result;
} }
@ -727,7 +679,7 @@ public class XmlConfiguration
{ {
field.set(obj, arg); field.set(obj, arg);
if (field.getAnnotation(Deprecated.class) != null) 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)) if ("Env".equals(tag))
return envObj(node); return envObj(node);
LOG.warn("Unknown value tag: " + node, new Throwable()); LOG.warn("Unknown value tag: " + node + " in " + _configuration, new Throwable());
return null; return null;
} }
@ -1754,7 +1706,7 @@ public class XmlConfiguration
{ {
if (!arg.toLowerCase(Locale.ENGLISH).endsWith(".properties") && (arg.indexOf('=') < 0)) 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) if (last != null)
configuration.getIdMap().putAll(last.getIdMap()); configuration.getIdMap().putAll(last.getIdMap());
if (properties.size() > 0) if (properties.size() > 0)

View File

@ -18,12 +18,13 @@
package org.eclipse.jetty.xml; package org.eclipse.jetty.xml;
import java.io.ByteArrayInputStream; import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -33,13 +34,19 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.util.resource.PathResource;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; 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.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is; 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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class XmlConfigurationTest public class XmlConfigurationTest
{ {
public WorkDir workDir;
protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"}; protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"};
private static final String STRING_ARRAY_XML = "<Array type=\"String\"><Item type=\"String\">String1</Item><Item type=\"String\">String2</Item></Array>"; private static final String STRING_ARRAY_XML = "<Array type=\"String\"><Item type=\"String\">String1</Item><Item type=\"String\">String2</Item></Array>";
@ -64,7 +74,8 @@ public class XmlConfigurationTest
public void testMortBay() throws Exception public void testMortBay() throws Exception
{ {
URL url = XmlConfigurationTest.class.getResource("mortbay.xml"); URL url = XmlConfigurationTest.class.getResource("mortbay.xml");
XmlConfiguration configuration = new XmlConfiguration(url); Resource resource = Resource.newResource(url);
XmlConfiguration configuration = new XmlConfiguration(resource);
configuration.configure(); configuration.configure();
} }
@ -77,7 +88,7 @@ public class XmlConfigurationTest
properties.put("whatever", "xxx"); properties.put("whatever", "xxx");
TestConfiguration.VALUE=77; TestConfiguration.VALUE=77;
URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure); URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure);
XmlConfiguration configuration = new XmlConfiguration(url); XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url));
TestConfiguration tc = new TestConfiguration("tc"); TestConfiguration tc = new TestConfiguration("tc");
configuration.getProperties().putAll(properties); configuration.getProperties().putAll(properties);
configuration.configure(tc); configuration.configure(tc);
@ -156,7 +167,7 @@ public class XmlConfigurationTest
URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure); URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure);
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
XmlConfiguration configuration = new XmlConfiguration(url) XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url))
{ {
@Override @Override
public void initializeDefaults(Object object) 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 @Test
public void testGetClass() throws Exception public void testGetClass() throws Exception
{ {
XmlConfiguration configuration = XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get name=\"class\"/></Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
configuration.configure(tc); configuration.configure(tc);
assertEquals(TestConfiguration.class,tc.testObject); assertEquals(TestConfiguration.class,tc.testObject);
configuration = configuration =
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get class=\"java.lang.String\" name=\"class\"><Get id=\"simple\" name=\"simpleName\"/></Get></Set></Configure>"); asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\"><Get class=\"java.lang.String\" name=\"class\"><Get id=\"simple\" name=\"simpleName\"/></Get></Set></Configure>");
configuration.configure(tc); configuration.configure(tc);
assertEquals(String.class,tc.testObject); assertEquals(String.class,tc.testObject);
assertEquals("String",configuration.getIdMap().get("simple")); assertEquals("String",configuration.getIdMap().get("simple"));
@ -256,8 +275,7 @@ public class XmlConfigurationTest
@Test @Test
public void testStringConfiguration() throws Exception public void testStringConfiguration() throws Exception
{ {
XmlConfiguration configuration = XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Test\">SetValue</Set><Set name=\"Test\" type=\"int\">2</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
configuration.configure(tc); configuration.configure(tc);
assertEquals("SetValue", tc.testObject, "Set String 3"); assertEquals("SetValue", tc.testObject, "Set String 3");
@ -267,8 +285,7 @@ public class XmlConfigurationTest
@Test @Test
public void testMeaningfullSetException() throws Exception public void testMeaningfullSetException() throws Exception
{ {
XmlConfiguration configuration = XmlConfiguration configuration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"PropertyTest\"><Property name=\"null\"/></Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> { NoSuchMethodException e = assertThrows(NoSuchMethodException.class, () -> {
@ -281,7 +298,7 @@ public class XmlConfigurationTest
@Test @Test
public void testListConstructorArg() throws Exception public void testListConstructorArg() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">" + "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">"
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>"); + STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
@ -294,7 +311,7 @@ public class XmlConfigurationTest
@Test @Test
public void testTwoArgumentListConstructorArg() throws Exception public void testTwoArgumentListConstructorArg() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\">" + "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\">"
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>" + "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
+ "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>" + "<Arg type=\"List\">" + STRING_ARRAY_XML + "</Arg>"
@ -309,7 +326,7 @@ public class XmlConfigurationTest
@Test @Test
public void testListNotContainingArray() throws Exception public void testListNotContainingArray() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">Some String</Arg></New></Configure>"); + "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"List\">Some String</Arg></New></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
@ -321,7 +338,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetConstructorArg() throws Exception public void testSetConstructorArg() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
+ "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">" + "<Set name=\"constructorArgTestClass\"><New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">"
+ STRING_ARRAY_XML + "</Arg></New></Set></Configure>"); + STRING_ARRAY_XML + "</Arg></New></Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
@ -334,7 +351,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetNotContainingArray() throws Exception public void testSetNotContainingArray() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">"
+ "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">Some String</Arg></New></Configure>"); + "<New class=\"org.eclipse.jetty.xml.ConstructorArgTestClass\"><Arg type=\"Set\">Some String</Arg></New></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThrows(IllegalArgumentException.class, ()->{ assertThrows(IllegalArgumentException.class, ()->{
@ -345,7 +362,7 @@ public class XmlConfigurationTest
@Test @Test
public void testListSetterWithStringArray() throws Exception public void testListSetterWithStringArray() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
+ STRING_ARRAY_XML + "</Set></Configure>"); + STRING_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue())); assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
@ -356,7 +373,7 @@ public class XmlConfigurationTest
@Test @Test
public void testListSetterWithPrimitiveArray() throws Exception public void testListSetterWithPrimitiveArray() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"List\">"
+ INT_ARRAY_XML + "</Set></Configure>"); + INT_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue())); assertThat("tc.getList() returns null as it's not configured yet",tc.getList(),is(nullValue()));
@ -367,7 +384,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNotSupportedLinkedListSetter() throws Exception public void testNotSupportedLinkedListSetter() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"LinkedList\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"LinkedList\">"
+ INT_ARRAY_XML + "</Set></Configure>"); + INT_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
@ -379,7 +396,7 @@ public class XmlConfigurationTest
@Test @Test
public void testArrayListSetter() throws Exception public void testArrayListSetter() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"ArrayList\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"ArrayList\">"
+ INT_ARRAY_XML + "</Set></Configure>"); + INT_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue()));
@ -390,7 +407,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetSetter() throws Exception public void testSetSetter() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
+ STRING_ARRAY_XML + "</Set></Configure>"); + STRING_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
@ -401,7 +418,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetSetterWithPrimitiveArray() throws Exception public void testSetSetterWithPrimitiveArray() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">" XmlConfiguration xmlConfiguration = asXmlConfiguration("<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\"><Set name=\"Set\">"
+ INT_ARRAY_XML + "</Set></Configure>"); + INT_ARRAY_XML + "</Set></Configure>");
TestConfiguration tc = new TestConfiguration(); TestConfiguration tc = new TestConfiguration();
assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue()));
@ -412,7 +429,7 @@ public class XmlConfigurationTest
@Test @Test
public void testMap() throws Exception public void testMap() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"map\">" + " <Set name=\"map\">" +
" <Map>" + " <Map>" +
@ -436,7 +453,7 @@ public class XmlConfigurationTest
@Test @Test
public void testConstructorNamedInjection() throws Exception public void testConstructorNamedInjection() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " + " <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -453,7 +470,7 @@ public class XmlConfigurationTest
@Test @Test
public void testConstructorNamedInjectionOrdered() throws Exception public void testConstructorNamedInjectionOrdered() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"second\">arg2</Arg> " + " <Arg name=\"second\">arg2</Arg> " +
@ -470,7 +487,7 @@ public class XmlConfigurationTest
@Test @Test
public void testConstructorNamedInjectionUnOrdered() throws Exception public void testConstructorNamedInjectionUnOrdered() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"third\">arg3</Arg> " + " <Arg name=\"third\">arg3</Arg> " +
@ -487,7 +504,7 @@ public class XmlConfigurationTest
@Test @Test
public void testConstructorNamedInjectionOrderedMixed() throws Exception public void testConstructorNamedInjectionOrderedMixed() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -504,7 +521,7 @@ public class XmlConfigurationTest
@Test @Test
public void testConstructorNamedInjectionUnorderedMixed() throws Exception public void testConstructorNamedInjectionUnorderedMixed() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"third\">arg3</Arg> " + " <Arg name=\"third\">arg3</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -521,7 +538,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNestedConstructorNamedInjection() throws Exception public void testNestedConstructorNamedInjection() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " + " <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -549,7 +566,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNestedConstructorNamedInjectionOrdered() throws Exception public void testNestedConstructorNamedInjectionOrdered() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"second\">arg2</Arg> " + " <Arg name=\"second\">arg2</Arg> " +
@ -576,7 +593,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNestedConstructorNamedInjectionUnOrdered() throws Exception public void testNestedConstructorNamedInjectionUnOrdered() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg name=\"third\">arg3</Arg> " + " <Arg name=\"third\">arg3</Arg> " +
@ -603,7 +620,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception public void testNestedConstructorNamedInjectionOrderedMixed() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"first\">arg1</Arg> " + " <Arg name=\"first\">arg1</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -630,7 +647,7 @@ public class XmlConfigurationTest
@Test @Test
public void testArgumentsGetIgnoredMissingDTD() throws Exception public void testArgumentsGetIgnoredMissingDTD() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg>arg1</Arg> " + " <Arg>arg1</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -642,8 +659,7 @@ public class XmlConfigurationTest
" <Arg>arg3</Arg>\n" + " <Arg>arg3</Arg>\n" +
" </New>" + " </New>" +
" </Set>" + " </Set>" +
"</Configure>").getBytes(StandardCharsets.ISO_8859_1))); "</Configure>");
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure(); AnnotatedTestConfiguration atc = (AnnotatedTestConfiguration)xmlConfiguration.configure();
@ -658,7 +674,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetGetIgnoredMissingDTD() throws Exception public void testSetGetIgnoredMissingDTD() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration(new ByteArrayInputStream(("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">arg1</Set> " + " <Set name=\"first\">arg1</Set> " +
" <Set name=\"second\">arg2</Set> " + " <Set name=\"second\">arg2</Set> " +
@ -670,8 +686,7 @@ public class XmlConfigurationTest
" <Set name=\"third\">arg3</Set> " + " <Set name=\"third\">arg3</Set> " +
" </New>" + " </New>" +
" </Set>" + " </Set>" +
"</Configure>").getBytes(StandardCharsets.UTF_8))); "</Configure>");
// XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure(); DefaultTestConfiguration atc = (DefaultTestConfiguration)xmlConfiguration.configure();
@ -686,7 +701,7 @@ public class XmlConfigurationTest
@Test @Test
public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception public void testNestedConstructorNamedInjectionUnorderedMixed() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.AnnotatedTestConfiguration\">" +
" <Arg name=\"third\">arg3</Arg> " + " <Arg name=\"third\">arg3</Arg> " +
" <Arg>arg2</Arg> " + " <Arg>arg2</Arg> " +
@ -751,7 +766,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetBooleanTrue() throws Exception public void testSetBooleanTrue() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">true</Set>" + " <Set name=\"boolean\">true</Set>" +
"</Configure>"); "</Configure>");
@ -763,7 +778,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetBooleanFalse() throws Exception public void testSetBooleanFalse() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">false</Set>" + " <Set name=\"boolean\">false</Set>" +
"</Configure>"); "</Configure>");
@ -776,7 +791,7 @@ public class XmlConfigurationTest
@Disabled @Disabled
public void testSetBadBoolean() throws Exception public void testSetBadBoolean() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"boolean\">tru</Set>" + " <Set name=\"boolean\">tru</Set>" +
"</Configure>"); "</Configure>");
@ -788,7 +803,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetBadInteger() throws Exception public void testSetBadInteger() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">bad</Set>" + " <Set name=\"integer\">bad</Set>" +
"</Configure>"); "</Configure>");
@ -801,7 +816,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetBadExtraInteger() throws Exception public void testSetBadExtraInteger() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">100 bas</Set>" + " <Set name=\"integer\">100 bas</Set>" +
"</Configure>"); "</Configure>");
@ -814,7 +829,7 @@ public class XmlConfigurationTest
@Test @Test
public void testSetBadFloatInteger() throws Exception public void testSetBadFloatInteger() throws Exception
{ {
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" + "<Configure class=\"org.eclipse.jetty.xml.XmlConfigurationTest$NativeHolder\">" +
" <Set name=\"integer\">1.5</Set>" + " <Set name=\"integer\">1.5</Set>" +
"</Configure>"); "</Configure>");
@ -829,7 +844,7 @@ public class XmlConfigurationTest
{ {
// No properties // No properties
String defolt = "baz"; String defolt = "baz";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"wibble\" deprecated=\"foo,bar\" default=\"" + defolt + "\"/></Set> " + " <Set name=\"first\"><Property name=\"wibble\" deprecated=\"foo,bar\" default=\"" + defolt + "\"/></Set> " +
"</Configure>"); "</Configure>");
@ -842,7 +857,7 @@ public class XmlConfigurationTest
{ {
String name = "foo"; String name = "foo";
String value = "foo"; String value = "foo";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"" + name + "\" deprecated=\"other,bar\" default=\"baz\"/></Set> " + " <Set name=\"first\"><Property name=\"" + name + "\" deprecated=\"other,bar\" default=\"baz\"/></Set> " +
"</Configure>"); "</Configure>");
@ -856,7 +871,7 @@ public class XmlConfigurationTest
{ {
String name = "bar"; String name = "bar";
String value = "bar"; String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"" + name + "\" default=\"baz\"/></Set> " + " <Set name=\"first\"><Property name=\"foo\" deprecated=\"" + name + "\" default=\"baz\"/></Set> " +
"</Configure>"); "</Configure>");
@ -870,7 +885,7 @@ public class XmlConfigurationTest
{ {
String name = "bar"; String name = "bar";
String value = "bar"; String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\"><Property name=\"foo\" deprecated=\"other," + name + "\" default=\"baz\"/></Set> " + " <Set name=\"first\"><Property name=\"foo\" deprecated=\"other," + name + "\" default=\"baz\"/></Set> " +
"</Configure>"); "</Configure>");
@ -884,7 +899,7 @@ public class XmlConfigurationTest
{ {
String name = "bar"; String name = "bar";
String value = "bar"; String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" + " <Set name=\"first\">" +
" <Property> " + " <Property> " +
@ -907,7 +922,7 @@ public class XmlConfigurationTest
String value = "bar"; String value = "bar";
String defaultValue = "_<Property name=\"bar\"/>_<Property name=\"bar\"/>_"; String defaultValue = "_<Property name=\"bar\"/>_<Property name=\"bar\"/>_";
String expectedValue = "_" + value + "_" + value + "_"; String expectedValue = "_" + value + "_" + value + "_";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" + " <Set name=\"first\">" +
" <Property>" + " <Property>" +
@ -925,7 +940,7 @@ public class XmlConfigurationTest
public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception public void testPropertyNotFoundWithPropertyInDefaultValueNotFoundWithDefault() throws Exception
{ {
String value = "bar"; String value = "bar";
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.DefaultTestConfiguration\">" +
" <Set name=\"first\">" + " <Set name=\"first\">" +
" <Property name=\"not_found\">" + " <Property name=\"not_found\">" +
@ -948,7 +963,7 @@ public class XmlConfigurationTest
for(String propName: propNames) for(String propName: propNames)
{ {
XmlConfiguration configuration = XmlConfiguration configuration =
new XmlConfiguration("" + asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" + " <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" + " <Property name=\"" + propName + "\"/>" +
@ -976,7 +991,7 @@ public class XmlConfigurationTest
for(String propName: propNames) for(String propName: propNames)
{ {
XmlConfiguration configuration = XmlConfiguration configuration =
new XmlConfiguration("" + asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" + " <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" + " <Property name=\"" + propName + "\"/>" +
@ -998,7 +1013,7 @@ public class XmlConfigurationTest
{ {
Path war = MavenTestingUtils.getTargetPath("no.war"); Path war = MavenTestingUtils.getTargetPath("no.war");
XmlConfiguration configuration = XmlConfiguration configuration =
new XmlConfiguration("" + asXmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" + "<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" + " <Set name=\"TestString\">" +
" <Property name=\"" + "jetty.webapps.uri" + "\"/>" + " <Property name=\"" + "jetty.webapps.uri" + "\"/>" +
@ -1012,12 +1027,12 @@ public class XmlConfigurationTest
assertThat("jetty.webapps.uri", tc.getTestString(), is(XmlConfiguration.normalizeURI(war.getParent().toUri().toString()))); assertThat("jetty.webapps.uri", tc.getTestString(), is(XmlConfiguration.normalizeURI(war.getParent().toUri().toString())));
} }
@Test @Test
public void testDeprecated() throws Exception public void testDeprecated() throws Exception
{ {
Class<?> testClass = AnnotatedTestConfiguration.class; Class<?> testClass = AnnotatedTestConfiguration.class;
XmlConfiguration xmlConfiguration = new XmlConfiguration("" + XmlConfiguration xmlConfiguration = asXmlConfiguration("" +
"<Configure class=\"" + testClass.getName() + "\">" + "<Configure class=\"" + testClass.getName() + "\">" +
" <Set name=\"deprecated\">foo</Set>" + " <Set name=\"deprecated\">foo</Set>" +
" <Set name=\"obsolete\">" + " <Set name=\"obsolete\">" +

View File

@ -69,8 +69,6 @@ VER_CURRENT=`sed -e "s/xmlns/ignore/" pom.xml | xmllint --xpath "/project/versio
echo "Current pom.xml Version: ${VER_CURRENT}" echo "Current pom.xml Version: ${VER_CURRENT}"
read -e -p "Release Version ? " VER_RELEASE read -e -p "Release Version ? " VER_RELEASE
read -e -p "Next Dev Version ? " VER_NEXT 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" TAG_NAME="jetty-$VER_RELEASE"
# Ensure tag doesn't exist (yet) # Ensure tag doesn't exist (yet)
@ -89,9 +87,12 @@ if [ ! -d "$ALT_DEPLOY_DIR" ] ; then
fi fi
# DEPLOY_OPTS="-Dmaven.test.failure.ignore=true" # 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/" # 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 "-----------------------------------------------" echo "-----------------------------------------------"
echo " Release Plan Review" echo " Release Plan Review"
@ -103,6 +104,7 @@ echo "Current Version : $VER_CURRENT"
echo "Release Version : $VER_RELEASE" echo "Release Version : $VER_RELEASE"
echo "Next Dev Version : $VER_NEXT" echo "Next Dev Version : $VER_NEXT"
echo "Tag name : $TAG_NAME" echo "Tag name : $TAG_NAME"
echo "MAVEN_OPTS : $MAVEN_OPTS"
echo "Maven Deploy Opts: $DEPLOY_OPTS" echo "Maven Deploy Opts: $DEPLOY_OPTS"
reportMavenTestFailures() { reportMavenTestFailures() {
@ -130,13 +132,20 @@ echo ""
if proceedyn "Are you sure you want to release using above? (y/N)" n; then if proceedyn "Are you sure you want to release using above? (y/N)" n; then
echo "" echo ""
if proceedyn "Update VERSION.txt for $VER_RELEASE? (Y/n)" y; then 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 mvn -N -Pupdate-version generate-resources
cp VERSION.txt VERSION.txt.backup cp VERSION.txt VERSION.txt.backup
cat VERSION.txt.backup | sed -e "s/$VER_CURRENT/$VER_RELEASE/" > VERSION.txt cat VERSION.txt.backup | sed -e "s/$VER_CURRENT/$VER_RELEASE/" > VERSION.txt
rm VERSION.txt.backup 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 "VERIFY the following files (in a different console window) before continuing."
echo " VERSION.txt - top section" 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 fi
# This is equivalent to 'mvn release:prepare' # 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 fi
if proceedyn "Create Tag $TAG_NAME? (Y/n)" y; then if proceedyn "Create Tag $TAG_NAME? (Y/n)" y; then
echo "TODO: Sign tags with GIT_USER_EMAIL=$GIT_USER_EMAIL" echo "TODO: Sign tags with GIT_USER_EMAIL=$GIT_USER_EMAIL"
echo "Using target/vers-tag.txt as tag text" echo "Using target/version-tag.txt as tag text"
git tag --file=target/vers-tag.txt $TAG_NAME git tag --file=target/version-tag.txt $TAG_NAME
fi fi
# This is equivalent to 'mvn release:perform' # 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 echo "" >> VERSION.txt
cat VERSION.txt.backup >> VERSION.txt cat VERSION.txt.backup >> VERSION.txt
echo "Update project.versions for $VER_NEXT" 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" \ -DoldVersion="$VER_RELEASE" \
-DnewVersion="$VER_NEXT" -DnewVersion="$VER_NEXT" \
-DprocessAllModules=true
echo "Commit $VER_NEXT" echo "Commit $VER_NEXT"
if proceedyn "Commit updates in working directory for $VER_NEXT? (Y/n)" y; then if proceedyn "Commit updates in working directory for $VER_NEXT? (Y/n)" y; then
git commit -a -m "Updating to version $VER_NEXT" git commit -a -m "Updating to version $VER_NEXT"

View File

@ -18,17 +18,12 @@
package org.eclipse.jetty.test.support; 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.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -41,15 +36,21 @@ import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; 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 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. * Allows for setting up a Jetty server for testing based on XML configuration files.
*/ */
public class XmlBasedJettyServer public class XmlBasedJettyServer
{ {
private static final Logger LOG = Log.getLogger(XmlBasedJettyServer.class); private static final Logger LOG = Log.getLogger(XmlBasedJettyServer.class);
private List<URL> _xmlConfigurations; private List<Resource> _xmlConfigurations;
private final Map<String,String> _properties = new HashMap<>(); private final Map<String,String> _properties = new HashMap<>();
private Server _server; private Server _server;
private int _serverPort; private int _serverPort;
@ -94,14 +95,14 @@ public class XmlBasedJettyServer
_properties.put(String.valueOf(key),String.valueOf(properties.get(key))); _properties.put(String.valueOf(key),String.valueOf(properties.get(key)));
} }
public void addXmlConfiguration(URL xmlConfig) public void addXmlConfiguration(Resource xmlConfig)
{ {
_xmlConfigurations.add(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 public void addXmlConfiguration(String testConfigName) throws MalformedURLException
@ -122,9 +123,9 @@ public class XmlBasedJettyServer
// Configure everything // Configure everything
for (int i = 0; i < this._xmlConfigurations.size(); i++) for (int i = 0; i < this._xmlConfigurations.size(); i++)
{ {
URL configURL = this._xmlConfigurations.get(i); Resource configResource = this._xmlConfigurations.get(i);
LOG.debug("configuring: "+configURL); LOG.debug("configuring: "+configResource);
XmlConfiguration configuration = new XmlConfiguration(configURL); XmlConfiguration configuration = new XmlConfiguration(configResource);
if (last != null) if (last != null)
{ {
configuration.getIdMap().putAll(last.getIdMap()); configuration.getIdMap().putAll(last.getIdMap());

View File

@ -74,7 +74,7 @@ public class QuickStartTest
if (contextXml != null) if (contextXml != null)
{ {
// System.err.println("Applying "+contextXml); // System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml);
xmlConfiguration.configure(webapp); xmlConfiguration.configure(webapp);
} }
@ -123,7 +123,7 @@ public class QuickStartTest
if (contextXml != null) if (contextXml != null)
{ {
// System.err.println("Applying "+contextXml); // System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI()); XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml);
xmlConfiguration.configure(webapp); xmlConfiguration.configure(webapp);
} }
@ -169,7 +169,7 @@ public class QuickStartTest
if (contextXml != null) if (contextXml != null)
{ {
// System.err.println("Applying "+contextXml); // System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI().toURL()); XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml);
xmlConfiguration.configure(webapp); xmlConfiguration.configure(webapp);
} }

View File

@ -48,8 +48,7 @@ public class Quickstart
//apply context xml file //apply context xml file
if (contextXml != null) if (contextXml != null)
{ {
// System.err.println("Applying "+contextXml); XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI());
xmlConfiguration.configure(webapp); xmlConfiguration.configure(webapp);
} }