Tabnine Logo
HttpSessionHandshakeInterceptor.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor
constructor

Best Java code snippets using org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor.<init> (Showing top 18 results out of 315)

origin: spring-projects/spring-framework

@Test
public void doNotCauseSessionCreation() throws Exception {
  Map<String, Object> attributes = new HashMap<>();
  WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
  assertNull(this.servletRequest.getSession(false));
}
origin: spring-projects/spring-framework

@Test
public void constructorWithAttributeNames() throws Exception {
  Map<String, Object> attributes = new HashMap<>();
  WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
  this.servletRequest.setSession(new MockHttpSession(null, "123"));
  this.servletRequest.getSession().setAttribute("foo", "bar");
  this.servletRequest.getSession().setAttribute("bar", "baz");
  Set<String> names = Collections.singleton("foo");
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names);
  interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
  assertEquals(2, attributes.size());
  assertEquals("bar", attributes.get("foo"));
  assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
origin: spring-projects/spring-framework

@Test
public void doNotCopyAttributes() throws Exception {
  Map<String, Object> attributes = new HashMap<>();
  WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
  this.servletRequest.setSession(new MockHttpSession(null, "123"));
  this.servletRequest.getSession().setAttribute("foo", "bar");
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  interceptor.setCopyAllAttributes(false);
  interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
  assertEquals(1, attributes.size());
  assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
origin: spring-projects/spring-framework

@Test
public void doNotCopyHttpSessionId() throws Exception {
  Map<String, Object> attributes = new HashMap<>();
  WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
  this.servletRequest.setSession(new MockHttpSession(null, "123"));
  this.servletRequest.getSession().setAttribute("foo", "bar");
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  interceptor.setCopyHttpSessionId(false);
  interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
  assertEquals(1, attributes.size());
  assertEquals("bar", attributes.get("foo"));
}
origin: spring-projects/spring-framework

@Test
public void defaultConstructor() throws Exception {
  Map<String, Object> attributes = new HashMap<>();
  WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
  this.servletRequest.setSession(new MockHttpSession(null, "123"));
  this.servletRequest.getSession().setAttribute("foo", "bar");
  this.servletRequest.getSession().setAttribute("bar", "baz");
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
  assertEquals(3, attributes.size());
  assertEquals("bar", attributes.get("foo"));
  assertEquals("baz", attributes.get("bar"));
  assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
origin: spring-projects/spring-security

public void registerStompEndpoints(StompEndpointRegistry registry) {
  registry.addEndpoint("/other").withSockJS()
      .setInterceptors(new HttpSessionHandshakeInterceptor());
  registry.addEndpoint("/chat").withSockJS()
      .setInterceptors(new HttpSessionHandshakeInterceptor());
}
origin: spring-projects/spring-framework

@Test
public void handshakeHandlerAndInterceptor() {
  WebMvcStompWebSocketEndpointRegistration registration =
      new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
  DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor);
  MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
  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());
}
origin: spring-projects/spring-framework

@Test
public void handshakeHandlerAndInterceptorWithAllowedOrigins() {
  WebMvcStompWebSocketEndpointRegistration registration =
      new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
  DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  String origin = "http://mydomain.com";
  registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin);
  MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
  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());
}
origin: spring-projects/spring-framework

