use of jakarta.servlet.ServletContext in project tomcat by apache.
the class TesterTldListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
servletContext = sc;
// Try and use one of the Servlet 3.0 methods that should be blocked
try {
sc.getServletRegistrations();
log.append("FAIL-01");
} catch (UnsupportedOperationException uoe) {
log.append("PASS-01");
} catch (Exception e) {
log.append("FAIL-02");
}
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class TestCorsFilter method testInitDefaultFilterConfig.
@Test
public void testInitDefaultFilterConfig() throws IOException, ServletException {
TesterHttpServletRequest request = new TesterHttpServletRequest();
request.setHeader(CorsFilter.REQUEST_HEADER_ORIGIN, TesterFilterConfigs.HTTPS_WWW_APACHE_ORG);
request.setMethod("GET");
TesterHttpServletResponse response = new TesterHttpServletResponse();
CorsFilter corsFilter = new CorsFilter();
corsFilter.init(new FilterConfig() {
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public String getFilterName() {
return null;
}
});
corsFilter.doFilter(request, response, filterChain);
Assert.assertNull(response.getHeader(CorsFilter.RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN));
Assert.assertTrue(((Boolean) request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_IS_CORS_REQUEST)).booleanValue());
Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_ORIGIN).equals(TesterFilterConfigs.HTTPS_WWW_APACHE_ORG));
Assert.assertTrue(request.getAttribute(CorsFilter.HTTP_REQUEST_ATTRIBUTE_REQUEST_TYPE).equals(CorsFilter.CORSRequestType.SIMPLE.name().toLowerCase(Locale.ENGLISH)));
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class TestApplicationContext method testGetJspConfigDescriptor.
@Test
public void testGetJspConfigDescriptor() throws Exception {
Tomcat tomcat = getTomcatInstanceTestWebapp(false, false);
StandardContext standardContext = (StandardContext) tomcat.getHost().findChildren()[0];
ServletContext servletContext = standardContext.getServletContext();
Assert.assertNull(servletContext.getJspConfigDescriptor());
tomcat.start();
Assert.assertNotNull(servletContext.getJspConfigDescriptor());
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class TestTagPluginManager method testBug54240.
@Test
public void testBug54240() throws Exception {
Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
ServletContext context = ((Context) tomcat.getHost().findChildren()[0]).getServletContext();
TagPluginManager manager = new TagPluginManager(context);
Node.Nodes nodes = new Node.Nodes();
Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag", "http://tomcat.apache.org/jasper", null, null, null, null, null, new TagFileInfo("ATag", "http://tomcat.apache.org/jasper", tagInfo));
c.setTagHandlerClass(TesterTag.class);
nodes.add(c);
manager.apply(nodes, null, null);
Node n = nodes.getNode(0);
Assert.assertNotNull(n);
Node.CustomTag t = (Node.CustomTag) n;
Assert.assertNotNull(t.getAtSTag());
Node.Nodes sTag = c.getAtSTag();
Node scriptlet = sTag.getNode(0);
Assert.assertNotNull(scriptlet);
Node.Scriptlet s = (Node.Scriptlet) scriptlet;
Assert.assertEquals("//Just a comment", s.getText());
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class AsyncStockContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
Stockticker stockticker = (Stockticker) sc.getAttribute(STOCK_TICKER_KEY);
stockticker.shutdown();
}
Aggregations