Package org.springframework.web.socket

Examples of org.springframework.web.socket.WebSocketHandler


  }


  private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception {

    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);

    transportHandler.initialize(new StubSockJsServiceConfig());
    transportHandler.handleRequest(this.request, this.response, wsHandler, session);
View Full Code Here


  private void handleRequestAndExpectFailure() throws Exception {

    resetResponse();

    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);

    new XhrReceivingTransportHandler().handleRequest(this.request, this.response, wsHandler, session);

    assertEquals(500, this.servletResponse.getStatus());
View Full Code Here

    assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
  }

  @Test
  public void getSubProtocolsNone() throws Exception {
    WebSocketHandler handler = new TextWebSocketHandler();
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
View Full Code Here

   * checking whether it is an instance of {@link SubProtocolCapable}.
   * @param handler the handler to check
   * @return a list of supported protocols, or an empty list if none available
   */
  protected final List<String> determineHandlerSupportedProtocols(WebSocketHandler handler) {
    WebSocketHandler handlerToCheck = WebSocketHandlerDecorator.unwrap(handler);
    List<String> subProtocols = null;
    if (handlerToCheck instanceof SubProtocolCapable) {
      subProtocols = ((SubProtocolCapable) handlerToCheck).getSubProtocols();
    }
    return (subProtocols != null ? subProtocols : Collections.<String>emptyList());
View Full Code Here

    WebSocketSession session = new TestWebSocketSession("id");
    wsHttpRequestHandler.getWebSocketHandler().afterConnectionEstablished(session);
    assertEquals(true, session.getAttributes().get("decorated"));

    WebSocketHandler wsHandler = unwrapWebSocketHandler(wsHttpRequestHandler.getWebSocketHandler());
    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));

    SubProtocolWebSocketHandler subProtocolWsHandler = (SubProtocolWebSocketHandler) wsHandler;
    assertEquals(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"), subProtocolWsHandler.getSubProtocols());
View Full Code Here

    HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
    assertNotNull(httpRequestHandler);
    assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class));
    SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
    WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
    assertNotNull(sockJsHttpRequestHandler.getSockJsService());

    UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
View Full Code Here

      this.factories = factories;
    }

    @Override
    public WebSocketHandler getObject() throws Exception {
      WebSocketHandler result = this.handler;
      for (WebSocketHandlerDecoratorFactory factory : this.factories) {
        result = factory.decorate(result);
      }
      return result;
    }
View Full Code Here

    requestHeaders.set("foo", "bar");

    TestXhrTransport transport = new TestXhrTransport();
    transport.setRequestHeaders(requestHeaders);

    WebSocketHandler handler = mock(WebSocketHandler.class);
    transport.connect(request, handler);

    ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
    verify(request).getSockJsUrlInfo();
    verify(request).addTimeoutTask(captor.capture());
View Full Code Here

  }

  @Test
  public void webSocketHandlerDecorator() throws Exception {
    ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
    WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
    assertNotNull(handler);

    SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
    WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
    handler = httpHandler.getWebSocketHandler();

    WebSocketSession session = new TestWebSocketSession("id");
    handler.afterConnectionEstablished(session);
    assertEquals(true, session.getAttributes().get("decorated"));
  }
View Full Code Here

    this.registration = new TestWebSocketHandlerRegistration(taskScheduler);
  }

  @Test
  public void minimal() {
    WebSocketHandler handler = new TextWebSocketHandler();
    this.registration.addHandler(handler, "/foo", "/bar");

    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(2, mappings.size());
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.WebSocketHandler

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.