org.atmosphere.cpr.AtmosphereInterceptor Java Examples

The following examples show how to use org.atmosphere.cpr.AtmosphereInterceptor. 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
Source File: AtmosphereUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void addInterceptors(AtmosphereFramework framework, Bus bus) {
    Object ais = bus.getProperty("atmosphere.interceptors");
    // pre-install those atmosphere default interceptors before the custom interceptors.
    framework.interceptor(new CacheHeadersInterceptor()).interceptor(new HeartbeatInterceptor())
    .interceptor(new SSEAtmosphereInterceptor()).interceptor(new JavaScriptProtocol());

    if (ais == null || ais instanceof AtmosphereInterceptor) {
        framework.interceptor(ais == null
            ? new DefaultProtocolInterceptor() : (AtmosphereInterceptor)ais);
        return;
    }
    if (ais instanceof List<?>) {
        List<AtmosphereInterceptor> icps = CastUtils.cast((List<?>)ais);
        // add the custom interceptors
        for (AtmosphereInterceptor icp : icps) {
            framework.interceptor(icp);
        }
    }
}
 
Example #2
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (DefaultProtocolInterceptor.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #3
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #4
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
 
Example #5
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (DefaultProtocolInterceptor.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #6
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example #7
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
 
Example #8
Source File: PushRequestHandler.java    From flow with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes Atmosphere for the given ServletConfiguration.
 *
 * @param vaadinServletConfig
 *            The servlet configuration for the servlet which should have
 *            Atmosphere support
 */
static AtmosphereFramework initAtmosphere(
        final ServletConfig vaadinServletConfig) {
    AtmosphereFramework atmosphere = new AtmosphereFramework(false, false) {
        @Override
        protected void analytics() {
            // Overridden to disable version number check
        }

        @Override
        public AtmosphereFramework addInitParameter(String name,
                String value) {
            if (vaadinServletConfig.getInitParameter(name) == null) {
                super.addInitParameter(name, value);
            }
            return this;
        }
    };

    atmosphere.addAtmosphereHandler("/*", new PushAtmosphereHandler());
    atmosphere.addInitParameter(ApplicationConfig.BROADCASTER_CACHE,
            UUIDBroadcasterCache.class.getName());
    atmosphere.addInitParameter(ApplicationConfig.ANNOTATION_PROCESSOR,
            VoidAnnotationProcessor.class.getName());
    atmosphere.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT,
            "true");
    atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER,
            String.valueOf(PushConstants.MESSAGE_DELIMITER));
    atmosphere.addInitParameter(
            ApplicationConfig.DROP_ACCESS_CONTROL_ALLOW_ORIGIN_HEADER,
            "false");
    // Disable heartbeat (it does not emit correct events client side)
    // https://github.com/Atmosphere/atmosphere-javascript/issues/141
    atmosphere.addInitParameter(
            ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTORS,
            HeartbeatInterceptor.class.getName());

    final String bufferSize = String
            .valueOf(PushConstants.WEBSOCKET_BUFFER_SIZE);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE,
            bufferSize);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE,
            bufferSize);
    atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE,
            bufferSize);
    atmosphere.addInitParameter(
            ApplicationConfig.PROPERTY_ALLOW_SESSION_TIMEOUT_REMOVAL,
            "false");
    // This prevents Atmosphere from recreating a broadcaster after it has
    // already been destroyed when the servlet is being undeployed
    // (see #20026)
    atmosphere.addInitParameter(ApplicationConfig.RECOVER_DEAD_BROADCASTER,
            "false");
    // Disable Atmosphere's message about commercial support
    atmosphere.addInitParameter("org.atmosphere.cpr.showSupportMessage",
            "false");

    try {
        atmosphere.init(vaadinServletConfig);

        // Ensure the client-side knows how to split the message stream
        // into individual messages when using certain transports
        AtmosphereInterceptor trackMessageSize = new TrackMessageSizeInterceptor();
        trackMessageSize.configure(atmosphere.getAtmosphereConfig());
        atmosphere.interceptor(trackMessageSize);

    } catch (ServletException e) {
        throw new RuntimeException("Atmosphere init failed", e);
    }
    return atmosphere;
}