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

The following examples show how to use org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry. 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: WebSocketConfig.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    WebSocketHandShakeInterceptor handShakeWebSocketInterceptor = interceptorWebSocket();

    registry.addHandler(this.brokerStomp, "/sockjs")
            .addInterceptors(handShakeWebSocketInterceptor)
            .setAllowedOrigins("*")
            .withSockJS()
            .setHeartbeatTime(this.weEventConfig.getStompHeartbeats() * 1000);

    registry.addHandler(this.brokerStomp, "/stomp")
            .addInterceptors(handShakeWebSocketInterceptor)
            .setAllowedOrigins("*");

    registry.addHandler(this.webSocketMqtt, "/mqtt")
            .addInterceptors(handShakeWebSocketInterceptor)
            .setAllowedOrigins("*");
}
 
Example #3
Source File: WebSocketEndpointConfig.java    From artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(final WebSocketHandlerRegistry registry) {
    registry.addHandler(heartbeatWsHandler(), WebSocketPaths.HEARTBEAT_DESTINATION).setAllowedOrigins("*")
            .addInterceptors(new WsIPBlackList("service-heartbeat"));
    registry.addHandler(serviceChangeWsHandler(), WebSocketPaths.SERVICE_CHANGE_DESTINATION).setAllowedOrigins("*")
            .addInterceptors(new WsIPBlackList("service-discovery"));
    registry.addHandler(allServicesChangeWsHandler(), WebSocketPaths.ALL_SERVICES_CHANGE_DESTINATION).setAllowedOrigins("*")
            .addInterceptors(new WsIPBlackList("service-discoveries"));
}
 
Example #4
Source File: BootStrap.java    From MyBlog with Apache License 2.0 5 votes vote down vote up
@Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(echoWebSocketHandler(), "/api/ws/chat")
                .addInterceptors(new MyHandshakeInterceptor())
                .setAllowedOrigins("*");

//        registry.addHandler(echoWebSocketHandler(), "/api/ws/chat");
    }
 
Example #5
Source File: TraderUMainConfiguration.java    From java-trader with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(createNodeMgmtHandler(), NodeMgmtService.URI_WS_NODEMGMT)
    .setAllowedOrigins("*")
    .addInterceptors(new HttpSessionHandshakeInterceptor());
    //.setHandshakeHandler(createJettyHandshakeHandler());
}
 
Example #6
Source File: WebSocketAutoConfiguration.java    From graphql-spqr-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
    String webSocketEndpoint = config.getWs().getEndpoint();
    String graphQLEndpoint = config.getHttp().getEndpoint();
    String endpointUrl = webSocketEndpoint == null ? graphQLEndpoint : webSocketEndpoint;
    webSocketHandlerRegistry
            .addHandler(webSocketHandler(webSocketExecutor(webSocketContextFactory())), endpointUrl)
            .setAllowedOrigins(config.getWs().getAllowedOrigins());
}
 
Example #7
Source File: WebSocketConfig.java    From spring-boot-starter-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	// 允许连接的域,只能以http或https开头
	String[] allowsOrigins = { "http://www.xxx.com" };

	// WebIM WebSocket通道
	registry.addHandler(chatWebSocketHandler(), "/           webSocketIMServer").setAllowedOrigins(allowsOrigins)
			.addInterceptors(myInterceptor());
	registry.addHandler(chatWebSocketHandler(), "/sockjs/w          ebSocketIMServer")
			.setAllowedOrigins(allowsOrigins).addInterceptors(myInterceptor()).withSockJS();
}
 
Example #8
Source File: WebSocketConfig.java    From mySSM with MIT License 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    //WebIM WebSocket通道
    registry.addHandler(chatWebSocketHandler(),"/webSocketIMServer");
    registry.addHandler(chatWebSocketHandler(),"/sockjs/webSocketIMServer");
    registry.addHandler(chatWebSocketHandler(), "/sockjs/webSocketIMServer").withSockJS();
}
 
Example #9
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 #10
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);
    
  }
}
 
Example #11
Source File: WebSocketConfig.java    From TrackRay with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(pluginHandler, "plugin.ws").
            setAllowedOrigins("*");
    registry.addHandler(msfHandler, "msf.ws").
            setAllowedOrigins("*");
}
 
Example #12
Source File: WebSocketConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		//将MarcoHandler映射到“/marco”上
		//withSockJS是为了使用SockJS,如果不加的话,前端将使用低层级的WebSocket(代码也要改)
