Java Code Examples for org.springframework.boot.web.servlet.FilterRegistrationBean#setAsyncSupported()

The following examples show how to use org.springframework.boot.web.servlet.FilterRegistrationBean#setAsyncSupported() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
public FilterRegistrationBean springMvcDelegatingFilterProxy() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    SpringMvcSofaTracerFilter filter = new SpringMvcSofaTracerFilter();
    filterRegistrationBean.setFilter(filter);
    List<String> urlPatterns = openTracingSpringProperties.getUrlPatterns();
    if (urlPatterns == null || urlPatterns.size() <= 0) {
        filterRegistrationBean.addUrlPatterns("/*");
    } else {
        filterRegistrationBean.setUrlPatterns(urlPatterns);
    }
    filterRegistrationBean.setName(filter.getFilterName());
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setOrder(openTracingSpringProperties.getFilterOrder());
    return filterRegistrationBean;
}
 
Example 2
Source Project: para   File: ParaServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return CORS filter bean
 */
@Bean
public FilterRegistrationBean<?> corsFilterRegistrationBean() {
	String path = Api1.PATH + "*";
	logger.debug("Initializing CORS filter [{}]...", path);
	FilterRegistrationBean<?> frb = new FilterRegistrationBean<>(new CORSFilter());
	frb.addInitParameter("cors.support.credentials", "true");
	frb.addInitParameter("cors.allowed.methods", "GET,POST,PATCH,PUT,DELETE,HEAD,OPTIONS");
	frb.addInitParameter("cors.exposed.headers", "Cache-Control,Content-Length,Content-Type,Date,ETag,Expires");
	frb.addInitParameter("cors.allowed.headers", "Origin,Accept,X-Requested-With,Content-Type,"
			+ "Access-Control-Request-Method,Access-Control-Request-Headers,X-Amz-Credential,"
			+ "X-Amz-Date,Authorization");
	frb.addUrlPatterns(path, "/" + JWTRestfulAuthFilter.JWT_ACTION);
	frb.setAsyncSupported(true);
	frb.setEnabled(Config.CORS_ENABLED);
	frb.setMatchAfter(false);
	frb.setOrder(2);
	return frb;
}
 
Example 3
/**
 * RequestDetailFilter配置
 *
 * @return
 */
@Bean
public FilterRegistrationBean requestDetailFilter() {
    SpringBootPlusFilterProperties.FilterConfig requestFilterConfig = filterConfig.getRequest();
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new RequestDetailFilter());
    filterRegistrationBean.setEnabled(requestFilterConfig.isEnable());
    filterRegistrationBean.addUrlPatterns(requestFilterConfig.getUrlPatterns());
    filterRegistrationBean.setOrder(requestFilterConfig.getOrder());
    filterRegistrationBean.setAsyncSupported(requestFilterConfig.isAsync());
    return filterRegistrationBean;
}
 
Example 4
/**
 * XssFilter配置
 *
 * @return
 */
@Bean
public FilterRegistrationBean xssFilter() {
    SpringBootPlusFilterProperties.FilterConfig xssFilterConfig = filterConfig.getXss();
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new XssFilter());
    filterRegistrationBean.setEnabled(xssFilterConfig.isEnable());
    filterRegistrationBean.addUrlPatterns(xssFilterConfig.getUrlPatterns());
    filterRegistrationBean.setOrder(xssFilterConfig.getOrder());
    filterRegistrationBean.setAsyncSupported(xssFilterConfig.isAsync());
    return filterRegistrationBean;
}
 
Example 5
Source Project: spring-boot-plus   File: ShiroConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * ShiroFilter配置
 *
 * @return
 */
@Bean
public FilterRegistrationBean delegatingFilterProxy() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    DelegatingFilterProxy proxy = new DelegatingFilterProxy();
    proxy.setTargetFilterLifecycle(true);
    proxy.setTargetBeanName(SHIRO_FILTER_NAME);
    filterRegistrationBean.setFilter(proxy);
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setEnabled(true);
    filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
    return filterRegistrationBean;
}
 
Example 6
Source Project: chronus   File: ShiroConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean<Filter> filterRegistrationBean(ShiroFilterFactoryBean shiroFilterFactoryBean) throws Exception {
    FilterRegistrationBean<Filter> filterRegistration = new FilterRegistrationBean<>();
    filterRegistration.setFilter((Filter) shiroFilterFactoryBean.getObject());
    filterRegistration.addInitParameter("targetFilterLifecycle", "true");
    filterRegistration.setAsyncSupported(true);
    filterRegistration.setEnabled(true);
    //这里添加一下对DispatcherType.ASYNC的支持就可以了
    filterRegistration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
    return filterRegistration;
}
 
Example 7
Source Project: poli   File: AppConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public FilterRegistrationBean authFilterRegistry() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setName("authFilter");
    registration.setFilter(new AuthFilter());
    registration.addUrlPatterns("/*");
    registration.setAsyncSupported(Boolean.TRUE);
    registration.setEnabled(Boolean.TRUE);
    return registration;
}
 
Example 8
Source Project: java-jaxrs   File: Configuration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public FilterRegistrationBean spanFinishingFilter() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new SpanFinishingFilter());
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST);
    filterRegistrationBean.addUrlPatterns("*");
    return filterRegistrationBean;
}
 
