Skip to content

Using Spring Request Scoped Beans in Atmosphere Requests

Jeanfrancois Arcand edited this page May 26, 2014 · 1 revision

If you register the AtmosphereInterceptor described below will enable request scoped beans with Atmosphere requests.

import org.atmosphere.config.service.AtmosphereInterceptorService;
import org.atmosphere.cpr.Action;
import org.atmosphere.cpr.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereInterceptor;
import org.atmosphere.cpr.AtmosphereResource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@AtmosphereInterceptorService
public class SpringInteceptor implements AtmosphereInterceptor{

    @Override
    public void configure(AtmosphereConfig config) {

    }

    @Override
    public Action inspect(AtmosphereResource r) {
        ServletRequestAttributes attributes = new ServletRequestAttributes(r.getRequest());
        LocaleContextHolder.setLocale(r.getRequest().getLocale(), true);
        RequestContextHolder.setRequestAttributes(attributes, true);

        return Action.CONTINUE;
    }

    @Override
    public void postInspect(AtmosphereResource r) {
        LocaleContextHolder.resetLocaleContext();
        RequestContextHolder.resetRequestAttributes();
    }

}

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally