use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class ContextConfig method processAnnotations.
protected void processAnnotations(Set<WebXml> fragments, boolean handlesTypesOnly, Map<String, JavaClassCacheEntry> javaClassCache) {
for (WebXml fragment : fragments) {
// Only need to scan for @HandlesTypes matches if any of the
// following are true:
// - it has already been determined only @HandlesTypes is required
// (e.g. main web.xml has metadata-complete="true"
// - this fragment is for a container JAR (Servlet 3.1 section 8.1)
// - this fragment has metadata-complete="true"
boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() || fragment.isMetadataComplete();
WebXml annotations = new WebXml();
// no impact on distributable
annotations.setDistributable(true);
URL url = fragment.getURL();
processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
Set<WebXml> set = new HashSet<>();
set.add(annotations);
// Merge annotations into fragment - fragment takes priority
fragment.merge(set);
}
}
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);
}
return webXmlDefaultFragment;
}
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestSchemaValidation method testWebapp_3_1.
@Test
public void testWebapp_3_1() throws Exception {
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
digester.setErrorHandler(handler);
digester.push(new WebXml());
WebXml desc = (WebXml) digester.parse(new File("test/webapp-3.1/WEB-INF/web.xml"));
Assert.assertEquals("3.1", desc.getVersion());
Assert.assertEquals(0, handler.getErrors().size());
Assert.assertEquals(0, handler.getWarnings().size());
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestSchemaValidation method testWebapp_4_0.
@Test
public void testWebapp_4_0() throws Exception {
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
digester.setErrorHandler(handler);
digester.push(new WebXml());
WebXml desc = (WebXml) digester.parse(new File("test/webapp-4.0/WEB-INF/web.xml"));
Assert.assertEquals("4.0", desc.getVersion());
Assert.assertEquals(0, handler.getErrors().size());
Assert.assertEquals(0, handler.getWarnings().size());
}
use of org.apache.tomcat.util.descriptor.web.WebXml in project tomcat by apache.
the class TestSchemaValidation method testWebapp.
@Test
public void testWebapp() throws Exception {
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(false), true);
digester.setErrorHandler(handler);
digester.push(new WebXml());
WebXml desc = (WebXml) digester.parse(new File("test/webapp/WEB-INF/web.xml"));
Assert.assertEquals("4.0", desc.getVersion());
Assert.assertEquals(0, handler.getErrors().size());
Assert.assertEquals(0, handler.getWarnings().size());
}
Aggregations