Package org.cometd.server.transport

Examples of org.cometd.server.transport.JSONTransport


                    break;
                case "jettyws":
                    bayeuxServer.addTransport(new LoadJettyWebSocketTransport(bayeuxServer, websocketThreadPool));
                    break;
                case "http":
                    bayeuxServer.addTransport(new JSONTransport(bayeuxServer));
                    break;
                case "asynchttp":
                    bayeuxServer.addTransport(new AsyncJSONTransport(bayeuxServer));
                    break;
                default:
View Full Code Here


            loader.loadClass("javax.servlet.ReadListener");
            return new AsyncJSONTransport(this);
        }
        catch (Exception x)
        {
            return new JSONTransport(this);
        }
    }
View Full Code Here

    }

    @Test
    public void testBadJSON() throws Exception
    {
        JSONTransport transport = new JSONTransport(bayeux)
        {
            @Override
            protected void handleJSONParseException(HttpServletRequest request, HttpServletResponse response, String json, Throwable exception) throws IOException
            {
                // Suppress logging during tests
                if (!response.isCommitted())
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            }
        };
        transport.init();
        bayeux.setTransports(transport);

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
View Full Code Here

    public void testConnectHandlerThenDisconnect() throws Exception
    {
        final CountDownLatch connectLatch = new CountDownLatch(2);
        final CountDownLatch disconnectLatch = new CountDownLatch(1);
        final CountDownLatch suspendLatch = new CountDownLatch(1);
        JSONTransport transport = new JSONTransport(bayeux)
        {
            @Override
            protected ServerMessage.Mutable bayeuxServerHandle(ServerSessionImpl session, ServerMessage.Mutable message)
            {
                ServerMessage.Mutable reply = super.bayeuxServerHandle(session, message);
                if (Channel.META_CONNECT.equals(message.getChannel()))
                {
                    connectLatch.countDown();
                    if (connectLatch.getCount() == 0)
                        await(disconnectLatch);
                }
                return reply;
            }

            @Override
            protected void metaConnectSuspended(HttpServletRequest request, HttpServletResponse response, AsyncContext asyncContext, ServerSession session)
            {
                suspendLatch.countDown();
            }
        };
        transport.init();
        bayeux.setTransports(transport);

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
View Full Code Here

    @Test
    public void testCreationWithTransports() throws Exception
    {
        BayeuxServerImpl bayeuxServer = new BayeuxServerImpl();

        JSONTransport jsonTransport = new JSONTransport(bayeuxServer);
        long timeout = 13003L;
        jsonTransport.setTimeout(timeout);
        bayeuxServer.setTransports(jsonTransport);
        bayeuxServer.setAllowedTransports(JSONTransport.NAME);

        bayeuxServer.start();
View Full Code Here

        Map<String, String> options = new HashMap<>();
        options.put(AbstractServerTransport.MAX_INTERVAL_OPTION, String.valueOf(maxInterval));
        startServer(options);

        final String channelName = "/test";
        JSONTransport transport = new JSONTransport(bayeux)
        {
            @Override
            protected void writeMessage(HttpServletResponse response, ServletOutputStream output, ServerSessionImpl session, ServerMessage message) throws IOException
            {
                try
                {
                    if (channelName.equals(message.getChannel()))
                    {
                        session.startIntervalTimeout(0);
                        TimeUnit.MILLISECONDS.sleep(2 * maxInterval);
                    }
                    super.writeMessage(response, output, session, message);
                }
                catch (InterruptedException x)
                {
                    throw new InterruptedIOException();
                }
            }
        };
        transport.init();
        bayeux.setTransports(transport);

        final CountDownLatch sweeperLatch = new CountDownLatch(1);
        bayeux.addListener(new BayeuxServer.SessionListener()
        {
View Full Code Here

    {
        startServer(null);

        final CountDownLatch sendLatch = new CountDownLatch(1);
        final CountDownLatch closeLatch = new CountDownLatch(1);
        final JSONTransport transport = new JSONTransport(bayeux)
        {
            @Override
            protected void writeMessage(HttpServletResponse response, ServletOutputStream output, ServerSessionImpl session, ServerMessage message) throws IOException
            {
                if (!message.isMeta() && !message.isPublishReply())
                {
                    sendLatch.countDown();
                    await(closeLatch);
                    // Simulate that an exception is being thrown while writing
                    throw new EofException("test_exception");
                }
                super.writeMessage(response, output, session, message);
            }
        };
        transport.init();
        bayeux.setTransports(transport);
        long maxInterval = 5000L;
        transport.setMaxInterval(maxInterval);

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
                "\"minimumVersion\": \"1.0\"," +
View Full Code Here

    {
        startServer(null);

        final long timeout = 2000;
        final long sleep = 500;
        JSONTransport transport = new JSONTransport(bayeux)
        {
            @Override
            protected HttpScheduler newHttpScheduler(HttpServletRequest request, HttpServletResponse response, AsyncContext asyncContext, ServerSessionImpl session, ServerMessage.Mutable reply, String browserId, long timeout)
            {
                return new DispatchingLongPollScheduler(request, response, asyncContext, session, reply, browserId, timeout)
                {
                    private final AtomicInteger decrements = new AtomicInteger();

                    @Override
                    public void onComplete(final AsyncEvent asyncEvent) throws IOException
                    {
                        if (decrements.incrementAndGet() == 1)
                        {
                            // Simulate that onComplete() is delayed without blocking
                            // this thread, to cause a race condition
                            new Thread()
                            {
                                @Override
                                public void run()
                                {
                                    try
                                    {
                                        Thread.sleep(sleep);
                                        superOnComplete(asyncEvent);
                                    }
                                    catch (Exception x)
                                    {
                                        x.printStackTrace();
                                    }
                                }
                            }.start();
                        }
                        else
                        {
                            superOnComplete(asyncEvent);
                        }
                    }

                    private void superOnComplete(AsyncEvent asyncEvent) throws IOException
                    {
                        super.onComplete(asyncEvent);
                    }
                };
            }
        };
        transport.setOption(AbstractServerTransport.TIMEOUT_OPTION, timeout);
        transport.init();
        bayeux.setTransports(transport);

        Request handshake = newBayeuxRequest("[{" +
                "\"channel\": \"/meta/handshake\"," +
                "\"version\": \"1.0\"," +
View Full Code Here

    @Bean(initMethod = "start", destroyMethod = "stop")
    public BayeuxServer bayeuxServer()
    {
        BayeuxServerImpl bean = new BayeuxServerImpl();
        bean.setTransports(new WebSocketTransport(bean), new JSONTransport(bean), new JSONPTransport(bean));
        servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bean);
        bean.setOption(ServletContext.class.getName(), servletContext);
        bean.setOption("ws.cometdURLMapping", "/cometd/*");
        return bean;
    }
View Full Code Here

TOP

Related Classes of org.cometd.server.transport.JSONTransport

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.