@Test
public void interceptors() {
  WebSocketHandler handler = new TextWebSocketHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  this.registration.addHandler(handler, "/foo").addInterceptors(interceptor);
  List<Mapping> mappings = this.registration.getMappings();
  assertEquals(1, mappings.size());
  Mapping mapping = mappings.get(0);
  assertEquals(handler, mapping.webSocketHandler);
  assertEquals("/foo", mapping.path);
  assertNotNull(mapping.interceptors);
  assertEquals(2, mapping.interceptors.length);
  assertEquals(interceptor, mapping.interceptors[0]);
  assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
origin: spring-projects/spring-framework

@Test
public void interceptorsWithAllowedOrigins() {
  WebSocketHandler handler = new TextWebSocketHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins("http://mydomain1.com");
  List<Mapping> mappings = this.registration.getMappings();
  assertEquals(1, mappings.size());
  Mapping mapping = mappings.get(0);
  assertEquals(handler, mapping.webSocketHandler);
  assertEquals("/foo", mapping.path);
  assertNotNull(mapping.interceptors);
  assertEquals(2, mapping.interceptors.length);
  assertEquals(interceptor, mapping.interceptors[0]);
  assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
origin: spring-projects/spring-security

public void registerStompEndpoints(StompEndpointRegistry registry) {
  registry.addEndpoint("/websocket")
      .setHandshakeHandler(testHandshakeHandler())
      .addInterceptors(new HttpSessionHandshakeInterceptor());
}
origin: spring-projects/spring-framework

@Test
public void interceptorsPassedToSockJsRegistration() {
  WebSocketHandler handler = new TextWebSocketHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  this.registration.addHandler(handler, "/foo")
      .addInterceptors(interceptor)
      .setAllowedOrigins("http://mydomain1.com")
      .withSockJS();
  this.registration.getSockJsServiceRegistration().setTaskScheduler(this.taskScheduler);
  List<Mapping> mappings = this.registration.getMappings();
  assertEquals(1, mappings.size());
  Mapping mapping = mappings.get(0);
  assertEquals(handler, mapping.webSocketHandler);
  assertEquals("/foo/**", mapping.path);
  assertNotNull(mapping.sockJsService);
  assertTrue(mapping.sockJsService.getAllowedOrigins().contains("http://mydomain1.com"));
  List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
  assertEquals(interceptor, interceptors.get(0));
  assertEquals(OriginHandshakeInterceptor.class, interceptors.get(1).getClass());
}
origin: spring-projects/spring-framework

@Test
public void emptyAllowedOrigin() {
  WebSocketHandler handler = new TextWebSocketHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins();
  List<Mapping> mappings = this.registration.getMappings();
  assertEquals(1, mappings.size());
  Mapping mapping = mappings.get(0);
  assertEquals(handler, mapping.webSocketHandler);
  assertEquals("/foo", mapping.path);
  assertNotNull(mapping.interceptors);
  assertEquals(2, mapping.interceptors.length);
  assertEquals(interceptor, mapping.interceptors[0]);
  assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
origin: spring-projects/spring-framework

@Test
public void handshakeHandlerInterceptorWithSockJsService() {
  WebMvcStompWebSocketEndpointRegistration registration =
      new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
  DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).withSockJS();
  MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
  assertEquals(1, mappings.size());
  Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
  assertEquals(Arrays.asList("/foo/**"), entry.getValue());
  SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
  assertNotNull(requestHandler.getWebSocketHandler());
  DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
  assertNotNull(sockJsService);
  Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers();
  WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
  assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
  assertEquals(2, sockJsService.getHandshakeInterceptors().size());
  assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0));
  assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass());
}
origin: spring-projects/spring-framework

@Test
public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() {
  WebMvcStompWebSocketEndpointRegistration registration =
      new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
  DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
  HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
  String origin = "http://mydomain.com";
  registration.setHandshakeHandler(handshakeHandler)
      .addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS();
  MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
  assertEquals(1, mappings.size());
  Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
  assertEquals(Arrays.asList("/foo/**"), entry.getValue());
  SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
  assertNotNull(requestHandler.getWebSocketHandler());
  DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
  assertNotNull(sockJsService);
  Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers();
  WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
  assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
  assertEquals(2, sockJsService.getHandshakeInterceptors().size());
  assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0));
  assertEquals(OriginHandshakeInterceptor.class,
      sockJsService.getHandshakeInterceptors().get(1).getClass());
  assertTrue(sockJsService.getAllowedOrigins().contains(origin));
}
origin: spring-projects/spring-security

public void registerStompEndpoints(StompEndpointRegistry registry) {
  registry.addEndpoint("/other").setHandshakeHandler(testHandshakeHandler())
      .withSockJS().setInterceptors(new HttpSessionHandshakeInterceptor());
  registry.addEndpoint("/chat").setHandshakeHandler(testHandshakeHandler())
      .withSockJS().setInterceptors(new HttpSessionHandshakeInterceptor());
}
origin: org.carewebframework/org.carewebframework.web.core

/**
 * Register the web socket handler and add a handshake interceptor to copy attributes from the
 * http session to the web socket.
 *
 * @see org.springframework.web.socket.config.annotation.WebSocketConfigurer#registerWebSocketHandlers(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry)
 */
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(cwf_WebSocketHandler, "/ws/**").addInterceptors(new HttpSessionHandshakeInterceptor());
}
origin: org.fujion/fujion-core

/**
 * Register the web socket handler and add a handshake interceptor to copy attributes from the
 * http session to the web socket.
 *
 * @see org.springframework.web.socket.config.annotation.WebSocketConfigurer#registerWebSocketHandlers(org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry)
 */
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(fujion_WebSocketHandler, "/ws/**").addInterceptors(new HttpSessionHandshakeInterceptor());
}

org.springframework.web.socket.server.supportHttpSessionHandshakeInterceptor<init>

Javadoc

Default constructor for copying all HTTP session attributes and the HTTP session id.

Popular methods of HttpSessionHandshakeInterceptor

  • beforeHandshake
  • afterHandshake
  • getAttributeNames
    Return the configured attribute names to copy (read-only).
  • getSession
  • isCopyAllAttributes
    Whether to copy all HTTP session attributes.
  • isCopyHttpSessionId
    Whether to copy the HTTP session id to the handshake attributes.
  • isCreateSession
    Whether the HTTP session is allowed to be created.
  • setCopyAllAttributes
    Whether to copy all attributes from the HTTP session. If set to "true", any explicitly configured at
  • setCopyHttpSessionId
    Whether the HTTP session id should be copied to the handshake attributes under the key #HTTP_SESSION

Popular in Java

  • Parsing JSON documents to java classes using gson
  • putExtra (Intent)
  • getSystemService (Context)
  • findViewById (Activity)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • JCheckBox (javax.swing)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now