Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.AtmosphereRequest$LazyComputation


        public void get(AtmosphereResource resource) {
            r.set(resource);
            resource.addEventListener(new OnSuspend() {
                @Override
                public void onSuspend(AtmosphereResourceEvent event) {
                    AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/k").method("POST").body("message").build();

                    try {
                        event.getResource().getAtmosphereConfig().framework().doCometSupport(request, AtmosphereResponse.newInstance());
                    } catch (IOException e) {
                        e.printStackTrace();
View Full Code Here


        public void get(AtmosphereResource resource) {
            r.set(resource);
            resource.addEventListener(new OnSuspend() {
                @Override
                public void onSuspend(AtmosphereResourceEvent event) {
                    AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/readerInjection").method("POST").body("message").build();

                    try {
                        event.getResource().getAtmosphereConfig().framework().doCometSupport(request, AtmosphereResponse.newInstance());
                    } catch (IOException e) {
                        e.printStackTrace();
View Full Code Here

        public void get(AtmosphereResource resource) {
            r.set(resource);
            resource.addEventListener(new OnSuspend() {
                @Override
                public void onSuspend(AtmosphereResourceEvent event) {
                    AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/inputStreamInjection").method("POST").body("message").build();

                    try {
                        event.getResource().getAtmosphereConfig().framework().doCometSupport(request, AtmosphereResponse.newInstance());
                    } catch (IOException e) {
                        e.printStackTrace();
View Full Code Here

        public void get(AtmosphereResource resource) {
            r.set(resource);
            resource.addEventListener(new OnSuspend() {
                @Override
                public void onSuspend(AtmosphereResourceEvent event) {
                    AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/injectAnnotation").method("POST").body("message").build();

                    try {
                        event.getResource().getAtmosphereConfig().framework().doCometSupport(request, AtmosphereResponse.newInstance());
                    } catch (IOException e) {
                        e.printStackTrace();
View Full Code Here

    }

    @Test
    public void testBroadcasterCache() throws IOException, ServletException {

        AtmosphereRequest request = new AtmosphereRequest.Builder().pathInfo("/cache").method("GET").build();
        framework.doCometSupport(request, AtmosphereResponse.newInstance());
        assertEquals(framework.getBroadcasterFactory().lookup("/*", true).getBroadcasterConfig().getBroadcasterCache().getClass(), UUIDBroadcasterCache.class);

    }
View Full Code Here

    public Action inspect(final AtmosphereResource r) {

        if (Utils.webSocketMessage(r)) return Action.CONTINUE;

        final AtmosphereResponse response = r.getResponse();
        final AtmosphereRequest request = r.getRequest();
        String accept = request.getHeader("Accept") == null ? "text/plain" : request.getHeader("Accept").trim();

        if (r.transport().equals(AtmosphereResource.TRANSPORT.SSE) || contentType.equalsIgnoreCase(accept)) {
            super.inspect(r);

            r.addEventListener(new P(response));
View Full Code Here

    private WebSocket webSocket(InputStream inputStream) throws IOException {
        WebSocket webSocket = webSockets.get(inputStream);
        if (webSocket == null) {
            webSocket = new ArrayBaseWebSocket();
            webSockets.put(inputStream, webSocket);
            AtmosphereRequest request = AtmosphereRequest.newInstance()
                    .header("Connection", "Upgrade")
                    .header("Upgrade", "websocket")
                    .pathInfo(requestURI);
            try {
                processor.open(webSocket, request, AtmosphereResponse.newInstance(framework.getAtmosphereConfig(), request, webSocket));
View Full Code Here

            }

            DefaultWebSocket g2WebSocket = DefaultWebSocket.class.cast(socket);
            try {

                AtmosphereRequest r = AtmosphereRequest.wrap(g2WebSocket.getUpgradeRequest());
                org.atmosphere.websocket.WebSocket webSocket = new Grizzly2WebSocket(g2WebSocket, config);
                g2WebSocket.getUpgradeRequest().setAttribute("grizzly.webSocket", webSocket);
                webSocketProcessor.open(webSocket, r, AtmosphereResponse.newInstance(config, r, webSocket));
            } catch (Exception e) {
                LOGGER.warn("failed to connect to web socket", e);
View Full Code Here

    }

    @Override
    public Action inspect(final AtmosphereResource r) {
        final AtmosphereResourceImpl impl = AtmosphereResourceImpl.class.cast(r);
        final AtmosphereRequest request = impl.getRequest(false);
        final AtmosphereResponse response = impl.getResponse(false);

        // Check heartbeat
        if (clientHeartbeatFrequencyInSeconds > 0) {
            byte[] body = IOUtils.readEntirelyAsByte(r);

            if (Arrays.equals(paddingBytes, body)) {
                // Dispatch an event to notify that a heartbeat has been intercepted
                // TODO: see https://github.com/Atmosphere/atmosphere/issues/1561
                final AtmosphereResourceEvent event = new HeartbeatAtmosphereResourceEvent(AtmosphereResourceImpl.class.cast(r));

                if (AtmosphereResourceHeartbeatEventListener.class.isAssignableFrom(r.getAtmosphereHandler().getClass())) {
                    r.addEventListener(new AtmosphereResourceEventListenerAdapter.OnHeartbeat() {
                        @Override
                        public void onHeartbeat(AtmosphereResourceEvent event) {
                            AtmosphereResourceHeartbeatEventListener.class.cast(r.getAtmosphereHandler()).onHeartbeat(event);
                        }
                    });
                }

                // Fire event
                r.notifyListeners(event);

                return Action.CANCELLED;
            }

            request.body(body);
        }

        if (Utils.webSocketMessage(r)) return Action.CONTINUE;

        final int interval = extractHeartbeatInterval(impl);

        if (interval != 0) {
            if (!Utils.pollableTransport(r.transport())) {
                super.inspect(r);
                final boolean wasSuspended = r.isSuspended();

                // Suspended? Ok can clock now
                // Otherwise, the listener will do the job
                if (wasSuspended) {
                    clock(interval, r, request, response);
                }

                r.addEventListener(new Clock() {
                    @Override
                    public void onSuspend(AtmosphereResourceEvent event) {

                        // We did not clocked when this listener was added because connection was not already suspended
                        if (!wasSuspended) {
                            clock(interval, r, request, response);
                        }
                    }

                    @Override
                    public void onResume(AtmosphereResourceEvent event) {
                        cancelF(request);
                    }

                    @Override
                    public void onDisconnect(AtmosphereResourceEvent event) {
                        cancelF(request);
                    }

                    @Override
                    public void onClose(AtmosphereResourceEvent event) {
                        cancelF(request);
                    }
                });
            } else {
                return Action.CONTINUE;
            }

            final AsyncIOWriter writer = response.getAsyncIOWriter();

            if (!Utils.resumableTransport(r.transport())
                    && AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())
                    && request.getAttribute(INTERCEPTOR_ADDED) == null) {
                AtmosphereInterceptorWriter.class.cast(writer).interceptor(new AsyncIOInterceptorAdapter() {

                    @Override
                    public byte[] transformPayload(AtmosphereResponse response, byte[] responseDraft, byte[] data) throws IOException {
                        cancelF(request);
                        return responseDraft;
                    }

                    @Override
                    public void postPayload(final AtmosphereResponse response, byte[] data, int offset, int length) {
                        logger.trace("Scheduling heartbeat for {}", r.uuid());
                        clock(interval, r, request, response);
                    }
                });
                request.setAttribute(INTERCEPTOR_ADDED, Boolean.TRUE);
            }

        }

        return Action.CONTINUE;
View Full Code Here


    @Override
    public void postInspect(AtmosphereResource r) {
        if (r.getRequest().getMethod().equalsIgnoreCase("POST")) {
            AtmosphereRequest request = r.getRequest();
            Object o = readEntirely(r);
            if (isBodyEmpty(o)) {
                logger.warn("{} received an empty body", request);
                return;
            }
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.AtmosphereRequest$LazyComputation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.