Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.AtmosphereFramework


    private final AsynchronousProcessor asynchronousProcessor;

    public BridgeRuntime(final Config config) {
        super(config.path());
        this.config = config;
        framework = new AtmosphereFramework();

        if (config.broadcaster() != null) {
            framework.setDefaultBroadcasterClassName(config.broadcaster().getName());
        }
View Full Code Here


    AppProperties appProperties;
   
    @BeforeAction
    public void beforeAction(RequestContext ctx) {
       
        AtmosphereFramework framework = (AtmosphereFramework) appProperties
                .getProperty(ATMOSPHERE_FRAMEWORK);
        HttpServletRequest req = ctx.getRequest();
        HttpServletResponse res = ctx.getResponse();
       
        try {
           
            framework.doCometSupport(
                    AtmosphereRequest.wrap(req), AtmosphereResponse.wrap(res));
           
        } catch (Exception e) {
            logger.error("error invoking Atmosphere framework", e);
        }
View Full Code Here

        logger.info("initializing Atmosphere framework...");
       
        /* ensure the Atmosphere framework uses the Mojave Guice injector */
        GuiceInjector.INJECTOR = resources.getInjector();
       
        AtmosphereFramework framework = new AtmosphereFramework(false, true);
       
        //TODO does the "/" mapping have any significance in this case?
        framework.addAtmosphereHandler("/", new MojaveAtmosphereHandler());
       
        //TODO call init() after configure class using setters or
        // call framework.init(servletConfig), and add support for passing along ServletConfig
        framework.init();
       
        collector.addProperty(AtmosphereInterceptor.ATMOSPHERE_FRAMEWORK, framework);
    }
View Full Code Here

    public AtmosphereGuiceServlet() {
        this(false, true);
    }

    public AtmosphereGuiceServlet(boolean isFilter, boolean autoDetectHandlers) {
        framework = new AtmosphereFramework(isFilter, autoDetectHandlers) {
            @Override
            protected void configureDetectedFramework(ReflectorServletProcessor rsp, boolean isJersey) {
                Injector injector = (Injector) framework().getAtmosphereConfig().getServletContext().getAttribute(Injector.class.getName());
                GuiceContainer guiceServlet = injector.getInstance(GuiceContainer.class);
                rsp.setServlet(guiceServlet);
View Full Code Here

     * Create an Atmosphere Servlet.
     *
     * @param isFilter true if this instance is used as an {@link org.atmosphere.cpr.AtmosphereFilter}
     */
    public AtmosphereWebLogicServlet(boolean isFilter, boolean autoDetectHandlers) {
        framework = new AtmosphereFramework(isFilter, autoDetectHandlers);
    }
View Full Code Here

            throws ServiceException {

        final ServletConfig vaadinServletConfig = service.getServlet()
                .getServletConfig();

        atmosphere = new AtmosphereFramework() {
            @Override
            protected void analytics() {
                // Overridden to disable version number check
            }
View Full Code Here

  private TesterBroadcaster createBroadcaster()
  {
    TesterBroadcaster broadcaster = new TesterBroadcaster();

    AtmosphereFramework framework = new AtmosphereFramework();
    AtmosphereConfig config = new AtmosphereConfig(framework);

    TesterBroadcasterFactory broadcasterFactory = new TesterBroadcasterFactory(config, broadcaster);
    framework.setBroadcasterFactory(broadcasterFactory);

    broadcaster.initialize("wicket-atmosphere-tester", config);

    return broadcaster;
  }
View Full Code Here

  private static TesterBroadcaster createBroadcaster()
  {
    TesterBroadcaster broadcaster = new TesterBroadcaster();

    AtmosphereFramework framework = new AtmosphereFramework();
    AtmosphereConfig config = new AtmosphereConfig(framework);

    TesterBroadcasterFactory broadcasterFactory = new TesterBroadcasterFactory(config, broadcaster);
    framework.setBroadcasterFactory(broadcasterFactory);

    broadcaster.initialize("wicket-atmosphere-tester", config);

    return broadcaster;
  }
View Full Code Here

        MetaBroadcaster.getDefault().cache(new MetaBroadcaster.ThirtySecondsCache(MetaBroadcaster.getDefault(),
                framework.getAtmosphereConfig()));
    }

    protected AtmosphereFramework newAtmosphereFramework() {
        return new AtmosphereFramework(isFilter, autoDetectHandlers);
    }
View Full Code Here

                schedule(r, identity);

                return Action.SUSPEND;
            }

            AtmosphereFramework framework = r.getAtmosphereConfig().framework();
            StringBuilder d = new StringBuilder();
            try {
                InputStreamReader isr = new InputStreamReader(request.getInputStream());
                BufferedReader bufReader = new BufferedReader(isr);
                char[] charBuffer = new char[8192];

                for (int readCount = bufReader.read(charBuffer); readCount > -1; readCount = bufReader.read(charBuffer)) {
                    d.append(charBuffer, 0, readCount);
                }

                String data = d.toString();

                if (data.length() == 0) {
                    return Action.CANCELLED;
                }

                String message = data.substring(0, 20).replaceAll(" ", "");
                logger.debug(data);
                if (message.startsWith("{\"handshake\"")) {
                    // This will fail if the message is not well formed.
                    HandshakeMessage handshakeMessage = mapper.readValue(data, HandshakeMessage.class);

                    // If we missed the CloseReason for whatever reason (IE is a good candidate), make sure we swap the previous session anyway.
                    String identity = (String) getContextValue(request, IDENTITY);
                    if (identity == null) {
                        identity = UUID.randomUUID().toString();
                    } else {
                        logger.debug("Client disconnected {}, cleaning session {}", identity);
                        try {
                            Enumeration<String> e = request.getSession().getAttributeNames();
                            while (e.hasMoreElements()) {
                                request.getSession().removeAttribute(e.nextElement());
                            }
                        } catch (Exception ex) {
                            logger.warn("", ex);
                        }
                    }
                    addContextValue(request, IDENTITY, identity);

                    StatusMessage statusMessage = new StatusMessage.Builder().status(new StatusMessage.Status(200, "OK"))
                            .identity(identity).build();
                    response.setContentType("application/json");
                    response.getOutputStream().write(mapper.writeValueAsBytes(statusMessage));

                    if (r.transport() == AtmosphereResource.TRANSPORT.WEBSOCKET) {
                        schedule(r, identity);
                    }

                    if (!delegateHandshake) {
                        return Action.CANCELLED;
                    }
                } else if (message.startsWith("{\"close\"")) {
                    CloseMessage c = mapper.readValue(data, CloseMessage.class);

                    logger.debug("Client disconnected {} with reason {}", c.getClose().getIdentity(), c.getClose().getReason());
                    try {
                        request.getSession().invalidate();
                    } catch (Exception ex) {
                        logger.warn("", ex);
                    }
                    return Action.CANCELLED;
                } else {
                    Message swaggerSocketMessage = mapper.readValue(data, Message.class);
                    swaggerSocketMessage.transactionID(UUID.randomUUID().toString());

                    String identity = (String) getContextValue(request, IDENTITY);

                    if (!swaggerSocketMessage.getIdentity().equals(identity)) {
                        StatusMessage statusMessage = new StatusMessage.Builder().status(new StatusMessage.Status(503, "Not Allowed"))
                                .identity(swaggerSocketMessage.getIdentity()).build();
                        response.getOutputStream().write(mapper.writeValueAsBytes(statusMessage));
                        return Action.CANCELLED;
                    }

                    transactionIdentity.set(swaggerSocketMessage.transactionID());

                    List<Request> requests = swaggerSocketMessage.getRequests();
                    addContextValue(request, swaggerSocketMessage.transactionID() + RESPONSE_COUNTER, new AtomicInteger(requests.size()));

                    AtmosphereRequest ar;
                    for (Request req : requests) {
                        ar = toAtmosphereRequest(request, req);
                        try {
                            ar.setAttribute(SWAGGER_SOCKET_DISPATCHED, "true");

                            // This is a new request, we must clean the Websocket AtmosphereResource.
                            request.removeAttribute(INJECTED_ATMOSPHERE_RESOURCE);
                            response.request(ar);
                            attachWriter(r);
                            ssRequest.set(req);
                            request.setAttribute("swaggerSocketRequest", req);

                            Action action = framework.doCometSupport(ar, response);
                            if (action.type() == Action.TYPE.SUSPEND) {
                                ar.destroyable(false);
                                response.destroyable(false);
                            }
                        } catch (ServletException e) {
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.AtmosphereFramework

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.