Search in sources :

Example 1 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereUtils method addInterceptors.

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);
        }
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) SSEAtmosphereInterceptor(org.atmosphere.interceptor.SSEAtmosphereInterceptor) HeartbeatInterceptor(org.atmosphere.interceptor.HeartbeatInterceptor) JavaScriptProtocol(org.atmosphere.interceptor.JavaScriptProtocol) CacheHeadersInterceptor(org.atmosphere.interceptor.CacheHeadersInterceptor) SSEAtmosphereInterceptor(org.atmosphere.interceptor.SSEAtmosphereInterceptor) List(java.util.List)

Example 2 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereWebSocketJettyDestinationTest method testUseCXFDefaultAtmoosphereInterceptor.

@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);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 3 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereWebSocketJettyDestinationTest method testUseCustomAtmoosphereInterceptor.

@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);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 4 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereWebSocketServletDestinationTest method testUseCXFDefaultAtmoosphereInterceptor.

@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);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 5 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereWebSocketServletDestinationTest method testUseCustomAtmoosphereInterceptor.

@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);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Aggregations

AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)15 Bus (org.apache.cxf.Bus)6 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)6 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)6 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)5 AtmosphereHandler (org.atmosphere.cpr.AtmosphereHandler)3 IOException (java.io.IOException)2 WebSocketHandlerService (org.atmosphere.config.service.WebSocketHandlerService)2 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)2 AtmosphereResourceEvent (org.atmosphere.cpr.AtmosphereResourceEvent)2 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)2 BroadcastFilter (org.atmosphere.cpr.BroadcastFilter)2 ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1