Fixed #1715 standardise XML properties and IDs

This commit is contained in:
Greg Wilkins 2017-08-08 11:55:47 +10:00 committed by Joakim Erdfelt
parent c917d9e72b
commit 76981a0a15
3 changed files with 57 additions and 26 deletions

View File

@ -598,27 +598,9 @@ public class DeploymentManager extends ContainerLifeCycle
return getApps(_lifecycle.getNodeByName(nodeName));
}
public void scope(XmlConfiguration xmlc, Resource webapp)
throws IOException
{
xmlc.getIdMap().put("Server", getServer());
Resource home = Resource.newResource(System.getProperty("jetty.home","."));
xmlc.getProperties().put("jetty.home",home.toString());
xmlc.getProperties().put("jetty.home.uri",normalizeURI(home.getURI().toString()));
Resource base = Resource.newResource(System.getProperty("jetty.base",home.toString()));
xmlc.getProperties().put("jetty.base",base.toString());
xmlc.getProperties().put("jetty.base.uri",normalizeURI(base.getURI().toString()));
xmlc.getProperties().put("jetty.webapp",webapp.toString());
xmlc.getProperties().put("jetty.webapps",webapp.getFile().toPath().getParent().toString());
}
private String normalizeURI(String uri)
{
if (uri.endsWith("/"))
return uri.substring(0,uri.length()-1);
return uri;
xmlc.setJettyStandardIdsAndProperties(getServer(),webapp);
}
}

View File

@ -86,11 +86,10 @@ 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());
setupXmlConfiguration(jetty_config, web_inf);
final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration?(XmlConfiguration)xml_attr:new XmlConfiguration(jetty.getURI().toURL());
setupXmlConfiguration(context, jetty_config, web_inf);
try
{
WebAppClassLoader.runWithServerClassAccess(()->{jetty_config.configure(context);return null;});
@ -110,11 +109,12 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
* @param jetty_config The configuration object.
* @param web_inf the WEB-INF location
*/
private void setupXmlConfiguration(XmlConfiguration jetty_config, Resource web_inf) throws IOException
private void setupXmlConfiguration(WebAppContext context, XmlConfiguration jetty_config, Resource web_inf) throws IOException
{
jetty_config.setJettyStandardIdsAndProperties(context.getServer(),null);
Map<String,String> props = jetty_config.getProperties();
props.put(PROPERTY_THIS_WEB_INF_URL, web_inf.getURI().toString());
props.put(PROPERTY_WEB_INF_URI, web_inf.getURI().toString());
props.put(PROPERTY_WEB_INF_URI, XmlConfiguration.normalizeURI(web_inf.getURI().toString()));
props.put(PROPERTY_WEB_INF, web_inf.toString());
}
}

View File

@ -115,6 +115,55 @@ public class XmlConfiguration
return parser;
}
/**
* Set the standard IDs and properties expected in a jetty XML file:
* <ul>
* <li>RefId Server</li>
* <li>Property jetty.home</li>
* <li>Property jetty.home.uri</li>
* <li>Property jetty.base</li>
* <li>Property jetty.base.uri</li>
* <li>Property jetty.webapps</li>
* <li>Property jetty.webapps.uri</li>
* </ul>
* @param server The Server object to set
* @param webapp The webapps Resource
*/
public void setJettyStandardIdsAndProperties(Object server, Resource webapp)
{
try
{
if (server!=null)
getIdMap().put("Server", server);
Resource home = Resource.newResource(System.getProperty("jetty.home","."));
getProperties().put("jetty.home",home.toString());
getProperties().put("jetty.home.uri",normalizeURI(home.getURI().toString()));
Resource base = Resource.newResource(System.getProperty("jetty.base",home.toString()));
getProperties().put("jetty.base",base.toString());
getProperties().put("jetty.base.uri",normalizeURI(base.getURI().toString()));
if (webapp!=null)
{
getProperties().put("jetty.webapp",webapp.toString());
getProperties().put("jetty.webapps",webapp.getFile().toPath().getParent().toString());
getProperties().put("jetty.webapps.uri",normalizeURI(webapp.getURI().toString()));
}
}
catch(Exception e)
{
LOG.warn(e);
}
}
public static String normalizeURI(String uri)
{
if (uri.endsWith("/"))
return uri.substring(0,uri.length()-1);
return uri;
}
private final Map<String, Object> _idMap = new HashMap<>();
private final Map<String, String> _propertyMap = new HashMap<>();
private final URL _url;