use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class ContextConfig method getTomcatWebXmlFragment.
private WebXml getTomcatWebXmlFragment(WebXmlParser webXmlParser) {
WebXml webXmlTomcatFragment = createWebXml();
webXmlTomcatFragment.setOverridable(true);
// Set to distributable else every app will be prevented from being
// distributable when the Tomcat fragment is merged with the main
// web.xml
webXmlTomcatFragment.setDistributable(true);
// When merging, the default welcome files are only used if the app has
// not defined any welcomes files.
webXmlTomcatFragment.setAlwaysAddWelcomeFiles(false);
WebResource resource = context.getResources().getResource(Constants.TomcatWebXml);
if (resource.isFile()) {
try {
InputSource source = new InputSource(resource.getURL().toURI().toString());
source.setByteStream(resource.getInputStream());
if (!webXmlParser.parseWebXml(source, webXmlTomcatFragment, false)) {
ok = false;
}
} catch (URISyntaxException e) {
log.error(sm.getString("contextConfig.tomcatWebXmlError"), e);
}
}
return webXmlTomcatFragment;
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class ContextConfig method getDefaultWebXmlFragment.
private WebXml getDefaultWebXmlFragment(WebXmlParser webXmlParser) {
// Host should never be null
Host host = (Host) context.getParent();
DefaultWebXmlCacheEntry entry = hostWebXmlCache.get(host);
InputSource globalWebXml = getGlobalWebXmlSource();
InputSource hostWebXml = getHostWebXmlSource();
long globalTimeStamp = 0;
long hostTimeStamp = 0;
if (globalWebXml != null) {
URLConnection uc = null;
try {
URL url = new URL(globalWebXml.getSystemId());
uc = url.openConnection();
globalTimeStamp = uc.getLastModified();
} catch (IOException e) {
globalTimeStamp = -1;
} finally {
if (uc != null) {
try {
uc.getInputStream().close();
} catch (IOException e) {
ExceptionUtils.handleThrowable(e);
globalTimeStamp = -1;
}
}
}
}
if (hostWebXml != null) {
URLConnection uc = null;
try {
URL url = new URL(hostWebXml.getSystemId());
uc = url.openConnection();
hostTimeStamp = uc.getLastModified();
} catch (IOException e) {
hostTimeStamp = -1;
} finally {
if (uc != null) {
try {
uc.getInputStream().close();
} catch (IOException e) {
ExceptionUtils.handleThrowable(e);
hostTimeStamp = -1;
}
}
}
}
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp && entry.getHostTimeStamp() == hostTimeStamp) {
InputSourceUtil.close(globalWebXml);
InputSourceUtil.close(hostWebXml);
return entry.getWebXml();
}
// already be held on the host by another thread
synchronized (host.getPipeline()) {
entry = hostWebXmlCache.get(host);
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp && entry.getHostTimeStamp() == hostTimeStamp) {
return entry.getWebXml();
}
WebXml webXmlDefaultFragment = createWebXml();
webXmlDefaultFragment.setOverridable(true);
// Set to distributable else every app will be prevented from being
// distributable when the default fragment is merged with the main
// web.xml
webXmlDefaultFragment.setDistributable(true);
// When merging, the default welcome files are only used if the app has
// not defined any welcomes files.
webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false);
// Parse global web.xml if present
if (globalWebXml == null) {
// This is unusual enough to log
log.info(sm.getString("contextConfig.defaultMissing"));
} else {
if (!webXmlParser.parseWebXml(globalWebXml, webXmlDefaultFragment, false)) {
ok = false;
}
}
// Parse host level web.xml if present
// Additive apart from welcome pages
webXmlDefaultFragment.setReplaceWelcomeFiles(true);
if (!webXmlParser.parseWebXml(hostWebXml, webXmlDefaultFragment, false)) {
ok = false;
}
// Don't update the cache if an error occurs
if (globalTimeStamp != -1 && hostTimeStamp != -1) {
entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment, globalTimeStamp, hostTimeStamp);
hostWebXmlCache.put(host, entry);
// Add a Lifecycle listener to the Host that will remove it from
// the hostWebXmlCache once the Host is destroyed
host.addLifecycleListener(new HostWebXmlCacheCleaner());
}
return webXmlDefaultFragment;
}
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class JspCServletContext method scanForResourceJARs.
private List<URL> scanForResourceJARs(Set<WebXml> orderedFragments, Collection<WebXml> fragments) throws JasperException {
List<URL> resourceJars = new ArrayList<>();
// Build list of potential resource JARs. Use same ordering as ContextConfig
Set<WebXml> resourceFragments = new LinkedHashSet<>(orderedFragments);
for (WebXml fragment : fragments) {
if (!resourceFragments.contains(fragment)) {
resourceFragments.add(fragment);
}
}
for (WebXml resourceFragment : resourceFragments) {
try (Jar jar = JarFactory.newInstance(resourceFragment.getURL())) {
if (jar.exists("META-INF/resources/")) {
// This is a resource JAR
resourceJars.add(resourceFragment.getURL());
}
} catch (IOException ioe) {
throw new JasperException(ioe);
}
}
return resourceJars;
}
Aggregations