use of org.apache.catalina.deploy.WebXml in project tomcat70 by apache.
the class ContextConfig method getDefaultWebXmlFragment.
private WebXml getDefaultWebXmlFragment() {
// 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 {
parseWebXml(globalWebXml, webXmlDefaultFragment, false);
}
// Parse host level web.xml if present
// Additive apart from welcome pages
webXmlDefaultFragment.setReplaceWelcomeFiles(true);
parseWebXml(hostWebXml, webXmlDefaultFragment, 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.catalina.deploy.WebXml in project tomcat70 by apache.
the class SetOverrideRule method begin.
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
WebXml webXml = (WebXml) digester.peek(digester.getCount() - 1);
// If we have a public ID, this is not a 2.4 or later webapp
boolean havePublicId = (webXml.getPublicId() != null);
// havePublicId and isServlet24OrLater should be mutually exclusive
if (havePublicId == isServlet24OrLater) {
throw new IllegalArgumentException("taglib definition not consistent with specification version");
}
}
use of org.apache.catalina.deploy.WebXml in project tomcat70 by apache.
the class SetOverrideRule method end.
@Override
public void end(String namespace, String name) throws Exception {
Object[] params = (Object[]) digester.peekParams();
if (params != null && params.length == 2) {
WebXml webXml = (WebXml) digester.peek();
if (postConstruct) {
if (webXml.getPostConstructMethods().containsKey(params[0])) {
throw new IllegalArgumentException(WebRuleSet.sm.getString("webRuleSet.postconstruct.duplicate", params[0]));
}
} else {
if (webXml.getPreDestroyMethods().containsKey(params[0])) {
throw new IllegalArgumentException(WebRuleSet.sm.getString("webRuleSet.predestroy.duplicate", params[0]));
}
}
}
super.end(namespace, name);
}
use of org.apache.catalina.deploy.WebXml in project tomcat70 by apache.
the class TestContextConfigAnnotation method testOverwriteAnnotation.
@Test
public void testOverwriteAnnotation() throws Exception {
WebXml webxml = new WebXml();
ServletDef servletDef = new ServletDef();
servletDef.setServletName("param");
servletDef.setServletClass("org.apache.catalina.startup.ParamServlet");
servletDef.addInitParameter("foo", "tomcat");
servletDef.setDescription("Description");
servletDef.setDisplayName("DisplayName");
servletDef.setLargeIcon("LargeIcon");
servletDef.setSmallIcon("SmallIcon");
servletDef.setAsyncSupported("true");
servletDef.setLoadOnStartup("1");
webxml.addServlet(servletDef);
webxml.addServletMapping("/param", "param");
ContextConfig config = new ContextConfig();
File pFile = paramClassResource("org/apache/catalina/startup/ParamServlet");
Assert.assertTrue(pFile.exists());
config.processAnnotationsFile(pFile, webxml, false);
Assert.assertEquals(servletDef, webxml.getServlets().get("param"));
Assert.assertEquals("tomcat", servletDef.getParameterMap().get("foo"));
Assert.assertEquals("param", webxml.getServletMappings().get("/param"));
// annotation mapping not added s. Servlet Spec 3.0 (Nov 2009)
// 8.2.3.3.iv page 81
Assert.assertNull(webxml.getServletMappings().get("/annotation/overwrite"));
Assert.assertEquals("Description", servletDef.getDescription());
Assert.assertEquals("DisplayName", servletDef.getDisplayName());
Assert.assertEquals("LargeIcon", servletDef.getLargeIcon());
Assert.assertEquals("SmallIcon", servletDef.getSmallIcon());
Assert.assertEquals(Boolean.TRUE, servletDef.getAsyncSupported());
Assert.assertEquals(Integer.valueOf(1), servletDef.getLoadOnStartup());
Assert.assertNull(servletDef.getEnabled());
Assert.assertNull(servletDef.getJspFile());
}
use of org.apache.catalina.deploy.WebXml in project tomcat70 by apache.
the class TestStandardContextResources method testResourcesAbsoluteOrdering.
@Test
public void testResourcesAbsoluteOrdering() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0-fragments");
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
LifecycleListener[] listener = ctx.findLifecycleListeners();
Assert.assertEquals(3, listener.length);
Assert.assertTrue(listener[1] instanceof ContextConfig);
ContextConfig config = new ContextConfig() {
@Override
protected WebXml createWebXml() {
WebXml wxml = new WebXml();
wxml.addAbsoluteOrdering("resources");
wxml.addAbsoluteOrdering("resources2");
return wxml;
}
};
// prevent it from looking ( if it finds one - it'll have dup error )
config.setDefaultWebXml(Constants.NoDefaultWebXml);
listener[1] = config;
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMapping("/getresource", "getresource");
tomcat.start();
assertPageContains("/test/getresource?path=/resourceF.jsp", "<p>resourceF.jsp in resources2.jar</p>");
assertPageContains("/test/getresource?path=/resourceB.jsp", "<p>resourceB.jsp in resources.jar</p>");
// Check ordering, for BZ 54391
Assert.assertEquals(Arrays.asList("resources.jar", "resources2.jar"), ctx.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
ctx.stop();
LifecycleListener[] listener1 = ctx.findLifecycleListeners();
// change ordering and reload
ContextConfig config1 = new ContextConfig() {
@Override
protected WebXml createWebXml() {
WebXml wxml = new WebXml();
wxml.addAbsoluteOrdering("resources2");
wxml.addAbsoluteOrdering("resources");
return wxml;
}
};
// prevent it from looking ( if it finds one - it'll have dup error )
config1.setDefaultWebXml(Constants.NoDefaultWebXml);
listener1[1] = config1;
// Need to init since context won't call init
config1.lifecycleEvent(new LifecycleEvent(ctx, Lifecycle.AFTER_INIT_EVENT, null));
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMapping("/getresource", "getresource");
ctx.start();
assertPageContains("/test/getresource?path=/resourceF.jsp", "<p>resourceF.jsp in resources2.jar</p>");
assertPageContains("/test/getresource?path=/resourceB.jsp", "<p>resourceB.jsp in resources2.jar</p>");
// Check ordering, for BZ 54391
Assert.assertEquals(Arrays.asList("resources2.jar", "resources.jar"), ctx.getServletContext().getAttribute(ServletContext.ORDERED_LIBS));
}
Aggregations