@Test
  public void restartWithKeepAlive() throws Exception {
    AbstractEmbeddedServletContainerFactory factory = getFactory();
    this.container = factory.getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory =
        new HttpComponentsAsyncClientHttpRequestFactory();
    ListenableFuture<ClientHttpResponse> response1 =
        clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));

    this.container.stop();
    this.container = factory.getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();

    ListenableFuture<ClientHttpResponse> response2 =
        clientHttpRequestFactory
            .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET)
            .executeAsync();
    assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));
  }
Ejemplo n.º 2
0
  private static void start() throws Exception {
    List<Transport> transports =
        Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient()));
    WebSocketStompClient stompClient = new WebSocketStompClient(new SockJsClient(transports));

    stompClient.setMessageConverter(new MappingJackson2MessageConverter());

    StompSessionHandlerAdapter handler =
        new StompSessionHandlerAdapter() {
          @Override
          public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
            LOG.info("Connected to {}", session);
          }

          @Override
          public void handleException(
              StompSession session,
              StompCommand command,
              StompHeaders headers,
              byte[] payload,
              Throwable exception) {
            throw new RuntimeException(exception);
          }
        };

    ListenableFuture<StompSession> lss = stompClient.connect(URL, handler);

    StompSession ss = lss.get();

    ss.subscribe("/user/queue/greetings", new StringHandler());
    ss.subscribe("/topic/latest/USD/EUR", new RatesHandler());
    ss.subscribe("/topic/latest/BRE/USD", new RatesHandler());

    ss.send("/app/hello", "dede");

    LOG.info("hello done");
  }