Example 9
@Bean
@SuppressWarnings({"rawtypes", "unchecked"}) // generic as of Spring Boot 2
public FilterRegistrationBean tracingFilter(
        final Tracer tracer) {

    final TracingFilter filter = new TracingFilter(tracer, emptyList(), null);
    final FilterRegistrationBean bean = new FilterRegistrationBean(filter);
    bean.setAsyncSupported(true);

    return bean;
}
 
Example 10
@Bean
@SuppressWarnings({"rawtypes", "unchecked"}) // generic as of Spring Boot 2
public FilterRegistrationBean tracingFilter(
        final Tracer tracer) {

    final TracingFilter filter = new TracingFilter(tracer, emptyList(), null);
    final FilterRegistrationBean bean = new FilterRegistrationBean(filter);
    bean.setAsyncSupported(true);

    return bean;
}
 
Example 11
@Bean
@SuppressWarnings({"rawtypes", "unchecked"}) // generic as of Spring Boot 2
public FilterRegistrationBean tracingFilter(
        final Tracer tracer,
        final List<ServletFilterSpanDecorator> decorators) {

    final TracingFilter filter = new TracingFilter(tracer, decorators, null);
    final FilterRegistrationBean bean = new FilterRegistrationBean(filter);
    bean.setAsyncSupported(true);

    return bean;
}
 
Example 12
@Bean
@SuppressWarnings({"rawtypes", "unchecked"}) // generic as of Spring Boot 2
public FilterRegistrationBean tracingFilter(
        final Tracer tracer,
        final List<ServletFilterSpanDecorator> decorators) {

    final TracingFilter filter = new TracingFilter(tracer, decorators, null);
    final FilterRegistrationBean bean = new FilterRegistrationBean(filter);
    bean.setAsyncSupported(true);

    return bean;
}
 
Example 13
Source Project: para   File: ParaServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return GZIP filter bean
 */
@Bean
public FilterRegistrationBean<?> gzipFilterRegistrationBean() {
	String path = Api1.PATH + "*";
	FilterRegistrationBean<?> frb = new FilterRegistrationBean<>(new GZipServletFilter());
	logger.debug("Initializing GZip filter [{}]...", path);
	frb.addUrlPatterns(path);
	frb.setAsyncSupported(true);
	frb.setEnabled(Config.GZIP_ENABLED);
	frb.setMatchAfter(true);
	frb.setOrder(20);
	return frb;
}
 
Example 14
@Bean
public FilterRegistrationBean spanFinishingFilter() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new SpanFinishingFilter());
    filterRegistrationBean.setAsyncSupported(true);
    filterRegistrationBean.setOrder(Integer.MIN_VALUE);
    filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST);
    filterRegistrationBean.addUrlPatterns("*");
    return filterRegistrationBean;
}
 
Example 15
/**
 * Registers the JavaMelody {@link MonitoringFilter}. The filter can be overridden completely by creating a custom
 * {@link FilterRegistrationBean} with the name "javamelody-registration" in the application context.
 * @param properties JavaMelodyConfigurationProperties
 * @param servletContext ServletContext
 * @return FilterRegistrationBean
 */
@Bean(name = REGISTRATION_BEAN_NAME)
@ConditionalOnMissingBean(name = REGISTRATION_BEAN_NAME)
public FilterRegistrationBean<MonitoringFilter> monitoringFilter(
		JavaMelodyConfigurationProperties properties, ServletContext servletContext) {
	final FilterRegistrationBean<MonitoringFilter> registrationBean = new FilterRegistrationBean<>();

	// Create the monitoring filter and set its configuration parameters.
	final MonitoringFilter filter;
	if (properties.isManagementEndpointMonitoringEnabled()) {
		// if the management endpoint is enabled, disable the /monitoring reports on the application port
		filter = new MonitoringFilter() {
			@Override
			protected boolean isAllowed(HttpServletRequest request,
					HttpServletResponse response) throws IOException {
				response.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden access");
				return false;
			}
		};
	} else {
		filter = new MonitoringFilter();
	}
	filter.setApplicationType("Spring Boot");

	// Wrap the monitoring filter in the registration bean.
	registrationBean.setFilter(filter);
	registrationBean.setAsyncSupported(true);
	registrationBean.setName("javamelody");
	registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);

	// Set the initialization parameter for the monitoring filter.
	for (final Entry<String, String> parameter : properties.getInitParameters().entrySet()) {
		registrationBean.addInitParameter(parameter.getKey(), parameter.getValue());
	}

	// Set the URL patterns to activate the monitoring filter for.
	registrationBean.addUrlPatterns("/*");

	final FilterRegistration filterRegistration = servletContext
			.getFilterRegistration("javamelody");
	if (filterRegistration != null) {
		// if webapp deployed as war in a container with MonitoringFilter already added by web-fragment.xml,
		// do not try to add it again
		registrationBean.setEnabled(false);
		for (final Map.Entry<String, String> entry : registrationBean.getInitParameters()
				.entrySet()) {
			filterRegistration.setInitParameter(entry.getKey(), entry.getValue());
		}
	}
	return registrationBean;
}