From 132df7aebf7471a5ea807c61e4474d5f242c2c6b Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 8 Jul 2022 10:40:04 +0000 Subject: [PATCH] Use a different logic when client is not using proxies to connect to Gitpod Server when using JetBrains IDEs Also, use a fixed version on JetBrains backend-plugin to avoid unexpected API changes which could block Werft to build the main branch on Gitpod repository. --- .../api/GitpodServerLauncher.java | 31 +++++++++++++++++++ .../backend-plugin/gradle-latest.properties | 2 +- .../remote/latest/GitpodTerminalService.kt | 5 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java index 17064ce885e044..f1ea3ddeda8f76 100644 --- a/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java +++ b/components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServerLauncher.java @@ -71,6 +71,37 @@ public GitpodServerConnection listen( ) throws Exception { String gitpodHost = URI.create(apiUrl).getHost(); HttpClient httpClient; + if (sslContext == null && proxies.size() == 0) { + GitpodServerConnectionImpl connection = new GitpodServerConnectionImpl(gitpodHost); + connection.setSession(ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() { + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(new WebSocketMessageHandler(messageReader, jsonHandler, remoteEndpoint)); + messageWriter.setSession(session); + client.notifyConnect(); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + connection.complete(closeReason); + } + + @Override + public void onError(Session session, Throwable thr) { + GitpodServerConnectionImpl.LOG.log(Level.WARNING, gitpodHost + ": connection error:", thr); + connection.completeExceptionally(thr); + } + }, ClientEndpointConfig.Builder.create().configurator(new ClientEndpointConfig.Configurator() { + @Override + public void beforeRequest(final Map> headers) { + headers.put("Origin", Arrays.asList(origin)); + headers.put("Authorization", Arrays.asList("Bearer " + token)); + headers.put("User-Agent", Arrays.asList(userAgent)); + headers.put("X-Client-Version", Arrays.asList(clientVersion)); + } + }).build(), URI.create(apiUrl))); + return connection; + } if (sslContext == null) { httpClient = new HttpClient(); } else { diff --git a/components/ide/jetbrains/backend-plugin/gradle-latest.properties b/components/ide/jetbrains/backend-plugin/gradle-latest.properties index bb2590085d2fd0..edaf7bd46684b5 100644 --- a/components/ide/jetbrains/backend-plugin/gradle-latest.properties +++ b/components/ide/jetbrains/backend-plugin/gradle-latest.properties @@ -6,4 +6,4 @@ pluginUntilBuild=222.* # See https://jb.gg/intellij-platform-builds-list for available build versions. pluginVerifierIdeVersions=2022.2 # Version from "com.jetbrains.intellij.idea" which can be found at https://www.jetbrains.com/intellij-repository/snapshots -platformVersion=222-EAP-SNAPSHOT +platformVersion=222.3345-EAP-CANDIDATE-SNAPSHOT diff --git a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt index ced1f759e52c30..7367897a47d7ec 100644 --- a/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt +++ b/components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodTerminalService.kt @@ -208,6 +208,11 @@ class GitpodTerminalService(private val session: ClientProjectSession) { thisLogger().error("gitpod: Failed to forward port $hostPort from Supervisor's Terminal " + "${supervisorTerminal.pid}: $reason") } + + override fun onPortForwardingEnded(hostPort: Int) { + thisLogger().info("gitpod: Port $hostPort from Supervisor's Terminal " + + "${supervisorTerminal.pid} is not being forwarded anymore.") + } } }