9
9
*/
10
10
package org .zowe .apiml .gateway .ws ;
11
11
12
- import org .zowe .apiml .product .routing .RoutedService ;
13
- import org .zowe .apiml .product .routing .RoutedServices ;
14
- import org .zowe .apiml .product .routing .RoutedServicesUser ;
15
12
import lombok .extern .slf4j .Slf4j ;
16
- import org .eclipse .jetty .util .ssl .SslContextFactory ;
17
13
import org .springframework .beans .factory .annotation .Autowired ;
18
14
import org .springframework .cloud .client .ServiceInstance ;
19
15
import org .springframework .cloud .client .discovery .DiscoveryClient ;
20
16
import org .springframework .stereotype .Component ;
21
- import org .springframework .web .socket .CloseStatus ;
22
- import org .springframework .web .socket .WebSocketMessage ;
23
- import org .springframework .web .socket .WebSocketSession ;
17
+ import org .springframework .web .socket .*;
24
18
import org .springframework .web .socket .handler .AbstractWebSocketHandler ;
19
+ import org .zowe .apiml .product .routing .*;
25
20
26
21
import javax .inject .Singleton ;
27
22
import java .io .IOException ;
@@ -43,26 +38,26 @@ public class WebSocketProxyServerHandler extends AbstractWebSocketHandler implem
43
38
private final Map <String , WebSocketRoutedSession > routedSessions ;
44
39
private final Map <String , RoutedServices > routedServicesMap = new ConcurrentHashMap <>();
45
40
private final DiscoveryClient discovery ;
46
- private final SslContextFactory .Server jettySslContextFactory ;
47
41
private final WebSocketRoutedSessionFactory webSocketRoutedSessionFactory ;
42
+ private final WebSocketClientFactory webSocketClientFactory ;
48
43
private static final String SEPARATOR = "/" ;
49
44
50
45
@ Autowired
51
- public WebSocketProxyServerHandler (DiscoveryClient discovery , SslContextFactoryProvider jettySslContextFactoryProvider ) {
46
+ public WebSocketProxyServerHandler (DiscoveryClient discovery , WebSocketClientFactory webSocketClientFactory ) {
52
47
this .discovery = discovery ;
53
- this .jettySslContextFactory = jettySslContextFactoryProvider . getSslFactory () ;
48
+ this .webSocketClientFactory = webSocketClientFactory ;
54
49
this .routedSessions = new ConcurrentHashMap <>(); // Default
55
50
this .webSocketRoutedSessionFactory = new WebSocketRoutedSessionFactoryImpl ();
56
- log .debug ("Creating WebSocketProxyServerHandler {} jettySslContextFactory={} " , this , jettySslContextFactory );
51
+ log .debug ("Creating WebSocketProxyServerHandler {} " , this );
57
52
}
58
53
59
- public WebSocketProxyServerHandler (DiscoveryClient discovery , SslContextFactoryProvider sslContextFactoryProvider ,
54
+ public WebSocketProxyServerHandler (DiscoveryClient discovery , WebSocketClientFactory webSocketClientFactory ,
60
55
Map <String , WebSocketRoutedSession > routedSessions , WebSocketRoutedSessionFactory webSocketRoutedSessionFactory ) {
61
56
this .discovery = discovery ;
62
- this .jettySslContextFactory = sslContextFactoryProvider . getSslFactory () ;
57
+ this .webSocketClientFactory = webSocketClientFactory ;
63
58
this .routedSessions = routedSessions ;
64
59
this .webSocketRoutedSessionFactory = webSocketRoutedSessionFactory ;
65
- log .debug ("Creating WebSocketProxyServerHandler {} jettySslContextFactory={} " , this , jettySslContextFactory );
60
+ log .debug ("Creating WebSocketProxyServerHandler {}" , this );
66
61
}
67
62
68
63
public void addRoutedServices (String serviceId , RoutedServices routedServices ) {
@@ -133,9 +128,9 @@ private void openWebSocketConnection(RoutedService service, ServiceInstance serv
133
128
String serviceUrl = service .getServiceUrl ();
134
129
String targetUrl = getTargetUrl (serviceUrl , serviceInstance , path );
135
130
136
- log .debug (String .format ("Opening routed WebSocket session from %s to %s with %s by %s" , uri .toString (), targetUrl , jettySslContextFactory , this ));
131
+ log .debug (String .format ("Opening routed WebSocket session from %s to %s with %s by %s" , uri .toString (), targetUrl , webSocketClientFactory , this ));
137
132
try {
138
- WebSocketRoutedSession session = webSocketRoutedSessionFactory .session (webSocketSession , targetUrl , jettySslContextFactory );
133
+ WebSocketRoutedSession session = webSocketRoutedSessionFactory .session (webSocketSession , targetUrl , webSocketClientFactory );
139
134
routedSessions .put (webSocketSession .getId (), session );
140
135
} catch (WebSocketProxyError e ) {
141
136
log .debug ("Error opening WebSocket connection to {}: {}" , targetUrl , e .getMessage ());
@@ -146,7 +141,7 @@ private void openWebSocketConnection(RoutedService service, ServiceInstance serv
146
141
private ServiceInstance findServiceInstance (String serviceId ) {
147
142
List <ServiceInstance > serviceInstances = this .discovery .getInstances (serviceId );
148
143
if (!serviceInstances .isEmpty ()) {
149
- // TODO: This just a simple implementation that will be replaced by more sophisticated mechanism in future
144
+ // TODO: Is this implementation apropriate?
150
145
return serviceInstances .get (0 );
151
146
}
152
147
else {
0 commit comments