当前位置: 首页>>代码示例>>Java>>正文


Java Dynamic类代码示例

本文整理汇总了Java中javax.servlet.FilterRegistration.Dynamic的典型用法代码示例。如果您正苦于以下问题:Java Dynamic类的具体用法?Java Dynamic怎么用?Java Dynamic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Dynamic类属于javax.servlet.FilterRegistration包,在下文中一共展示了Dynamic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onStartup

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
  public void onStartup(ServletContext servletContext) throws ServletException {
Dynamic fr = servletContext.addFilter("org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0", EmptyFilter.class);
if(fr!=null){
	fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/fuckSpringBootFilterSecurityInterceptor");
	fr.setAsyncSupported(true);
}

fr = servletContext.addFilter("org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0", EmptyFilter.class);
if(fr!=null){
	fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/fuckSpringBootFilterSecurityInterceptor");
	fr.setAsyncSupported(true);
}

fr = servletContext.addFilter("casFilter", EmptyFilter.class);
if(fr!=null){
	fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/fuckSpringBootFilterSecurityInterceptor");
	fr.setAsyncSupported(true);
}
  }
 
开发者ID:wayshall,项目名称:onetwo,代码行数:21,代码来源:FixSecurityFilterBugServletContextInitializer.java

示例2: run

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public void run(BlogConfiguration blogConfiguration, Environment environment) throws Exception {
    final BlogDao blogDao = new BlogDao(hibernate.getSessionFactory());

    // Register all resources here.
    environment.jersey().register(new BlogResources(blogDao));
    environment.jersey().register(new UploadResources());
    environment.jersey().register(new UnitTestResources());

    // Register MultiPartFeature.class to support mime type "multipart/form-data."
    environment.jersey().getResourceConfig().register(MultiPartFeature.class);

    // All Filter
    // CORS enable
    Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);
    filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
    filter.setInitParameter("allowCredentials", "true");

}
 
开发者ID:zslucky,项目名称:dropwizard-myblog,代码行数:24,代码来源:BlogApplication.java

示例3: testWithProviders

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Test
public void testWithProviders() throws ServletException {
  InitializeSessionManagement ism = new InitializeSessionManagement();
  ServletContext context = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic);
  when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader());
  ism.onStartup(null, context);
  @SuppressWarnings("rawtypes")
  ArgumentCaptor<HashMap> arg = ArgumentCaptor.forClass(HashMap.class);
  verify(context).setAttribute(eq(PROVIDERS), arg.capture());
  assertTrue(arg.getValue().containsKey("redis"));
  assertEquals(JedisSessionRepositoryFactory.class.getName(), arg.getValue().get("redis"));
  assertTrue(arg.getValue().containsKey("in-memory"));
  assertEquals(InMemoryRepositoryFactory.class.getName(), arg.getValue().get("in-memory"));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:17,代码来源:TestInitializeSessionManagement.java

示例4: registerServletFilter

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
/**
 * Add the given filter to the ServletContext and map it to the
 * {@code DispatcherServlet} as follows:
 * <ul>
 * <li>a default filter name is chosen based on its concrete type
 * <li>the {@code asyncSupported} flag is set depending on the
 * return value of {@link #isAsyncSupported() asyncSupported}
 * <li>a filter mapping is created with dispatcher types {@code REQUEST},
 * {@code FORWARD}, {@code INCLUDE}, and conditionally {@code ASYNC} depending
 * on the return value of {@link #isAsyncSupported() asyncSupported}
 * </ul>
 * <p>If the above defaults are not suitable or insufficient, override this
 * method and register filters directly with the {@code ServletContext}.
 * @param servletContext the servlet context to register filters with
 * @param filter the filter to be registered
 * @return the filter registration
 */
protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
	String filterName = Conventions.getVariableName(filter);
	Dynamic registration = servletContext.addFilter(filterName, filter);
	if (registration == null) {
		int counter = -1;
		while (counter == -1 || registration == null) {
			counter++;
			registration = servletContext.addFilter(filterName + "#" + counter, filter);
			Assert.isTrue(counter < 100,
					"Failed to register filter '" + filter + "'." +
					"Could the same Filter instance have been registered already?");
		}
	}
	registration.setAsyncSupported(isAsyncSupported());
	registration.addMappingForServletNames(getDispatcherTypes(), false, getServletName());
	return registration;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:AbstractDispatcherServletInitializer.java

示例5: handleFilter

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
private void handleFilter(FilterConfiguration filter,ServletContext webappContext){
	filter.getFilter().visit(clazz-> {
		setInitParameters(webappContext.addFilter(getName(filter),
					clazz), filter)
			.addMappingForUrlPatterns(
					EnumSet.allOf(DispatcherType.class),true,
					filter.getMapping());
		return 1; 
		}, obj-> {
						Dynamic filterReg = webappContext.addFilter(
								getName(filter), obj);
						
						filterReg.addMappingForUrlPatterns(
								EnumSet.allOf(DispatcherType.class),true,
								filter.getMapping());
						
						return 2;
					});
}
 
开发者ID:aol,项目名称:micro-server,代码行数:20,代码来源:FilterConfigurer.java

示例6: onStartup

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
	webAppContext.setConfigLocation(getClass().getPackage().getName());
	
       ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(webAppContext));
       dispatcher.setLoadOnStartup(1);
       dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

       OpenEntityManagerInViewFilter openEntityManagerInViewFilter = new OpenEntityManagerInViewFilter();
	openEntityManagerInViewFilter.setEntityManagerFactoryBeanName("entityManagerFactory");
	
	Dynamic dynamic = servletContext.addFilter("openEntityManagerInViewFilter", openEntityManagerInViewFilter);
	dynamic.addMappingForUrlPatterns(getDispatcherTypes(), false, DISPATCHER_SERVLET_MAPPING);
       
	servletContext.addListener(new ContextLoaderListener(webAppContext));
}
 
开发者ID:leosilvadev,项目名称:SJPAReference,代码行数:18,代码来源:ApplicationInitializer.java

示例7: onStartup

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);

    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());

    configureSessionCookie(servletContext);
    
    CharacterEncodingFilter cef = new CharacterEncodingFilter();
    cef.setEncoding("UTF-8");
    cef.setForceEncoding(true);
    
    Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", cef);
    characterEncodingFilter.setAsyncSupported(true);
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    //force log initialization, then disable it
    XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
    XRLog.setLoggingEnabled(false);

}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:22,代码来源:Initializer.java

示例8: setupContext

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
/**
 * Sets up servlet context - registers {@link SessionFilter} and
 * {@link ShutdownListener}.
 *
 * @param context
 *          servlet context to set up
 */
static void setupContext(ServletContext context) {
  if (ServletLevel.isServlet3) {
    // When using Servlet 3.x+, we will register SessionFilter to make
    // sure session replacement is enabled
    Dynamic reg = context.addFilter("com.amdeus.session.filter", new SessionFilter());
    if (reg != null) {
      // The filter applies to all requests
      reg.addMappingForUrlPatterns(null, false, "/*");
    }
    // At the web app shutdown, we need to do some cleanup
    context.addListener(new ShutdownListener());
  }
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:21,代码来源:SessionHelpers.java

示例9: testDefaultWithNullClasses

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Test
public void testDefaultWithNullClasses() throws ServletException {
  InitializeSessionManagement ism = new InitializeSessionManagement();
  ServletContext context = mock(ServletContext.class);
  when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader());
  Dynamic dynamic = mock(Dynamic.class);
  when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic);
  ism.onStartup(null, context);
  verify(context).addFilter(eq("com.amdeus.session.filter"), any(SessionFilter.class));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:11,代码来源:TestInitializeSessionManagement.java

