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


Java WebFilter类代码示例

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


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

示例1: Registration

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
public Registration(WebFilter annotation) {
    urlPatterns = new ArrayList<>();
    dispatcherTypes = new ArrayList<>();

    EnumSet<DispatcherType> dispatchers = EnumSet.noneOf(DispatcherType.class);
    dispatchers.addAll(Arrays.asList(annotation.dispatcherTypes()));

    if (annotation.value().length > 0) {
        addMappingForUrlPatterns(dispatchers, true, annotation.value());
    }

    if (annotation.urlPatterns().length > 0) {
        addMappingForUrlPatterns(dispatchers, true, annotation.urlPatterns());
    }

    asyncSupported = annotation.asyncSupported();
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:18,代码来源:FilterHolder.java

示例2: toMappedFilter

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
public MappedFilter toMappedFilter(Filter filter, int order) {

		WebFilter wfAnnotation = filter.getClass().getAnnotation(WebFilter.class);

		if (wfAnnotation == null) {
			throw new IllegalArgumentException(
					"Filter contains no @WebFilter annotation and can not be mapped directly. Wrap it in a MappedFilter instead.");
		}

		String name = wfAnnotation.filterName() != null && wfAnnotation.filterName().length() > 0
				? wfAnnotation.filterName() : null;
		Set<String> urlPatterns = new HashSet<>(asList(wfAnnotation.urlPatterns()));

		Map<String, String> initParams = new HashMap<>();

		WebInitParam[] paramsArray = wfAnnotation.initParams();
		if (paramsArray != null) {
			asList(paramsArray).forEach(p -> initParams.put(p.name(), p.value()));
		}

		return new MappedFilter(filter, urlPatterns, name, initParams, order);
	}
 
开发者ID:bootique,项目名称:bootique-jetty,代码行数:23,代码来源:MappedFilterFactory.java

示例3: registerJeeComponents

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private void registerJeeComponents(ConfigurableListableBeanFactory beanFactory, ClassLoader cl,
		Set<BeanDefinition> candiates) {

	for (BeanDefinition bd : candiates) {

		try {
			Class<?> beanClass = ClassUtils.forName(bd.getBeanClassName(), cl);
			WebServlet webServlet = beanClass.getDeclaredAnnotation(WebServlet.class);
			WebFilter webFilter = beanClass.getDeclaredAnnotation(WebFilter.class);
			WebListener webListener = beanClass.getDeclaredAnnotation(WebListener.class);

			DefaultListableBeanFactory targetBeanFactory = (DefaultListableBeanFactory) beanFactory;

			if (webServlet != null) {
				createAndRegisterServletBean(targetBeanFactory, bd, beanClass, webServlet);
			} else if (webFilter != null) {
				createAndRegisterServletFilterBean(targetBeanFactory, bd, beanClass, webFilter);
			} else if (webListener != null) {
				createAndRegisterWebListenerBean(targetBeanFactory, bd, beanClass, webListener);
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:thomasdarimont,项目名称:spring-boot-jee-web-example,代码行数:27,代码来源:JeeComponentsBeanFactoryPostProcessor.java

示例4: addFilter

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
/**
 * Method invoked for tracking filters that are registered via the OSGi service registry
 *
 * @param filter The filter to add
 * @return The name of the filter, if added
 */
private String addFilter(Filter filter) {
    Class<?> clz = filter.getClass();
    WebFilter ann = clz.getAnnotation(WebFilter.class);
    if (ann == null) {
        return null;
    }
    String name = ann.filterName();
    DynamicFRegistration reg = addFilter(name, filter);
    if (reg == null) {
        return null;
    }
    reg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, ann.urlPatterns());
    reg.addMappingForServletNames(EnumSet.allOf(DispatcherType.class), false, ann.servletNames());
    doParameters(reg, ann.initParams());
    return name;
}
 
开发者ID:arievanwi,项目名称:osgi.ee,代码行数:23,代码来源:OurServletContext.java

示例5: install

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
@Override
public void install(final Environment environment, final Filter instance) {
    final Class<? extends Filter> extType = FeatureUtils.getInstanceClass(instance);
    final WebFilter annotation = FeatureUtils.getAnnotation(extType, WebFilter.class);
    final String[] servlets = annotation.servletNames();
    final String[] patterns = annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value();
    Preconditions.checkArgument(servlets.length > 0 || patterns.length > 0,
            "Filter %s not specified servlet or pattern for mapping", extType.getName());
    Preconditions.checkArgument(servlets.length == 0 || patterns.length == 0,
            "Filter %s specifies both servlets and patters, when only one allowed",
            extType.getName());
    final boolean servletMapping = servlets.length > 0;
    final AdminContext context = FeatureUtils.getAnnotation(extType, AdminContext.class);
    final String name = WebUtils.getFilterName(annotation, extType);
    reporter.line("%-15s %-5s %-2s (%s)   %s", Joiner.on(",").join(servletMapping ? servlets : patterns),
            WebUtils.getAsyncMarker(annotation), WebUtils.getContextMarkers(context), extType.getName(), name);

    if (WebUtils.isForMain(context)) {
        configure(environment.servlets(), instance, name, annotation);
    }
    if (WebUtils.isForAdmin(context)) {
        configure(environment.admin(), instance, name, annotation);
    }
}
 
开发者ID:xvik,项目名称:dropwizard-guicey,代码行数:25,代码来源:WebFilterInstaller.java

示例6: configure

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private void configure(final ServletEnvironment environment, final Filter filter,
                       final String name, final WebFilter annotation) {
    final FilterRegistration.Dynamic mapping = environment.addFilter(name, filter);
    final EnumSet<DispatcherType> dispatcherTypes = EnumSet.copyOf(Arrays.asList(annotation.dispatcherTypes()));
    if (annotation.servletNames().length > 0) {
        mapping.addMappingForServletNames(dispatcherTypes, false, annotation.servletNames());
    } else {
        final String[] urlPatterns = annotation.urlPatterns().length > 0
                ? annotation.urlPatterns() : annotation.value();
        mapping.addMappingForUrlPatterns(dispatcherTypes, false, urlPatterns);
    }
    if (annotation.initParams().length > 0) {
        for (WebInitParam param : annotation.initParams()) {
            mapping.setInitParameter(param.name(), param.value());
        }
    }
    mapping.setAsyncSupported(annotation.asyncSupported());
}
 
开发者ID:xvik,项目名称:dropwizard-guicey,代码行数:19,代码来源:WebFilterInstaller.java

示例7: readAnnotatedFilterName

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private String readAnnotatedFilterName() {
    if (isAnnotated()) {
        WebFilter regAnnotation = filter.getClass().getAnnotation(WebFilter.class);
        if (!"".equals(regAnnotation.filterName().trim())) {
            return regAnnotation.filterName();
        } else {
            return filter.getClass().getName();
        }
    } else {
        return null;
    }
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:13,代码来源:FilterHolder.java

示例8: readAnnotatedInitParams

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private Map<String, String> readAnnotatedInitParams() {
    Map<String, String> initParams = new HashMap<>();
    if (isAnnotated()) {
        WebFilter regAnnotation = filter.getClass().getAnnotation(WebFilter.class);
        for (WebInitParam param : regAnnotation.initParams()) {
            initParams.put(param.name(), param.value());
        }
    }

    return initParams;
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:12,代码来源:FilterHolder.java

示例9: getAnnotation

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private WebFilter getAnnotation() {
    if (isAnnotated()) {
        return filter.getClass().getAnnotation(WebFilter.class);
    } else {
        return null;
    }
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:8,代码来源:FilterHolder.java

示例10: createAndRegisterServletFilterBean

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private void createAndRegisterServletFilterBean(DefaultListableBeanFactory beanFactory, BeanDefinition bd,
		Class<?> beanClass, WebFilter webFilter) {

	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(FilterRegistrationBean.class);
	builder.addPropertyValue("filter", bd);
	builder.addPropertyValue("urlPatterns", new LinkedHashSet<>(Arrays.asList(webFilter.urlPatterns())));

	String beanName = webFilter.filterName().isEmpty() ? StringUtils.uncapitalize(beanClass.getSimpleName())
			: webFilter.filterName();

	beanFactory.registerBeanDefinition(beanName, builder.getBeanDefinition());
}
 
开发者ID:thomasdarimont,项目名称:spring-boot-jee-web-example,代码行数:13,代码来源:JeeComponentsBeanFactoryPostProcessor.java

示例11: processFilters

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
private void processFilters() {
    Consumer<Class<? extends Filter>> c = filter -> {
        WebFilter webFilter = ClassUtils.getAnnotation(filter, WebFilter.class);
        if(webFilter != null) {
            FilterDescriptor filterDescriptor = new FilterDescriptor(webFilter.filterName(),
                    webFilter.value(), mapUrls(webFilter.urlPatterns()), webFilter.dispatcherTypes(),
                    webFilter.initParams(), webFilter.asyncSupported(), webFilter.servletNames(),
                    filter);
            webServer.addFilter(filterDescriptor);
        }
    };
    extension.processFilters(c);
}
 
开发者ID:hammock-project,项目名称:hammock,代码行数:14,代码来源:StartWebServer.java

示例12: bindAnnotatedFilters

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
/**
 * Sets up filters that are annotated with the {@link WebFilter} annotation.
 * Every class in the classpath is searched for the annotation.
 */
@SuppressWarnings("unchecked")
private void bindAnnotatedFilters() {

    String appsPackages = null;
    if (System.getProperties().containsKey(IO_JOYNR_APPS_PACKAGES)) {
        logger.info("Using property {} from system properties", IO_JOYNR_APPS_PACKAGES);
        appsPackages = System.getProperty(IO_JOYNR_APPS_PACKAGES);
    } else {
        Properties servletProperties = PropertyLoader.loadProperties("servlet.properties");
        if (servletProperties.containsKey(IO_JOYNR_APPS_PACKAGES)) {
            appsPackages = servletProperties.getProperty(IO_JOYNR_APPS_PACKAGES);
        }
    }

    if (appsPackages != null) {
        String[] packageNames = appsPackages.split(";");
        logger.info("Searching packages for @WebFilter annotation: {}", Arrays.toString(packageNames));

        PackageNamesScanner scanner = new PackageNamesScanner(packageNames);
        AnnotationScannerListener sl = new AnnotationScannerListener(WebFilter.class);
        scanner.scan(sl);

        for (Class<?> webFilterAnnotatedClass : sl.getAnnotatedClasses()) {

            if (Filter.class.isAssignableFrom(webFilterAnnotatedClass)) {
                bind(webFilterAnnotatedClass).in(Singleton.class);
                filter("/*").through((Class<? extends Filter>) webFilterAnnotatedClass);
                logger.info("Adding filter {} for '/*'", webFilterAnnotatedClass.getName());
            }

        }
    }
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:38,代码来源:AbstractJoynrServletModule.java

示例13: WebFilterHandler

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
WebFilterHandler() {
    super(WebFilter.class);
}
 
开发者ID:PebbleTemplates,项目名称:pebble-spring-boot-starter,代码行数:4,代码来源:WebFilterHandler.java

示例14: isAnnotated

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
public boolean isAnnotated() {
    return filter.getClass().isAnnotationPresent(WebFilter.class);
}
 
开发者ID:awslabs,项目名称:aws-serverless-java-container,代码行数:4,代码来源:FilterHolder.java

示例15: WebFilterHandler

import javax.servlet.annotation.WebFilter; //导入依赖的package包/类
WebFilterHandler() {
	super(WebFilter.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:4,代码来源:WebFilterHandler.java


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