@Test void givenInvalidURI_whenTheConnectionIsEstablished_thenTheSocketIsClosedAsNotAcceptable() throws Exception { WebSocketSession establishedSession = mock(WebSocketSession.class); when(establishedSession.isOpen()).thenReturn(true); when(establishedSession.getUri()).thenReturn(new URI("wss: underTest.afterConnectionEstablished(establishedSession); verify(establishedSession).close(new CloseStatus(CloseStatus.NOT_ACCEPTABLE.getCode(), "Invalid URL format")); }
@Override public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception { String[] uriParts = getUriParts(webSocketSession); if (uriParts != null && uriParts.length == 5) { String majorVersion = uriParts[2]; String serviceId = uriParts[3]; String path = uriParts[4]; RoutedServices routedServices = routedServicesMap.get(serviceId); if (routedServices != null) { RoutedService service = routedServices.findServiceByGatewayUrl("ws/" + majorVersion); if (service == null) { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested ws/%s url is not known by the gateway", majorVersion)); return; } ServiceInstance serviceInstance = findServiceInstance(serviceId); if (serviceInstance != null) { openWebSocketConnection(service, serviceInstance, serviceInstance, path, webSocketSession); } else { closeWebSocket(webSocketSession, CloseStatus.SERVICE_RESTARTED, String.format("Requested service %s does not have available instance", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested service %s is not known by the gateway", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, "Invalid URL format"); } }
WebSocketProxyServerHandler extends AbstractWebSocketHandler implements RoutedServicesUser { @Override public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception { String[] uriParts = getUriParts(webSocketSession); if (uriParts != null && uriParts.length == 5) { String majorVersion = uriParts[2]; String serviceId = uriParts[3]; String path = uriParts[4]; RoutedServices routedServices = routedServicesMap.get(serviceId); if (routedServices != null) { RoutedService service = routedServices.findServiceByGatewayUrl("ws/" + majorVersion); if (service == null) { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested ws/%s url is not known by the gateway", majorVersion)); return; } ServiceInstance serviceInstance = findServiceInstance(serviceId); if (serviceInstance != null) { openWebSocketConnection(service, serviceInstance, serviceInstance, path, webSocketSession); } else { closeWebSocket(webSocketSession, CloseStatus.SERVICE_RESTARTED, String.format("Requested service %s does not have available instance", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested service %s is not known by the gateway", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, "Invalid URL format"); } } }
WebSocketProxyServerHandler extends AbstractWebSocketHandler implements RoutedServicesUser { @Override public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception { String[] uriParts = getUriParts(webSocketSession); if (uriParts != null && uriParts.length == 5) { String majorVersion = uriParts[2]; String serviceId = uriParts[3]; String path = uriParts[4]; RoutedServices routedServices = routedServicesMap.get(serviceId); if (routedServices != null) { RoutedService service = routedServices.findServiceByGatewayUrl("ws/" + majorVersion); if (service == null) { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested ws/%s url is not known by the gateway", majorVersion)); return; } ServiceInstance serviceInstance = findServiceInstance(serviceId); if (serviceInstance != null) { openWebSocketConnection(service, serviceInstance, serviceInstance, path, webSocketSession); } else { closeWebSocket(webSocketSession, CloseStatus.SERVICE_RESTARTED, String.format("Requested service %s does not have available instance", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested service %s is not known by the gateway", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, "Invalid URL format"); } } @Autowired  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider jettySslContextFactoryProvider);  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider sslContextFactoryProvider,
                                       Map<String, WebSocketRoutedSession> routedSessions, WebSocketRoutedSessionFactory webSocketRoutedSessionFactory); }
WebSocketProxyServerHandler extends AbstractWebSocketHandler implements RoutedServicesUser { @Override public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception { String[] uriParts = getUriParts(webSocketSession); if (uriParts != null && uriParts.length == 5) { String majorVersion = uriParts[2]; String serviceId = uriParts[3]; String path = uriParts[4]; RoutedServices routedServices = routedServicesMap.get(serviceId); if (routedServices != null) { RoutedService service = routedServices.findServiceByGatewayUrl("ws/" + majorVersion); if (service == null) { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested ws/%s url is not known by the gateway", majorVersion)); return; } ServiceInstance serviceInstance = findServiceInstance(serviceId); if (serviceInstance != null) { openWebSocketConnection(service, serviceInstance, serviceInstance, path, webSocketSession); } else { closeWebSocket(webSocketSession, CloseStatus.SERVICE_RESTARTED, String.format("Requested service %s does not have available instance", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested service %s is not known by the gateway", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, "Invalid URL format"); } } @Autowired  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider jettySslContextFactoryProvider);  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider sslContextFactoryProvider,
                                       Map<String, WebSocketRoutedSession> routedSessions, WebSocketRoutedSessionFactory webSocketRoutedSessionFactory); void addRoutedServices(String serviceId, RoutedServices routedServices); Map<String, WebSocketRoutedSession> getRoutedSessions(); @Override void afterConnectionEstablished(WebSocketSession webSocketSession); @Override void afterConnectionClosed(WebSocketSession session, CloseStatus status); @Override void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage); }
WebSocketProxyServerHandler extends AbstractWebSocketHandler implements RoutedServicesUser { @Override public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception { String[] uriParts = getUriParts(webSocketSession); if (uriParts != null && uriParts.length == 5) { String majorVersion = uriParts[2]; String serviceId = uriParts[3]; String path = uriParts[4]; RoutedServices routedServices = routedServicesMap.get(serviceId); if (routedServices != null) { RoutedService service = routedServices.findServiceByGatewayUrl("ws/" + majorVersion); if (service == null) { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested ws/%s url is not known by the gateway", majorVersion)); return; } ServiceInstance serviceInstance = findServiceInstance(serviceId); if (serviceInstance != null) { openWebSocketConnection(service, serviceInstance, serviceInstance, path, webSocketSession); } else { closeWebSocket(webSocketSession, CloseStatus.SERVICE_RESTARTED, String.format("Requested service %s does not have available instance", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, String.format("Requested service %s is not known by the gateway", serviceId)); } } else { closeWebSocket(webSocketSession, CloseStatus.NOT_ACCEPTABLE, "Invalid URL format"); } } @Autowired  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider jettySslContextFactoryProvider);  WebSocketProxyServerHandler(DiscoveryClient discovery, SslContextFactoryProvider sslContextFactoryProvider,
                                       Map<String, WebSocketRoutedSession> routedSessions, WebSocketRoutedSessionFactory webSocketRoutedSessionFactory); void addRoutedServices(String serviceId, RoutedServices routedServices); Map<String, WebSocketRoutedSession> getRoutedSessions(); @Override void afterConnectionEstablished(WebSocketSession webSocketSession); @Override void afterConnectionClosed(WebSocketSession session, CloseStatus status); @Override void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage);  }