示例10: testDefault

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Test
public void testDefault() throws ServletException {
  InitializeSessionManagement ism = new InitializeSessionManagement();
  Set<Class<?>> classes = Collections.emptySet();
  ServletContext context = mock(ServletContext.class);
  Dynamic dynamic = mock(Dynamic.class);
  when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic);
  when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader());
  ism.onStartup(classes, context);
  verify(context).addFilter(eq("com.amdeus.session.filter"), any(SessionFilter.class));
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:12,代码来源:TestInitializeSessionManagement.java

示例11: registerDispatcherServlet

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
/**
 * Register a {@link DispatcherServlet} against the given servlet context.
 * <p>This method will create a {@code DispatcherServlet} with the name returned by
 * {@link #getServletName()}, initializing it with the application context returned
 * from {@link #createServletApplicationContext()}, and mapping it to the patterns
 * returned from {@link #getServletMappings()}.
 * <p>Further customization can be achieved by overriding {@link
 * #customizeRegistration(ServletRegistration.Dynamic)} or
 * {@link #createDispatcherServlet(WebApplicationContext)}.
 * @param servletContext the context to register the servlet against
 */
protected void registerDispatcherServlet(ServletContext servletContext) {
	String servletName = getServletName();
	Assert.hasLength(servletName, "getServletName() must not return empty or null");

	WebApplicationContext servletAppContext = createServletApplicationContext();
	Assert.notNull(servletAppContext,
			"createServletApplicationContext() did not return an application " +
			"context for servlet [" + servletName + "]");

	FrameworkServlet dispatcherServlet = createDispatcherServlet(servletAppContext);
	dispatcherServlet.setContextInitializers(getServletApplicationContextInitializers());

	ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet);
	Assert.notNull(registration,
			"Failed to register servlet with name '" + servletName + "'." +
			"Check if there is another servlet registered under the same name.");

	registration.setLoadOnStartup(1);
	registration.addMapping(getServletMappings());
	registration.setAsyncSupported(isAsyncSupported());

	Filter[] filters = getServletFilters();
	if (!ObjectUtils.isEmpty(filters)) {
		for (Filter filter : filters) {
			registerServletFilter(servletContext, filter);
		}
	}

	customizeRegistration(registration);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:AbstractDispatcherServletInitializer.java

示例12: addServlet

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) {
	if (servlets.containsKey(servletName)) {
		return null;
	}
	servlets.put(servletName, servlet);
	MockServletRegistration registration = new MockServletRegistration();
	servletRegistrations.put(servletName, registration);
	return registration;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AnnotationConfigDispatcherServletInitializerTests.java

示例13: addFilter

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public Dynamic addFilter(String filterName, Filter filter) {
	if (filters.containsKey(filterName)) {
		return null;
	}
	filters.put(filterName, filter);
	MockFilterRegistration registration = new MockFilterRegistration();
	filterRegistrations.put(filterName, registration);
	return registration;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:AnnotationConfigDispatcherServletInitializerTests.java

示例14: contextInitialized

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
    Dynamic filterRegistration = sce.getServletContext().addFilter("BraveServletFilter",
        new BraveServletFilter(brave.serverRequestInterceptor(), brave.serverResponseInterceptor(), new DefaultSpanNameProvider()));
    // Explicit mapping to avoid trace on readiness probe
    filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/api/hello", "/api/hello-chaining");
}
 
开发者ID:redhat-helloworld-msa,项目名称:hello,代码行数:8,代码来源:ZipKinFilter.java

示例15: addExplicitlyDeclaredFilters

import javax.servlet.FilterRegistration.Dynamic; //导入依赖的package包/类
private void addExplicitlyDeclaredFilters(ServletContext webappContext) {
	for (FilterData filterData : filterData) {
		Dynamic filterReg = webappContext.addFilter(
				filterData.getFilterName(), filterData.getFilter());
		
		filterReg.addMappingForUrlPatterns(
				EnumSet.allOf(DispatcherType.class),true,
				filterData.getMapping());
		logFilter(filterData);
	}
}
 
开发者ID:aol,项目名称:micro-server,代码行数:12,代码来源:FilterConfigurer.java


注:本文中的javax.servlet.FilterRegistration.Dynamic类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。