Java Code Examples for org.springframework.web.context.request.RequestContextListener

The following examples show how to use org.springframework.web.context.request.RequestContextListener. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: konker-platform   Source File: RegistryAppInitializer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    super.onStartup(servletContext);
    servletContext.addListener(new RequestContextListener());

    // verifying configs for features activation
    Set<String> profiles = new HashSet<String>();
    if (isEmailFeaturesEnabled()) {
        profiles.add("email");
    }
    if (isCdnFeaturesEnabled()) {
        profiles.add("cdn");
    }
    if (isSslFeaturesEnabled()) {
        profiles.add("ssl");
    }

    servletContext.setInitParameter("spring.profiles.active", StringUtils.arrayToCommaDelimitedString(profiles.toArray()));
}
 
Example 2
/**
 * Test of getPage method, of class fr.paris.lutece.portal.web.search.SearchApp.
 * 
 * @throws SiteMessageException
 */
public void testGetPage( ) throws SiteMessageException
{
    System.out.println( "getPage" );

    MockHttpServletRequest request = new MockHttpServletRequest( );
    request.addParameter( "query", "lutece" );
    request.addParameter( "items_per_page", "5" );

    RequestContextListener listener = new RequestContextListener( );
    ServletContext context = new MockServletContext( );
    listener.requestInitialized( new ServletRequestEvent( context, request ) );

    int nMode = 0;
    Plugin plugin = null;
    SearchApp instance = SpringContextService.getBean( "core.xpage.search" );

    assertNotNull( instance.getPage( request, nMode, plugin ) );

    listener.requestDestroyed( new ServletRequestEvent( context, request ) );
}
 
Example 3
Source Project: metamodel-membrane   Source File: WebServer.java    License: Apache License 2.0 5 votes vote down vote up
public static void startServer(int port, boolean enableCors) throws Exception {
    final DeploymentInfo deployment = Servlets.deployment().setClassLoader(WebServer.class.getClassLoader());
    deployment.setContextPath("");
    deployment.setDeploymentName("membrane");
    deployment.addInitParameter("contextConfigLocation", "classpath:context/application-context.xml");
    deployment.setResourceManager(new FileResourceManager(new File("."), 0));
    deployment.addListener(Servlets.listener(ContextLoaderListener.class));
    deployment.addListener(Servlets.listener(RequestContextListener.class));
    deployment.addServlet(Servlets.servlet("dispatcher", DispatcherServlet.class).addMapping("/*")
            .addInitParam("contextConfigLocation", "classpath:context/dispatcher-servlet.xml"));
    deployment.addFilter(Servlets.filter(CharacterEncodingFilter.class).addInitParam("forceEncoding", "true")
            .addInitParam("encoding", "UTF-8"));

    final DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment);
    manager.deploy();

    final HttpHandler handler;
    if (enableCors) {
        CorsHandlers corsHandlers = new CorsHandlers();
        handler = corsHandlers.allowOrigin(manager.start());
    } else {
        handler = manager.start();
    }

    final Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0").setHandler(handler).build();
    server.start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // graceful shutdown of everything
            server.stop();
            try {
                manager.stop();
            } catch (ServletException e) {
            }
            manager.undeploy();
        }
    });
}
 
Example 4
Source Project: joinfaces   Source File: JoinfacesAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This registers a {@link RequestContextFilter} in case {@link WebMvcAutoConfiguration} is not loaded.
 *
 * @see WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextFilter()
 * @return The {@link RequestContextFilter} Bean.
 */
@Bean
@ConditionalOnMissingBean({ RequestContextListener.class, RequestContextFilter.class })
@ConditionalOnMissingFilterBean(RequestContextFilter.class)
public static RequestContextFilter requestContextFilter() {
	return new OrderedRequestContextFilter();
}
 
Example 5
Source Project: spring-boot   Source File: WebMVCConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义,并注册   listener 演示
 * 直接用 Bean ,也可以用 ServletListenerRegistrationBean
 *
 * @return
 */
// 向系统注册一个 RequestContextListener Bean ,这样在其他组件中就可以使用了
//  CustomUserDetailsService 用到,用于截获 HttpServletRequest
//  @Autowired
//  private HttpServletRequest request;
@Bean
public RequestContextListener requestContextListener() {

    return new RequestContextListener();
}
 
