Search in sources :

Example 11 with AsyncIOWriter

use of org.atmosphere.runtime.AsyncIOWriter in project atmosphere by Atmosphere.

the class AndroidAtmosphereInterceptor method inspect.

@Override
public Action inspect(final AtmosphereResource r) {
    if (!r.transport().equals(TRANSPORT.STREAMING))
        return Action.CONTINUE;
    final AtmosphereResponse response = AtmosphereResourceImpl.class.cast(r).getResponse(false);
    String userAgent = AtmosphereResourceImpl.class.cast(r).getRequest(false).getHeader("User-Agent");
    if (userAgent != null && (userAgent.indexOf("Android 2.") != -1 || userAgent.indexOf("Android 3.") != -1)) {
        super.inspect(r);
        AsyncIOWriter writer = response.getAsyncIOWriter();
        if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) {
            AtmosphereInterceptorWriter.class.cast(writer).interceptor(new AsyncIOInterceptorAdapter() {

                @Override
                public void prePayload(AtmosphereResponse response, byte[] data, int offset, int length) {
                    response.write(padding, true);
                }

                @Override
                public void postPayload(AtmosphereResponse response, byte[] data, int offset, int length) {
                    response.write(padding, true);
                }
            });
        } else {
            logger.warn("Unable to apply {}. Your AsyncIOWriter must implement {}", getClass().getName(), AtmosphereInterceptorWriter.class.getName());
        }
    }
    return Action.CONTINUE;
}
Also used : AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AsyncIOWriter(org.atmosphere.runtime.AsyncIOWriter) AtmosphereInterceptorWriter(org.atmosphere.runtime.AtmosphereInterceptorWriter) AtmosphereResourceImpl(org.atmosphere.runtime.AtmosphereResourceImpl) AsyncIOInterceptorAdapter(org.atmosphere.runtime.AsyncIOInterceptorAdapter)

Example 12 with AsyncIOWriter

use of org.atmosphere.runtime.AsyncIOWriter in project atmosphere by Atmosphere.

the class TrackMessageSizeInterceptor method inspect.

@Override
public Action inspect(final AtmosphereResource r) {
    if (AtmosphereResource.TRANSPORT.UNDEFINED == r.transport() || Utils.webSocketMessage(r))
        return Action.CONTINUE;
    final AtmosphereResponse response = r.getResponse();
    super.inspect(r);
    AsyncIOWriter writer = response.getAsyncIOWriter();
    if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) {
        AtmosphereInterceptorWriter.class.cast(writer).interceptor(interceptor);
    } else {
        logger.warn("Unable to apply {}. Your AsyncIOWriter must implement {}", getClass().getName(), AtmosphereInterceptorWriter.class.getName());
    }
    return Action.CONTINUE;
}
Also used : AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AsyncIOWriter(org.atmosphere.runtime.AsyncIOWriter) AtmosphereInterceptorWriter(org.atmosphere.runtime.AtmosphereInterceptorWriter)

Aggregations

AsyncIOWriter (org.atmosphere.runtime.AsyncIOWriter)12 AtmosphereResponse (org.atmosphere.runtime.AtmosphereResponse)11 AtmosphereInterceptorWriter (org.atmosphere.runtime.AtmosphereInterceptorWriter)9 IOException (java.io.IOException)6 AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)6 AsyncIOInterceptorAdapter (org.atmosphere.runtime.AsyncIOInterceptorAdapter)5 AtmosphereResourceEvent (org.atmosphere.runtime.AtmosphereResourceEvent)2 AtmosphereResourceEventListenerAdapter (org.atmosphere.runtime.AtmosphereResourceEventListenerAdapter)2 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ServletException (javax.servlet.ServletException)1 Action (org.atmosphere.runtime.Action)1 AsyncIOWriterAdapter (org.atmosphere.runtime.AsyncIOWriterAdapter)1 AtmosphereRequestImpl (org.atmosphere.runtime.AtmosphereRequestImpl)1 HeartbeatAtmosphereResourceEvent (org.atmosphere.runtime.HeartbeatAtmosphereResourceEvent)1 ByteArrayAsyncWriter (org.atmosphere.util.ByteArrayAsyncWriter)1 Test (org.testng.annotations.Test)1