use of javax.servlet.FilterRegistration in project tutorials by eugenp.
the class SpringBootWithoutServletComponentIntegrationTest method givenServletContext_whenCheckFilterMappings_thenEmpty.
@Test
public void givenServletContext_whenCheckFilterMappings_thenEmpty() {
assertNotNull(servletContext);
FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter");
assertNull(filterRegistration);
}
use of javax.servlet.FilterRegistration in project AJSC by att.
the class CamundaBpmWebappInitializer method registerFilter.
private FilterRegistration registerFilter(final String filterName, final Class<? extends Filter> filterClass, final Map<String, String> initParameters, final String... urlPatterns) {
FilterRegistration filterRegistration = servletContext.getFilterRegistration(filterName);
if (filterRegistration == null) {
filterRegistration = servletContext.addFilter(filterName, filterClass);
filterRegistration.addMappingForUrlPatterns(DISPATCHER_TYPES, true, urlPatterns);
if (initParameters != null) {
filterRegistration.setInitParameters(initParameters);
}
}
return filterRegistration;
}
use of javax.servlet.FilterRegistration in project jetty.project by eclipse.
the class TestListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
// System.err.println("contextInitialized "+sce);
_called.put("contextInitialized", new Throwable());
//configure programmatic security
ServletRegistration.Dynamic rego = sce.getServletContext().addServlet("RegoTest", RegTest.class.getName());
rego.addMapping("/rego/*");
HttpConstraintElement constraintElement = new HttpConstraintElement(ServletSecurity.EmptyRoleSemantic.PERMIT, ServletSecurity.TransportGuarantee.NONE, new String[] { "admin" });
ServletSecurityElement securityElement = new ServletSecurityElement(constraintElement, null);
Set<String> unchanged = rego.setServletSecurity(securityElement);
//// System.err.println("Security constraints registered: "+unchanged.isEmpty());
//Test that a security constraint from web.xml can't be overridden programmatically
ServletRegistration.Dynamic rego2 = sce.getServletContext().addServlet("RegoTest2", RegTest.class.getName());
rego2.addMapping("/rego2/*");
securityElement = new ServletSecurityElement(constraintElement, null);
unchanged = rego2.setServletSecurity(securityElement);
//// System.err.println("Overridding web.xml constraints not possible:" +!unchanged.isEmpty());
/* For servlet 3.0 */
FilterRegistration registration = sce.getServletContext().addFilter("TestFilter", TestFilter.class.getName());
if (//otherwise defined in web.xml
registration != null) {
((FilterRegistration.Dynamic) registration).setAsyncSupported(true);
} else {
registration = sce.getServletContext().getFilterRegistration("TestFilter");
}
registration.setInitParameter("remote", "false");
registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.ERROR, DispatcherType.ASYNC, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST), true, new String[] { "/*" });
}
use of javax.servlet.FilterRegistration in project ocvn by devgateway.
the class WebInitializer method onStartup.
@Override
public void onStartup(final ServletContext sc) throws ServletException {
sc.addFilter("Spring OpenEntityManagerInViewFilter", org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class).addMappingForUrlPatterns(null, false, "/*");
FilterRegistration filter = sc.addFilter("wicket-filter", WicketFilter.class);
filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName());
filter.setInitParameter(PARAM_APP_BEAN, "formsWebApplication");
// This line is the only surprise when comparing to the equivalent
// web.xml. Without some initialization seems to be missing.
filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*");
filter.addMappingForUrlPatterns(null, false, "/*");
// // Request Listener
sc.addListener(new RequestContextListener());
sc.addListener(new HttpSessionEventPublisher());
}
use of javax.servlet.FilterRegistration in project Payara by payara.
the class EmbeddedCreateServletAndFilterTest method testEmbeddedAddServletDefaultVS.
@Test
public void testEmbeddedAddServletDefaultVS() throws Exception {
VirtualServer vs = embedded.getVirtualServer("server");
System.out.println("Default virtual server " + vs);
Context context = (Context) embedded.createContext(root);
Class<NewFilterServlet> servletCl = (Class<NewFilterServlet>) Class.forName("org.glassfish.tests.embedded.web.NewFilterServlet");
NewFilterServlet filterServlet = context.createServlet(servletCl);
ServletRegistration sr = context.addServlet("NewFilterServlet", filterServlet);
sr.setInitParameter("servletInitName", "servletInitValue");
sr.addMapping("/newFilterServlet");
Class<NewFilter> filterCl = (Class<NewFilter>) Class.forName("org.glassfish.tests.embedded.web.NewFilter");
NewFilter filter = context.createFilter(filterCl);
FilterRegistration fr = context.addFilter("NewFilter", filter);
fr.setInitParameter("filterInitName", "filterInitValue");
fr.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "NewFilterServlet");
vs.addContext(context, contextRoot);
URL servlet = new URL("http://localhost:8080/" + contextRoot + "/newFilterServlet");
URLConnection yc = servlet.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
StringBuilder sb = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
vs.removeContext(context);
}
Aggregations