org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration Java Examples

The following examples show how to use org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketConfig.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    final String[] allowedOriginArray = getAllowedOriginArray(configProperties.getWebSocketAllowedOrigins());

    for (PinpointWebSocketHandler handler : handlerRepository.getWebSocketHandlerRepository()) {
        String path = handler.getRequestMapping() + WEBSOCKET_SUFFIX;

        WebSocketHandler webSocketHandler = webSocketHandlerDecoratorFactory.decorate(handler);
        final WebSocketHandlerRegistration webSocketHandlerRegistration = registry.addHandler(webSocketHandler, path);

        webSocketHandlerRegistration.addInterceptors(new HttpSessionHandshakeInterceptor());
        webSocketHandlerRegistration.addInterceptors(new WebSocketSessionContextPrepareHandshakeInterceptor());
        if (Objects.nonNull(customHandshakeInterceptor)) {
            webSocketHandlerRegistration.addInterceptors(customHandshakeInterceptor);
        }
        webSocketHandlerRegistration.setAllowedOrigins(allowedOriginArray);
    }
}
 
Example #2
Source File: GemWebSocketConfig.java    From gem with MIT License 5 votes vote down vote up
/**
 * 设置连接地址和拦截器
 */
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	System.out.println("1111111111111111111111111111111111111");
	// 设置websocket的连接地址
	WebSocketHandlerRegistration addHandler = registry.addHandler(webSocketMessage(), "/");
	// 设置websocket的拦截器
	WebSocketHandlerRegistration addInterceptors = addHandler.addInterceptors(new GemWebSocketInterceptor());
	// 设置跨域请求
	addInterceptors.setAllowedOrigins("*");
}
 
Example #3
Source File: JsonRpcConfiguration.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private void publishWebSocketEndpoint(WebSocketHandlerRegistry wsHandlerRegistry,
    JsonRpcHandler<?> handler, List<String> paths) {

  ProtocolManager protocolManager = (ProtocolManager) ctx.getBean("protocolManager", handler);

  JsonRpcWebSocketHandler wsHandler = new JsonRpcWebSocketHandler(protocolManager);

  protocolManager.setPingWachdog(handler.isPingWatchdog());

  for (String path : paths) {

    WebSocketHandlerRegistration registration = wsHandlerRegistry.addHandler(wsHandler, path);

    List<String> origins = handler.allowedOrigins();
    registration.setAllowedOrigins(origins.toArray(new String[origins.size()]));

    if (handler.isSockJSEnabled()) {
      registration.withSockJS().setSessionCookieNeeded(false);
    }
  
    if (handler.getLabel() != null) {
      wsHandler.setLabel(handler.getLabel());
    }
    
    HandshakeInterceptor[] interceptors = new HandshakeInterceptor[handler.interceptors().size()];
    int i = 0;
    for (Object obj : handler.interceptors()) {
  	  if (obj instanceof HandshakeInterceptor) {
   	  interceptors[i] = (HandshakeInterceptor) obj;
   	  i++;
  	  }
    }
    registration.addInterceptors(interceptors);
    
  }
}