protected <T> DeferredResult<ResponseEntity<T>> objectResult(ListenableFuture<T> futureResult) {
   DeferredResult<ResponseEntity<T>> response =
       new DeferredResult<>(
           WEB_SERVICE_TIMEOUT, errorResult("Request timeout", HttpStatus.REQUEST_TIMEOUT));
   futureResult.addCallback(new SimpleCallback<>(response));
   return response;
 }
 protected <T> DeferredResult<ResponseEntity<Map<String, T>>> mapResult(
     String key, ListenableFuture<T> futureResult) {
   DeferredResult<ResponseEntity<Map<String, T>>> response =
       new DeferredResult<>(
           WEB_SERVICE_TIMEOUT, errorResult("Request timeout", HttpStatus.REQUEST_TIMEOUT));
   futureResult.addCallback(new MapCallback<>(key, response));
   return response;
 }
  @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));
  }
  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");
  }