Esempio n. 1
0
 @Bean(initMethod = "start", destroyMethod = "stop")
 public BayeuxServer bayeuxServer() {
   BayeuxServerImpl bayeuxServer = new BayeuxServerImpl();
   bayeuxServer.setOption(ServletContext.class.getName(), servletContext);
   bayeuxServer.setOption("ws.cometdURLMapping", "/cometd/*");
   servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer);
   return bayeuxServer;
 }
Esempio n. 2
0
  @Test
  public void testHandshakeOverHTTPReportsHTTPFailure() throws Exception {
    startServer(null);
    // No transports on server, to make the client fail
    ((BayeuxServerImpl) bayeux).setAllowedTransports();

    BayeuxClient client = newBayeuxClient();
    final CountDownLatch latch = new CountDownLatch(1);
    client
        .getChannel(Channel.META_HANDSHAKE)
        .addListener(
            new ClientSessionChannel.MessageListener() {
              public void onMessage(ClientSessionChannel channel, Message message) {
                // Verify the failure object is there
                @SuppressWarnings("unchecked")
                Map<String, Object> failure = (Map<String, Object>) message.get("failure");
                Assert.assertNotNull(failure);
                // Verify that the transport is there
                Assert.assertEquals("long-polling", failure.get(Message.CONNECTION_TYPE_FIELD));
                // Verify the original message is there
                Assert.assertNotNull(failure.get("message"));
                // Verify the HTTP status code is there
                Assert.assertEquals(400, failure.get("httpCode"));
                // Verify the exception string is there
                Assert.assertNotNull(failure.get("exception"));
                latch.countDown();
              }
            });
    client.handshake();

    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));

    disconnectBayeuxClient(client);
  }
Esempio n. 3
0
 @Override
 public boolean sendMeta(ServerSession to, Mutable message) {
   if (Channel.META_HANDSHAKE.equals(message.getChannel())
       || Channel.META_CONNECT.equals(message.getChannel())
       || Channel.META_DISCONNECT.equals(message.getChannel())) {
     AbstractHttpTransport transport = (AbstractHttpTransport) bayeux.getCurrentTransport();
     HttpServletRequest request = transport.getCurrentRequest();
     if (request != null) {
       String uri = request.getRequestURI();
       message.getExt(true).put("uri", uri);
     }
   }
   return true;
 }