Package org.springframework.web.socket.server.support

Examples of org.springframework.web.socket.server.support.WebSocketHttpRequestHandler


      assertTrue(hm instanceof SimpleUrlHandlerMapping);
      SimpleUrlHandlerMapping shm = (SimpleUrlHandlerMapping) hm;

      if (shm.getUrlMap().keySet().contains("/foo")) {
        assertThat(shm.getUrlMap().keySet(), contains("/foo", "/bar"));
        WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/foo");
        assertNotNull(handler);
        unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
        HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
        assertNotNull(handshakeHandler);
        assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
        assertTrue(handler.getHandshakeInterceptors().isEmpty());
      }
      else {
        assertThat(shm.getUrlMap().keySet(), contains("/test"));
        WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/test");
        assertNotNull(handler);
        unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
        HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
        assertNotNull(handshakeHandler);
        assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
        assertTrue(handler.getHandshakeInterceptors().isEmpty());
      }
    }
  }
View Full Code Here


    assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);

    SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
    assertEquals(2, urlHandlerMapping.getOrder());

    WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/foo");
    assertNotNull(handler);
    unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
    HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
    assertNotNull(handshakeHandler);
    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    List<HandshakeInterceptor> interceptors = handler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));

    handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
    assertNotNull(handler);
    unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
    handshakeHandler = handler.getHandshakeHandler();
    assertNotNull(handshakeHandler);
    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    interceptors = handler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
  }
View Full Code Here

    HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo");
    assertNotNull(httpRequestHandler);
    assertThat(httpRequestHandler, Matchers.instanceOf(WebSocketHttpRequestHandler.class));

    WebSocketHttpRequestHandler wsHttpRequestHandler = (WebSocketHttpRequestHandler) httpRequestHandler;
    HandshakeHandler handshakeHandler = wsHttpRequestHandler.getHandshakeHandler();
    assertNotNull(handshakeHandler);
    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    List<HandshakeInterceptor> interceptors = wsHttpRequestHandler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));

    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

    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

    registration.setAllowedOrigins("http://mydomain.com");

    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler)mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertEquals(1, requestHandler.getHandshakeInterceptors().size());
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(0).getClass());
  }
View Full Code Here

        mappings.add(handler, pattern);
      }
    }
    else {
      for (String path : this.paths) {
        WebSocketHttpRequestHandler handler;
        if (this.handshakeHandler != null) {
          handler = new WebSocketHttpRequestHandler(this.webSocketHandler, this.handshakeHandler);
        }
        else {
          handler = new WebSocketHttpRequestHandler(this.webSocketHandler);
        }
        HandshakeInterceptor[] interceptors = getInterceptors();
        if (interceptors.length > 0) {
          handler.setHandshakeInterceptors(Arrays.asList(interceptors));
        }
        mappings.add(handler, path);
      }
    }
    return mappings;
View Full Code Here

    assertEquals(1, mappings.size());

    Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
    assertEquals(Arrays.asList("/foo"), entry.getValue());

    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
    assertEquals(Arrays.asList(interceptor), requestHandler.getHandshakeInterceptors());
  }
View Full Code Here

    assertEquals(1, mappings.size());

    Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
    assertEquals(Arrays.asList("/foo"), entry.getValue());

    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
    assertEquals(2, requestHandler.getHandshakeInterceptors().size());
    assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
  }
View Full Code Here

  @Override
  protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings,
      WebSocketHandler wsHandler, HandshakeHandler handshakeHandler,
      HandshakeInterceptor[] interceptors, String path) {

    WebSocketHttpRequestHandler httpHandler = new WebSocketHttpRequestHandler(wsHandler, handshakeHandler);
    if (!ObjectUtils.isEmpty(interceptors)) {
      httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors));
    }
    mappings.add(httpHandler, path);
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.server.support.WebSocketHttpRequestHandler

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.