2222import java .net .Proxy ;
2323import java .net .SocketAddress ;
2424import java .net .URI ;
25- import java .util .Arrays ;
2625import java .util .Collections ;
2726import java .util .List ;
2827import java .util .Map ;
@@ -50,16 +49,6 @@ private GitpodServerLauncher(
5049 this .client = client ;
5150 }
5251
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-
6352 public GitpodServerConnection listen (
6453 String apiUrl ,
6554 String origin ,
@@ -70,45 +59,11 @@ public GitpodServerConnection listen(
7059 SSLContext sslContext
7160 ) throws Exception {
7261 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 ) {
10964 ssl .setSslContext (sslContext );
110- httpClient = new HttpClient (ssl );
11165 }
66+ HttpClient httpClient = new HttpClient (ssl );
11267 for (Proxy proxy : proxies ) {
11368 if (proxy .type ().equals (Proxy .Type .DIRECT )) {
11469 continue ;
@@ -161,10 +116,10 @@ public void onError(Session session, Throwable thr) {
161116 }, ClientEndpointConfig .Builder .create ().configurator (new ClientEndpointConfig .Configurator () {
162117 @ Override
163118 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 ));
168123 }
169124 }).build (), URI .create (apiUrl )));
170125 return connection ;
0 commit comments