Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.AtmosphereRequest$IS


        DefaultWebSocket dws = DefaultWebSocket.class.cast(w);
        wMap.put(w,webSocket);

        try {

            AtmosphereRequest r = AtmosphereRequest.wrap(dws.getRequest());
            AtmosphereResponse response = AtmosphereResponse.newInstance(config, r, webSocket);
            config.framework().configureRequestResponse(r, response);
            try {
                // Stupid Stupid Stupid
               if (r.getPathInfo() == null) {
                    String uri = r.getRequestURI();
                    String pathInfo = uri.substring(uri.indexOf(r.getServletPath()) + r.getServletPath().length());
                    r.pathInfo(pathInfo);
                }
            } catch (Exception e) {
                // Whatever exception occurs skip it
                logger.trace("", e);
            }
View Full Code Here


    @Override
    public Action inspect(AtmosphereResource r) {

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

        final AtmosphereRequest request = r.getRequest();
        final AtmosphereResponse response = r.getResponse();
        // Shield from Broken server
        String uri = request.getRequestURI() == null ? "" : request.getRequestURI();

        if (r.transport().equals(AtmosphereResource.TRANSPORT.JSONP) || uri.indexOf("jsonp") != -1) {
            super.inspect(r);

            if (uri.indexOf("jsonp") != -1) {
                startChunk = "(\"";
                endChunk = "\");\r\n\r\n";
            }

            AsyncIOWriter writer = response.getAsyncIOWriter();
            if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) {
                AtmosphereInterceptorWriter.class.cast(writer).interceptor(new AsyncIOInterceptorAdapter() {

                    String callbackName() {
                        String callback =  request.getParameter(HeaderConfig.JSONP_CALLBACK_NAME);
                        if (callback == null) {
                            // Look for extension
                            String jsonp = (String) config.properties().get(HeaderConfig.JSONP_CALLBACK_NAME);
                            if (jsonp != null) {
                                callback = request.getParameter(jsonp);
                            }
                        }
                        return callback;
                    }
View Full Code Here

        whitespace.append("\n");
        return whitespace.toString();
    }

    private void writePadding(AtmosphereResponse response) {
        AtmosphereRequest request = response.request();
        if (request != null && request.getAttribute("paddingWritten") != null) return;

        if (response.resource() != null && response.resource().transport().equals(TRANSPORT.STREAMING)) {
            request.setAttribute(FrameworkConfig.TRANSPORT_IN_USE, HeaderConfig.STREAMING_TRANSPORT);
            response.setContentType("text/plain");
        }

        response.write(padding, true);
        try {
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 uuid = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID);
        boolean padding = r.transport().equals(TRANSPORT.STREAMING) || r.transport().equals(TRANSPORT.LONG_POLLING);
        if (uuid != null
                && !uuid.equals("0")
                && r.transport().equals(TRANSPORT.WEBSOCKET)
                && request.getAttribute(INJECTED_ATMOSPHERE_RESOURCE) != null) {
            padding = true;
        }

        if (padding) {
            r.addEventListener(new ForcePreSuspend(response));

            super.inspect(r);

            AsyncIOWriter writer = response.getAsyncIOWriter();
            if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) {
                AtmosphereInterceptorWriter.class.cast(writer).interceptor(new AsyncIOInterceptorAdapter() {
                    private void padding() {
                        if (!r.isSuspended()) {
                            writePadding(response);
                            request.setAttribute("paddingWritten", "true");
                        }
                    }

                    @Override
                    public void prePayload(AtmosphereResponse response, byte[] data, int offset, int length) {
View Full Code Here

    @Override
    public Action inspect(final AtmosphereResource r) {

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

        AtmosphereRequest request = AtmosphereResourceImpl.class.cast(r).getRequest(false);
        String uuid = r.uuid();
        if (closeMessage(request)) {
            AtmosphereResource ss = config.resourcesFactory().find(uuid);

            if (ss == null) {
View Full Code Here

    @Override
    public Action inspect(final AtmosphereResource r) {

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

        final AtmosphereRequest request = AtmosphereResourceImpl.class.cast(r).getRequest(false);
        boolean connecting = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID) != null && request.getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID).equals("0");

        if (!connecting && !Utils.pollableTransport(r.transport())) {
            if (!trackedUUID.add(r.uuid())) {
                logger.trace("Blocking {} from suspend", r.uuid());
                AtmosphereResourceImpl.class.cast(r).disableSuspendEvent(true);
View Full Code Here

        this.webSocketProcessor = webSocketProcessor;
    }

    private AtmosphereRequest cloneRequest(final HttpServletRequest request) {
        try {
            AtmosphereRequest r = AtmosphereRequest.wrap(request);
            return AtmosphereRequest.cloneRequest(r, false, false, false);
        } catch (Exception ex) {
            logger.error("", ex);
            throw new RuntimeException("Invalid WebSocket Request");
        }
View Full Code Here

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

        if (!enableAccessControl) return Action.CONTINUE;

        AtmosphereRequest req = r.getRequest();
        AtmosphereResponse res = r.getResponse();

        if (req.getHeader("Origin") != null && res.getHeader("Access-Control-Allow-Origin") == null) {
            res.addHeader("Access-Control-Allow-Origin", req.getHeader("Origin"));
            res.addHeader("Access-Control-Expose-Headers", EXPOSE_HEADERS);
            res.setHeader("Access-Control-Allow-Credentials", "true");
        }

        if ("OPTIONS".equals(req.getMethod())) {
            res.setHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST");
            res.setHeader("Access-Control-Allow-Headers",
                    "Origin, Content-Type, AuthToken, X-Atmosphere-Framework, "
                            + EXPOSE_HEADERS
                            + ", X-Atmosphere-Transport, X-Atmosphere-TrackMessageSize, X-atmo-protocol");
View Full Code Here

        }
    }

    protected void idleResources() {
        for (AtmosphereResource r : config.resourcesFactory().findAll()) {
            AtmosphereRequest req = AtmosphereResourceImpl.class.cast(r).getRequest(false);
            try {
                if (req.getAttribute(MAX_INACTIVE) == null) {
                    logger.error("Invalid state {}", r);
                    config.getBroadcasterFactory().removeAllAtmosphereResource(r);
                    config.resourcesFactory().unRegisterUuidForFindCandidate(r);
                    continue;
                }

                long l = (Long) req.getAttribute(MAX_INACTIVE);
                if (l > 0 && System.currentTimeMillis() - l > maxInactiveTime ) {
                    try {
                        req.setAttribute(MAX_INACTIVE, (long) -1);

                        logger.debug("IdleResourceInterceptor disconnecting {}", r);
                        Future<?> f = (Future<?>) req.getAttribute(HeartbeatInterceptor.HEARTBEAT_FUTURE);
                        if (f != null) f.cancel(false);
                        req.removeAttribute(HeartbeatInterceptor.HEARTBEAT_FUTURE);

                        WebSocket webSocket = AtmosphereResourceImpl.class.cast(r).webSocket();
                        if (webSocket != null) {
                            webSocket.close();
                        } else {
View Full Code Here

        }
    }

    public static Object readEntirely(AtmosphereResource r) {
        AtmosphereRequest request = r.getRequest();
        return isBodyBinary(request) ? readEntirelyAsByte(r) : readEntirelyAsString(r).toString();
    }
View Full Code Here

TOP

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

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.