//		registry.addHandler(marcoHandler(), "/marco");
		registry.addHandler(marcoHandler(), "/marco").withSockJS();
	}
 
Example #13
Source File: ServerWebSocketConfig.java    From Jpom with MIT License 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    // 控制台
    registry.addHandler(new ConsoleHandler(), "/console")
            .addInterceptors(serverWebSocketInterceptor).setAllowedOrigins("*");
    // 脚本模板
    registry.addHandler(new ScriptHandler(), "/script_run")
            .addInterceptors(serverWebSocketInterceptor).setAllowedOrigins("*");
    // tomcat
    registry.addHandler(new TomcatHandler(), "/tomcat_log")
            .addInterceptors(serverWebSocketInterceptor).setAllowedOrigins("*");
    // ssh
    registry.addHandler(new SshHandler(), "/ssh")
            .addInterceptors(serverWebSocketInterceptor).setAllowedOrigins("*");
}
 
Example #14
Source File: WebSocketConfig.java    From code with Apache License 2.0 5 votes vote down vote up
/**
 * ws://localhost:9501/ws
 * http://www.websocket-test.com/
 * http://coolaf.com/tool/chattest
 */
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
    webSocketHandlerRegistry.addHandler(myHandler(), "/ws")
            .setAllowedOrigins("*")
            .addInterceptors(myHandshakeInterceptor);
}
 
Example #15
Source File: WebSocketConfig.java    From example-restful-project with MIT License 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry
        .addHandler(notificationHandler(), "/teapots")
        .addHandler(teapotHandler(), "/teapots/register/{teapotId}")
        .addHandler(consoleHandler(), "/teapots/{teapotId}")
        .setAllowedOrigins("*")    // allow all origins
        .addInterceptors(new UriTemplateHandshakeInterceptor());
}
 
Example #16
Source File: WebSocketConfig.java    From jt808-server with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    WebSocketMessageHandler webSocketHandler = webSocketMessageHandler();
    WebSocketInterceptor webSocketInterceptor = webSocketInterceptor();
    registry.addHandler(webSocketHandler, "/websocket").addInterceptors(webSocketInterceptor);
    registry.addHandler(webSocketHandler, "/sockjs").addInterceptors(webSocketInterceptor).withSockJS();
}
 
Example #17
Source File: WebSocketConfiguration.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry
      .addHandler(webSocketHandler(), "/offramp/**")
      .addInterceptors(new OfframpHandshakeInterceptor())
      .setAllowedOrigins("*");
}
 
Example #18
Source File: Application.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry)
{
  registry.addHandler(handler(), "/helloworld");
}
 
Example #19
Source File: ChromaApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(handler(), "/chroma");
}
 
Example #20
Source File: PointerDetectorApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(handler(), "/pointerdetector");
}
 
Example #21
Source File: MagicMirrorApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(handler(), "/magicmirror");
}
 
Example #22
Source File: CrowdDetectorApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(handler(), "/crowddetector");
}
 
Example #23
Source File: HelloWorldRecApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(handler(), "/repository");
}
 
Example #24
Source File: GroupCallApp.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(groupCallHandler(), "/groupcall");
}
 
Example #25
Source File: WebSocketConfiguration.java    From aws-refapp with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(sqsReceivingMessageHandler(), "/sqs-messages").withSockJS();
    registry.addHandler(snsReceivingMessageHandler(), "/sns-messages").withSockJS();
}
 
Example #26
Source File: KurentoRoomServerApp.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  registry.addHandler(groupCallHandler(), "/room");
}
 
Example #27
Source File: WebsocketConfiguration.java    From onboard with Apache License 2.0 4 votes vote down vote up
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
    registry.addHandler(websocketHandler, "/websocket");
}
 
Example #28
Source File: SpringWebsocketsApplication.java    From training with MIT License 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	registry.addHandler(chatSocket, "/chat/*")
			.addInterceptors(new HttpSessionHandshakeInterceptor());
}
 
Example #29
Source File: WebSocketConfiguration.java    From khs-trouble-maker with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	registry.addHandler(servicesHandler(), "/ws/services").setAllowedOrigins("*");
	registry.addHandler(eventsHandler(), "/ws/events").setAllowedOrigins("*");
}
 
Example #30
Source File: Application.java    From full-teaching with Apache License 2.0 4 votes vote down vote up
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
	registry.addHandler(chatHandler(), "/chat").setAllowedOrigins("*");		
}