Example 6
protected void createWebApplicationContext(ServletContext servletContext, Class clazz) {
        log.info("Creating Web Application Context started");

        List<Class> configClasses = new ArrayList<>();
        configClasses.add(clazz);

        // let's determine if this is a cloud based server
        Cloud cloud = getCloud();

        String activeProfiles = System.getProperty(SPRING_PROFILES_ACTIVE);

        if (StringUtils.isEmpty(activeProfiles)) {
            if (cloud == null) {
                // if no active profiles are specified, we default to these profiles
                activeProfiles = String.format("%s,%s,%s,%s,%s", MONGODB_LOCAL,REDIS_LOCAL,RABBIT_LOCAL,ELASTICSEARCH_LOCAL,LOCAL);
            } else {
                activeProfiles = String.format("%s,%s,%s,%s,%s", MONGODB_CLOUD,REDIS_CLOUD,RABBIT_CLOUD,ELASTICSEARCH_CLOUD,CLOUD);
            }
        }

        log.info("Active spring profiles: " + activeProfiles);

        // load local or cloud based configs
        if (cloud != null) {

            // list available service - fail servlet initializing if we are missing one that we require below
            printAvailableCloudServices(cloud.getServiceInfos());

        }

        AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
        appContext.register(configClasses.toArray(new Class[configClasses.size()]));

        servletContext.addListener(new ContextLoaderListener(appContext));
        servletContext.addListener(new RequestContextListener());

//        log.info("Creating Web Application Context completed");
    }
 
Example 7
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

	/* Setting the configuration classes */
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setConfigLocation("qa.qcri.aidr.data.config");

	/*Configuring error handler filter for errors out isde the controllers
	FilterRegistration.Dynamic errorHandlerFilter = servletContext.addFilter("errorHandlerFilter", new ErrorHandlerFilter());
	errorHandlerFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
	*/
	FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", new org.springframework.web.filter.CharacterEncodingFilter());
	encodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
	encodingFilter.setInitParameter("encoding", "UTF-8");
	encodingFilter.setInitParameter("forceEncoding", "true");
	
	/* Adding context listener */
	servletContext.addListener(new ContextLoaderListener(context));
	
	/* Adding request listener */
	servletContext.addListener(new RequestContextListener());

	/* Configuring dispatcher servlet for spring mvc */
	/*CustomDispatcherServlet servlet = new CustomDispatcherServlet(context); */
	ServletRegistration.Dynamic appServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
	appServlet.setLoadOnStartup(1);
	appServlet.addMapping("/*");
}
 
Example 8
Source Project: we-cmdb   Source File: SpringWebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletListenerRegistrationBean<ServletRequestListener> registerRequestListener() {
    ServletListenerRegistrationBean<ServletRequestListener> servletListenerRegistrationBean = new ServletListenerRegistrationBean<>();
    servletListenerRegistrationBean.setListener(new RequestContextListener());
    return servletListenerRegistrationBean;
}
 
Example 9
@Bean
@Order(0)
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 10
Source Project: MeetingFilm   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * RequestContextListener注册
 */
@Bean
public ServletListenerRegistrationBean<RequestContextListener> requestContextListenerRegistration() {
    return new ServletListenerRegistrationBean<>(new RequestContextListener());
}
 
Example 11
Source Project: WebStack-Guns   Source File: WebConfig.java    License: MIT License 4 votes vote down vote up
/**
 * RequestContextListener注册
 */
@Bean
public ServletListenerRegistrationBean<RequestContextListener> requestContextListenerRegistration() {
    return new ServletListenerRegistrationBean<>(new RequestContextListener());
}
 
Example 12
@Bean 
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 13
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 14
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 15
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
	return new RequestContextListener();
}
 
Example 16
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 17
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
	return new RequestContextListener();
}
 
Example 18
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 19
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 20
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 21
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
	return new RequestContextListener();
}
 
Example 22
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 23
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 24
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 25
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 26
Source Project: Spring   Source File: WebConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 27
Source Project: n2o-framework   Source File: N2oContextConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnBean(SessionContextEngine.class)
public RequestContextListener requestContextListener(){
    return new RequestContextListener();
}
 
Example 28
Source Project: kob   Source File: ListenerConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 29
Source Project: wetech-admin   Source File: WebConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public RequestContextListener requestContextListener() {
    return new RequestContextListener();
}
 
Example 30
Source Project: Guns   Source File: WebConfig.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * RequestContextListener注册
 */
@Bean
public ServletListenerRegistrationBean<RequestContextListener> requestContextListenerRegistration() {
    return new ServletListenerRegistrationBean<>(new RequestContextListener());
}