22
22
import java .net .Proxy ;
23
23
import java .net .SocketAddress ;
24
24
import java .net .URI ;
25
- import java .util .Arrays ;
26
25
import java .util .Collections ;
27
26
import java .util .List ;
28
27
import java .util .Map ;
@@ -50,16 +49,6 @@ private GitpodServerLauncher(
50
49
this .client = client ;
51
50
}
52
51
53
- public GitpodServerConnection listen (
54
- String apiUrl ,
55
- String origin ,
56
- String userAgent ,
57
- String clientVersion ,
58
- String token
59
- ) throws Exception {
60
- return listen (apiUrl , origin , userAgent , clientVersion , token , Collections .emptyList (), null );
61
- }
62
-
63
52
public GitpodServerConnection listen (
64
53
String apiUrl ,
65
54
String origin ,
@@ -70,45 +59,11 @@ public GitpodServerConnection listen(
70
59
SSLContext sslContext
71
60
) throws Exception {
72
61
String gitpodHost = URI .create (apiUrl ).getHost ();
73
- HttpClient httpClient ;
74
- if (sslContext == null && proxies .size () == 0 ) {
75
- GitpodServerConnectionImpl connection = new GitpodServerConnectionImpl (gitpodHost );
76
- connection .setSession (ContainerProvider .getWebSocketContainer ().connectToServer (new Endpoint () {
77
- @ Override
78
- public void onOpen (Session session , EndpointConfig config ) {
79
- session .addMessageHandler (new WebSocketMessageHandler (messageReader , jsonHandler , remoteEndpoint ));
80
- messageWriter .setSession (session );
81
- client .notifyConnect ();
82
- }
83
-
84
- @ Override
85
- public void onClose (Session session , CloseReason closeReason ) {
86
- connection .complete (closeReason );
87
- }
88
-
89
- @ Override
90
- public void onError (Session session , Throwable thr ) {
91
- GitpodServerConnectionImpl .LOG .log (Level .WARNING , gitpodHost + ": connection error:" , thr );
92
- connection .completeExceptionally (thr );
93
- }
94
- }, ClientEndpointConfig .Builder .create ().configurator (new ClientEndpointConfig .Configurator () {
95
- @ Override
96
- public void beforeRequest (final Map <String , List <String >> headers ) {
97
- headers .put ("Origin" , Arrays .asList (origin ));
98
- headers .put ("Authorization" , Arrays .asList ("Bearer " + token ));
99
- headers .put ("User-Agent" , Arrays .asList (userAgent ));
100
- headers .put ("X-Client-Version" , Arrays .asList (clientVersion ));
101
- }
102
- }).build (), URI .create (apiUrl )));
103
- return connection ;
104
- }
105
- if (sslContext == null ) {
106
- httpClient = new HttpClient ();
107
- } else {
108
- SslContextFactory ssl = new SslContextFactory .Client ();
62
+ SslContextFactory ssl = new SslContextFactory .Client ();
63
+ if (sslContext != null ) {
109
64
ssl .setSslContext (sslContext );
110
- httpClient = new HttpClient (ssl );
111
65
}
66
+ HttpClient httpClient = new HttpClient (ssl );
112
67
for (Proxy proxy : proxies ) {
113
68
if (proxy .type ().equals (Proxy .Type .DIRECT )) {
114
69
continue ;
@@ -161,10 +116,10 @@ public void onError(Session session, Throwable thr) {
161
116
}, ClientEndpointConfig .Builder .create ().configurator (new ClientEndpointConfig .Configurator () {
162
117
@ Override
163
118
public void beforeRequest (final Map <String , List <String >> headers ) {
164
- headers .put ("Origin" , Arrays . asList (origin ));
165
- headers .put ("Authorization" , Arrays . asList ("Bearer " + token ));
166
- headers .put ("User-Agent" , Arrays . asList (userAgent ));
167
- headers .put ("X-Client-Version" , Arrays . asList (clientVersion ));
119
+ headers .put ("Origin" , Collections . singletonList (origin ));
120
+ headers .put ("Authorization" , Collections . singletonList ("Bearer " + token ));
121
+ headers .put ("User-Agent" , Collections . singletonList (userAgent ));
122
+ headers .put ("X-Client-Version" , Collections . singletonList (clientVersion ));
168
123
}
169
124
}).build (), URI .create (apiUrl )));
170
125
return connection ;
0 commit comments