use of org.springframework.web.socket.handler.PerConnectionWebSocketHandler in project ma-core-public by infiniteautomation.
the class MangoWebSocketConfiguration method registerWebSocketHandlers.
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
// Setup Allowed Origins for CORS requests
boolean hasOrigins = false;
String[] origins = null;
if (Common.envProps.getBoolean("rest.cors.enabled", false)) {
hasOrigins = true;
origins = Common.envProps.getStringArray("rest.cors.allowedOrigins", ",", new String[0]);
}
for (WebSocketDefinition def : websocketDefinitions()) {
WebSocketHandler handler = def.getHandlerInstance();
if (def.perConnection()) {
PerConnectionWebSocketHandler perConnection = new PerConnectionWebSocketHandler(handler.getClass());
beanFactory.initializeBean(perConnection, PerConnectionWebSocketHandler.class.getName());
handler = perConnection;
} else {
beanFactory.autowireBean(handler);
handler = (WebSocketHandler) beanFactory.initializeBean(handler, handler.getClass().getName());
}
WebSocketHandlerRegistration registration = registry.addHandler(handler, def.getUrl()).setHandshakeHandler(handshakeHandler()).addInterceptors(handshakeIterceptor());
if (hasOrigins)
registration.setAllowedOrigins(origins);
}
}
Aggregations