From f6af4f23d9709312a312f9b68d212955cc03ca93 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Thu, 21 Sep 2023 14:07:16 -0700 Subject: [PATCH] GLSP-1041: Fix connection to JavaServer via websocket (#179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * GLSP-1041: Fix connection to JavaServer via websocket Update `websocket-connection-forwarder´ to send messages via websockets as decoded strings instead of buffers. Althoug the websocket protocol supports both string and buffer messages the java implementation is only capable of handling string messages. Fixes https://github.com/eclipse-glsp/glsp/issues/1041 # Update to latest client version Adapt code base to conform to changes for https://github.com/eclipse-glsp/glsp-client/pull/288 # Also - Ensure that the diagramDiContainer gets unloaded when the widget is disposed. (This trigger dispose functionality defiend in th diagram container (e.g. methods annoted with @preDestroy) -Align name of `notification-module` directory wither other feature root dirs (=> notification) Requires https://github.com/eclipse-glsp/glsp-client/pull/288 --- .../diagram/features/default-modules.ts | 2 +- .../notification-module.ts | 0 .../theia-glsp-message-service.ts | 0 .../browser/diagram/glsp-diagram-widget.ts | 5 +- .../src/browser/diagram/index.ts | 4 +- .../src/browser/theia-jsonrpc-glsp-client.ts | 9 --- .../src/common/websocket-util.ts | 2 +- .../node/glsp-socket-server-contribution.ts | 3 +- .../node/websocket-connection-forwarder.ts | 8 +- yarn.lock | 74 +++++++++---------- 10 files changed, 53 insertions(+), 54 deletions(-) rename packages/theia-integration/src/browser/diagram/features/{notification-module => notification}/notification-module.ts (100%) rename packages/theia-integration/src/browser/diagram/features/{notification-module => notification}/theia-glsp-message-service.ts (100%) diff --git a/packages/theia-integration/src/browser/diagram/features/default-modules.ts b/packages/theia-integration/src/browser/diagram/features/default-modules.ts index 3590e0b..077bf39 100644 --- a/packages/theia-integration/src/browser/diagram/features/default-modules.ts +++ b/packages/theia-integration/src/browser/diagram/features/default-modules.ts @@ -17,7 +17,7 @@ import { ModuleConfiguration } from '@eclipse-glsp/client'; import { theiaExportModule } from './export/theia-export-module'; import { theiaNavigationModule } from './navigation/theia-navigation-module'; -import { theiaNotificationModule } from './notification-module/notification-module'; +import { theiaNotificationModule } from './notification/notification-module'; import { theiaSelectModule } from './select/theia-select-module'; import { theiaSourceModelWatcherModule } from './source-model-watcher/theia-source-model-watcher-module'; diff --git a/packages/theia-integration/src/browser/diagram/features/notification-module/notification-module.ts b/packages/theia-integration/src/browser/diagram/features/notification/notification-module.ts similarity index 100% rename from packages/theia-integration/src/browser/diagram/features/notification-module/notification-module.ts rename to packages/theia-integration/src/browser/diagram/features/notification/notification-module.ts diff --git a/packages/theia-integration/src/browser/diagram/features/notification-module/theia-glsp-message-service.ts b/packages/theia-integration/src/browser/diagram/features/notification/theia-glsp-message-service.ts similarity index 100% rename from packages/theia-integration/src/browser/diagram/features/notification-module/theia-glsp-message-service.ts rename to packages/theia-integration/src/browser/diagram/features/notification/theia-glsp-message-service.ts diff --git a/packages/theia-integration/src/browser/diagram/glsp-diagram-widget.ts b/packages/theia-integration/src/browser/diagram/glsp-diagram-widget.ts index 3312a2a..fd94690 100644 --- a/packages/theia-integration/src/browser/diagram/glsp-diagram-widget.ts +++ b/packages/theia-integration/src/browser/diagram/glsp-diagram-widget.ts @@ -128,6 +128,10 @@ export class GLSPDiagramWidget extends BaseWidget implements SaveableSource, Sta } super.onAfterAttach(msg); + this.disposed.connect(() => { + this.diContainer.unbindAll(); + }); + this.node.dataset['uri'] = this.uri.toString(); if (this.diContainer.isBound(TYPES.ICopyPasteHandler)) { this.copyPasteHandler = this.diContainer.get(TYPES.ICopyPasteHandler); @@ -163,7 +167,6 @@ export class GLSPDiagramWidget extends BaseWidget implements SaveableSource, Sta }; const loader = this.diContainer.get(DiagramLoader); - return loader.load({ requestModelOptions: this.requestModelOptions }); } diff --git a/packages/theia-integration/src/browser/diagram/index.ts b/packages/theia-integration/src/browser/diagram/index.ts index d8c7b9a..d66694f 100644 --- a/packages/theia-integration/src/browser/diagram/index.ts +++ b/packages/theia-integration/src/browser/diagram/index.ts @@ -17,8 +17,8 @@ export * from './features/export/theia-export-module'; export * from './features/export/theia-export-svg-action-handler'; export * from './features/navigation/theia-navigate-to-external-target-handler'; export * from './features/navigation/theia-navigation-module'; -export * from './features/notification-module/notification-module'; -export * from './features/notification-module/theia-glsp-message-service'; +export * from './features/notification/notification-module'; +export * from './features/notification/theia-glsp-message-service'; export * from './features/select/theia-glsp-selection-forwarder'; export * from './features/select/theia-select-module'; export * from './features/source-model-watcher/theia-source-model-changed-handler'; diff --git a/packages/theia-integration/src/browser/theia-jsonrpc-glsp-client.ts b/packages/theia-integration/src/browser/theia-jsonrpc-glsp-client.ts index 54fe3ff..9bb0dca 100644 --- a/packages/theia-integration/src/browser/theia-jsonrpc-glsp-client.ts +++ b/packages/theia-integration/src/browser/theia-jsonrpc-glsp-client.ts @@ -36,15 +36,6 @@ export class TheiaJsonrpcGLSPClient extends BaseJsonrpcGLSPClient { } super.handleConnectionClosed(); } - - protected override checkConnectionState(): boolean { - if (this.state === ClientState.ServerError) { - this.messageService.error( - `Could not establish connection to ${this.id} glsp server. Maybe the server has been shutdown due to a previous error.` - ); - } - return super.checkConnectionState(); - } } // eslint-disable-next-line no-redeclare diff --git a/packages/theia-integration/src/common/websocket-util.ts b/packages/theia-integration/src/common/websocket-util.ts index 2843dad..56eeb26 100644 --- a/packages/theia-integration/src/common/websocket-util.ts +++ b/packages/theia-integration/src/common/websocket-util.ts @@ -37,7 +37,7 @@ export interface WebSocketConnectionInfo { export function getWebSocketAddress(info: Partial): string | undefined { if ('path' in info && info.path !== undefined && 'port' in info && info.port !== undefined) { const protocol = info.protocol ?? 'ws'; - const host = info.host ?? 'localhost'; + const host = info.host ?? '127.0.0.1'; return `${protocol}://${host}:${info.port}/${info.path}`; } diff --git a/packages/theia-integration/src/node/glsp-socket-server-contribution.ts b/packages/theia-integration/src/node/glsp-socket-server-contribution.ts index d405f1f..a8bf46e 100644 --- a/packages/theia-integration/src/node/glsp-socket-server-contribution.ts +++ b/packages/theia-integration/src/node/glsp-socket-server-contribution.ts @@ -56,7 +56,8 @@ export namespace GLSPSocketServerContributionOptions { return { ...GLSPServerContributionOptions.createDefaultOptions(), socketConnectionOptions: { - port: NaN + port: NaN, + host: '127.0.0.1' } }; } diff --git a/packages/theia-integration/src/node/websocket-connection-forwarder.ts b/packages/theia-integration/src/node/websocket-connection-forwarder.ts index b49047a..00e93c0 100644 --- a/packages/theia-integration/src/node/websocket-connection-forwarder.ts +++ b/packages/theia-integration/src/node/websocket-connection-forwarder.ts @@ -54,7 +54,7 @@ export class WebSocketConnectionForwarder implements Disposable { connection.onClose(() => webSocket.close()), this.clientChannel.onMessage(msgProvider => { const buffer = msgProvider().readBytes(); - wrappedWebSocket.send(buffer); + wrappedWebSocket.send(this.decodeMessage(buffer)); }), connection.onClose(() => this.clientChannel.close()), Disposable.create(() => { @@ -72,11 +72,15 @@ export class WebSocketConnectionForwarder implements Disposable { // process initially received buffer messages this.initialChannelListener.dispose(); this.initialBufferStore.forEach(msg => { - wrappedWebSocket.send(msg); + wrappedWebSocket.send(this.decodeMessage(msg)); }); this.initialBufferStore = []; } + protected decodeMessage(buffer: Uint8Array): string { + return new TextDecoder().decode(buffer); + } + dispose(): void { this.toDispose.dispose(); } diff --git a/yarn.lock b/yarn.lock index 3f0d9a7..8affc7e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -978,11 +978,11 @@ integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== "@eclipse-glsp-examples/workflow-glsp@next": - version "1.1.0-next.42b06df.279" - resolved "https://registry.yarnpkg.com/@eclipse-glsp-examples/workflow-glsp/-/workflow-glsp-1.1.0-next.42b06df.279.tgz#05ab58749cb38e5ade5f1439d9702028d897b011" - integrity sha512-qOMNHBcQc3g7p/3dIuVBGWgF1AzckB54G+ynEcNGDKkopyVLrmxk1yzJrytDBKziSCGcRXmSGibh/fxaWVoAEg== + version "1.1.0-next.3d1b3e6.280" + resolved "https://registry.yarnpkg.com/@eclipse-glsp-examples/workflow-glsp/-/workflow-glsp-1.1.0-next.3d1b3e6.280.tgz#787d450860d52cf166996ec63e6b0b8351fed281" + integrity sha512-a96M5g2SBKR1NtZdjtiDv2PFjBOzCVUsj+nUcMOQFnbXe+yHfltDsWgV12caAy8JsDvBECzKsu/ChZddcpkceg== dependencies: - "@eclipse-glsp/client" "1.1.0-next.42b06df.279+42b06df" + "@eclipse-glsp/client" "1.1.0-next.3d1b3e6.280+3d1b3e6" balloon-css "^0.5.0" "@eclipse-glsp-examples/workflow-server-bundled@next": @@ -1011,12 +1011,12 @@ semver "^7.5.1" shelljs "^0.8.5" -"@eclipse-glsp/client@1.1.0-next.42b06df.279+42b06df", "@eclipse-glsp/client@next": - version "1.1.0-next.42b06df.279" - resolved "https://registry.yarnpkg.com/@eclipse-glsp/client/-/client-1.1.0-next.42b06df.279.tgz#f04f1e464aa5aa1dbc874f48a02e427da8d22155" - integrity sha512-Xv6cPI/9b43nntdg1YVSflu9y4Z61pFLYeEFtkr4TJ9D1n9zNW6ji3QOfLlzsx5iFcvcXQSng0ues0W48F7PHw== +"@eclipse-glsp/client@1.1.0-next.3d1b3e6.280+3d1b3e6", "@eclipse-glsp/client@next": + version "1.1.0-next.3d1b3e6.280" + resolved "https://registry.yarnpkg.com/@eclipse-glsp/client/-/client-1.1.0-next.3d1b3e6.280.tgz#0767de5184428677c1d6cb6ccf73ea26c45e957f" + integrity sha512-rSp1s16bw+71gvpDcU3AujSKlDGoWDHukBBjXnqbS2ckEfC/1nHI5/OCQmejzKD2zUJsJBnIIrXCD31GhM8oLg== dependencies: - "@eclipse-glsp/protocol" "1.1.0-next.42b06df.279+42b06df" + "@eclipse-glsp/protocol" "1.1.0-next.3d1b3e6.280+3d1b3e6" autocompleter "5.1.0" lodash "4.17.21" sprotty "~0.14.0" @@ -1108,10 +1108,10 @@ dependencies: prettier-plugin-packagejson "~2.4.3" -"@eclipse-glsp/protocol@1.1.0-next.42b06df.279+42b06df", "@eclipse-glsp/protocol@next": - version "1.1.0-next.42b06df.279" - resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-1.1.0-next.42b06df.279.tgz#b8ec860b4d99ffe73f1bc6b0821199a769f452c3" - integrity sha512-eWKnmXT5JhG8eu+jI6MKrGCRHxwOAw3O3S018Mznim5fXfC+x95QjObmsTaw1x/YEzoScy35s8TZVASIhqYSIg== +"@eclipse-glsp/protocol@1.1.0-next.3d1b3e6.280+3d1b3e6", "@eclipse-glsp/protocol@next": + version "1.1.0-next.3d1b3e6.280" + resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-1.1.0-next.3d1b3e6.280.tgz#cc3631ef02726be58e1c90cc3caa24e5327158e2" + integrity sha512-fbnnL5fypPpsPENCyS9tVFjPdWnM4RVO3l1ybY4wQ1cXWv5QqtN92PExt/tn6/UwYUKvIoPXYWcN8w10f4JM8Q== dependencies: sprotty-protocol "0.14.0-next.02bbac0.26" uuid "7.0.3" @@ -2702,14 +2702,14 @@ form-data "^4.0.0" "@types/node@*", "@types/node@>=10.0.0": - version "20.6.2" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.6.2.tgz#a065925409f59657022e9063275cd0b9bd7e1b12" - integrity sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw== + version "20.6.3" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.6.3.tgz#5b763b321cd3b80f6b8dde7a37e1a77ff9358dd9" + integrity sha512-HksnYH4Ljr4VQgEy2lTStbCKv/P590tmPe5HqOnv9Gprffgv5WXAY+Y5Gqniu0GGqeTCUdBnzC3QSrzPkBkAMA== "@types/node@16.x": - version "16.18.52" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.52.tgz#70c56b55d0d7e15fafa875127e95a92605c59c9b" - integrity sha512-sm2aph6cRSsTMFYFgI+RpPLunXO9ClJkpizUVdT7KmGeyfQ14xnjTMT/f3MHcfKqevXqGT6BgVFzW8wcEoDUtA== + version "16.18.53" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.53.tgz#21820fe4d5968aaf8071dabd1ee13d24ada1350a" + integrity sha512-vVmHeo4tpF8zsknALU90Hh24VueYdu45ZlXzYWFbom61YR4avJqTFDC3QlWzjuTdAv6/3xHaxiO9NrtVZXrkmw== "@types/normalize-package-data@^2.4.0": version "2.4.1" @@ -2832,9 +2832,9 @@ "@types/tar-stream" "*" "@types/tar-stream@*": - version "2.2.3" - resolved "https://registry.yarnpkg.com/@types/tar-stream/-/tar-stream-2.2.3.tgz#f17780c6628b27ade3cd8ff3be7deebb4480f462" - integrity sha512-if3mugZfjVkXOMZdFjIHySxY13r6GXPpyOlsDmLffvyI7tLz9wXE8BFjNivXsvUeyJ1KNlOpfLnag+ISmxgxPw== + version "3.1.0" + resolved "https://registry.yarnpkg.com/@types/tar-stream/-/tar-stream-3.1.0.tgz#b67783c27135d21ed6a29e1f9e4a49f32debf741" + integrity sha512-U05c7l6K5VdO1ZV+j3E0NJOX1hfJB497M1+QT2rXx2QqyMbEQJqBw3Utk9eUVnWPyLLqYKt5Ja1kPV1ejm6cZw== dependencies: "@types/node" "*" @@ -5092,9 +5092,9 @@ electron-rebuild@^3.2.7: yargs "^17.0.1" electron-to-chromium@^1.4.477: - version "1.4.525" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.525.tgz#614284f33901fbecd3e90176c0d60590cd939700" - integrity sha512-GIZ620hDK4YmIqAWkscG4W6RwY6gOx1y5J6f4JUQwctiJrqH2oxZYU4mXHi35oV32tr630UcepBzSBGJ/WYcZA== + version "1.4.526" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.526.tgz#1bcda5f2b8238e497c20fcdb41af5da907a770e2" + integrity sha512-tjjTMjmZAx1g6COrintLTa2/jcafYKxKoiEkdQOrVdbLaHh2wCt2nsAF8ZHweezkrP+dl/VG9T5nabcYoo0U5Q== elkjs@^0.7.1: version "0.7.1" @@ -6256,9 +6256,9 @@ glob@7.2.0: path-is-absolute "^1.0.0" glob@^10.2.2, glob@^10.2.5: - version "10.3.4" - resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.4.tgz#c85c9c7ab98669102b6defda76d35c5b1ef9766f" - integrity sha512-6LFElP3A+i/Q8XQKEvZjkEWEOTgAIALR9AO2rwT8bgPhDd1anmqDJDZ6lLddI4ehxxxR1S5RIqKe1uapMQfYaQ== + version "10.3.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.5.tgz#4c0e46b5bccd78ac42b06a7eaaeb9ee34062968e" + integrity sha512-bYUpUD7XDEHI4Q2O5a7PXGvyw4deKR70kHiDxzQbe925wbZknhOzUt2xBgTkYL6RBcVeXYuD9iNYeqoWbBZQnA== dependencies: foreground-child "^3.1.0" jackspeak "^2.0.3" @@ -6317,9 +6317,9 @@ globals@^11.1.0: integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== globals@^13.19.0: - version "13.21.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-13.21.0.tgz#163aae12f34ef502f5153cfbdd3600f36c63c571" - integrity sha512-ybyme3s4yy/t/3s35bewwXKOf7cvzfreG2lH0lZl0JB7I4GxRP2ghxOK/Nb9EkRXdbBXZLfq/p/0W2JUONB/Gg== + version "13.22.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-13.22.0.tgz#0c9fcb9c48a2494fbb5edbfee644285543eba9d8" + integrity sha512-H1Ddc/PbZHTDVJSnj8kWptIRSD6AM3pK+mKytuIVF4uoBV7rshFlhhvA58ceJ5wp3Er58w6zj7bykMpYXt3ETw== dependencies: type-fest "^0.20.2" @@ -10975,9 +10975,9 @@ terser-webpack-plugin@^5.3.7: terser "^5.16.8" terser@^5.16.8: - version "5.19.4" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.19.4.tgz#941426fa482bf9b40a0308ab2b3cd0cf7c775ebd" - integrity sha512-6p1DjHeuluwxDXcuT9VR8p64klWJKo1ILiy19s6C9+0Bh2+NWTX6nD9EPppiER4ICkHDVB1RkVpin/YW2nQn/g== + version "5.20.0" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.20.0.tgz#ea42aea62578703e33def47d5c5b93c49772423e" + integrity sha512-e56ETryaQDyebBwJIWYB2TT6f2EZ0fL0sW/JRXNMN26zZdKi2u/E/5my5lG6jNxym6qsrVXfFRmOdV42zlAgLQ== dependencies: "@jridgewell/source-map" "^0.3.3" acorn "^8.8.2" @@ -11476,9 +11476,9 @@ upath@2.0.1, upath@^2.0.1: integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w== update-browserslist-db@^1.0.11: - version "1.0.11" - resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940" - integrity sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA== + version "1.0.13" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz#3c5e4f5c083661bd38ef64b6328c26ed6c8248c4" + integrity sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg== dependencies: escalade "^3.1.1" picocolors "^1.0.0"