diff --git a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/web.xml b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/web.xml index 804ac84a7f..9b11592c52 100644 --- a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/web.xml +++ b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/web.xml @@ -23,7 +23,7 @@ org.eclipse.che.websocket.endpoint - /ws/{ws-id} + /ws org.eclipse.che.eventbus.endpoint diff --git a/dashboard/src/app/ide/ide.service.ts b/dashboard/src/app/ide/ide.service.ts index 0db1849689..9c15f561ce 100644 --- a/dashboard/src/app/ide/ide.service.ts +++ b/dashboard/src/app/ide/ide.service.ts @@ -73,7 +73,7 @@ class IdeSvc { this.updateRecentWorkspace(workspace.id); - let bus = this.cheAPI.getWebsocket().getBus(workspace.id); + let bus = this.cheAPI.getWebsocket().getBus(); let startWorkspaceDefer = this.$q.defer(); this.startWorkspace(bus, workspace).then(() => { @@ -279,7 +279,7 @@ class IdeSvc { websocketStream.close(); } - let workspaceBus = this.cheAPI.getWebsocket().getBus(workspaceId); + let workspaceBus = this.cheAPI.getWebsocket().getBus(); if (workspaceBus != null) { this.listeningChannels.forEach((channel) => { diff --git a/dashboard/src/app/projects/create-project/create-project.controller.ts b/dashboard/src/app/projects/create-project/create-project.controller.ts index 670aaed7a3..8fd3a7dd0c 100755 --- a/dashboard/src/app/projects/create-project/create-project.controller.ts +++ b/dashboard/src/app/projects/create-project/create-project.controller.ts @@ -221,7 +221,7 @@ export class CreateProjectController { //check current workspace if (findWorkspace) { // init WS bus - this.messageBus = this.cheAPI.getWebsocket().getBus(findWorkspace.id); + this.messageBus = this.cheAPI.getWebsocket().getBus(); } else { this.resetCreateProgress(); } @@ -914,7 +914,7 @@ export class CreateProjectController { }); } else { this.subscribeStatusChannel(workspace); - let bus = this.cheAPI.getWebsocket().getBus(workspace.id); + let bus = this.cheAPI.getWebsocket().getBus(); this.startWorkspace(bus, workspace); } } @@ -945,7 +945,7 @@ export class CreateProjectController { let promiseWorkspace = this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id); promiseWorkspace.then(() => { let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id), - bus = this.cheAPI.getWebsocket().getBus(workspace.id); + bus = this.cheAPI.getWebsocket().getBus(); // try to connect this.websocketReconnect = 10; this.connectToExtensionServer(websocketUrl, workspace.id, this.importProjectData.project.name, this.importProjectData, bus); @@ -974,7 +974,7 @@ export class CreateProjectController { // init message bus if not there if (this.workspaces.length === 0) { - this.messageBus = this.cheAPI.getWebsocket().getBus(workspace.id); + this.messageBus = this.cheAPI.getWebsocket().getBus(); } this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id).then(() => { @@ -982,7 +982,7 @@ export class CreateProjectController { }); this.$timeout(() => { - let bus = this.cheAPI.getWebsocket().getBus(workspace.id); + let bus = this.cheAPI.getWebsocket().getBus(); this.startWorkspace(bus, workspace); }, 1000); diff --git a/dashboard/src/app/workspaces/workspace-details/export-workspace/dialog/export-workspace-dialog.controller.ts b/dashboard/src/app/workspaces/workspace-details/export-workspace/dialog/export-workspace-dialog.controller.ts index 2d4c6e27cb..3241f05a1c 100644 --- a/dashboard/src/app/workspaces/workspace-details/export-workspace/dialog/export-workspace-dialog.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/export-workspace/dialog/export-workspace-dialog.controller.ts @@ -173,7 +173,7 @@ export class ExportWorkspaceDialogController { // compute WS url let remoteURL = authData.url; - let remoteWsURL = remoteURL.replace('http', 'ws') + '/api/ws/'; + let remoteWsURL = remoteURL.replace('http', 'ws') + '/api/ws'; let startWorkspacePromise = remoteWorkspaceAPI.startWorkspace(remoteWsURL, remoteWorkspace.id, remoteWorkspace.config.defaultEnv); diff --git a/dashboard/src/components/api/che-websocket.factory.ts b/dashboard/src/components/api/che-websocket.factory.ts index 2137889d8d..2a2ec4ea5d 100644 --- a/dashboard/src/components/api/che-websocket.factory.ts +++ b/dashboard/src/components/api/che-websocket.factory.ts @@ -32,7 +32,7 @@ export class CheWebsocket { if (inDevMode) { // it handle then http and https - wsUrl = proxySettings.replace('http', 'ws') + '/api/ws/'; + wsUrl = proxySettings.replace('http', 'ws') + '/api/ws'; } else { var wsProtocol; @@ -42,10 +42,11 @@ export class CheWebsocket { wsProtocol = 'wss'; } - wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws/'; + wsUrl = wsProtocol + '://' + $location.host() + ':' + $location.port() + '/api/ws'; } this.wsBaseUrl = wsUrl; - this.sockets = new Map(); + this.bus = null; + this.remoteBus = null; } @@ -54,34 +55,25 @@ export class CheWebsocket { } - getBus(workspaceId) { - var currentBus = this.sockets.get(workspaceId); - if (!currentBus) { + getBus() { + if (!this.bus) { // needs to initialize - var url = this.wsBaseUrl + workspaceId; - var dataStream = this.$websocket(url); - var bus = new MessageBus(dataStream, this.$interval); - this.sockets.set(workspaceId, bus); - currentBus = bus; + this.bus = new MessageBus(this.$websocket(this.wsBaseUrl), this.$interval); } - return currentBus; + return this.bus; } /** * Gets a bus for a remote worksace, by providing the remote URL to this websocket * @param websocketURL the remote host base WS url - * @param workspaceId the workspaceID used as suffix for the URL */ - getRemoteBus(websocketURL, workspaceId) { - var currentBus = this.sockets.get(workspaceId); - if (!currentBus) { - var dataStream = this.$websocket(websocketURL + workspaceId); - var bus = new MessageBus(dataStream, this.$interval); - this.sockets.set(workspaceId, bus); - currentBus = bus; + getRemoteBus(websocketURL) { + if (!this.remoteBus) { + // needs to initialize + this.remoteBus = new MessageBus(this.$websocket(websocketURL), this.$interval); } - return currentBus; + return this.remoteBus; } } diff --git a/dashboard/src/components/api/che-workspace.factory.ts b/dashboard/src/components/api/che-workspace.factory.ts index 371d890ebc..39106e9002 100644 --- a/dashboard/src/components/api/che-workspace.factory.ts +++ b/dashboard/src/components/api/che-workspace.factory.ts @@ -47,8 +47,8 @@ export class CheWorkspace { // listeners if workspaces are changed/updated this.listeners = []; - // list of websocket bus per workspace - this.websocketBusByWorkspaceId = new Map(); + // list of subscribed to websocket workspace Ids + this.subscribedWorkspacesIds = []; this.statusDefers = {}; // remote call @@ -474,9 +474,9 @@ export class CheWorkspace { * @param workspaceId */ startUpdateWorkspaceStatus(workspaceId) { - if (!this.websocketBusByWorkspaceId.has(workspaceId)) { - let bus = this.cheWebsocket.getBus(workspaceId); - this.websocketBusByWorkspaceId.set(workspaceId, bus); + if (!this.subscribedWorkspacesIds.includes(workspaceId)) { + let bus = this.cheWebsocket.getBus(); + this.subscribedWorkspacesIds.push(workspaceId); bus.subscribe('workspace:' + workspaceId, (message) => { diff --git a/dashboard/src/components/api/remote/che-remote-workspace.ts b/dashboard/src/components/api/remote/che-remote-workspace.ts index 4de00f8548..fb2c6fb1df 100644 --- a/dashboard/src/components/api/remote/che-remote-workspace.ts +++ b/dashboard/src/components/api/remote/che-remote-workspace.ts @@ -70,7 +70,7 @@ export class CheRemoteWorkspace { let deferred = this.$q.defer(); let deferredPromise = deferred.promise; - let bus = this.cheWebsocket.getRemoteBus(remoteWsURL, workspaceId); + let bus = this.cheWebsocket.getRemoteBus(remoteWsURL); // subscribe to workspace events bus.subscribe('workspace:' + workspaceId, (message) => { if (message.eventType === 'RUNNING' && message.workspaceId === workspaceId) { diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java index 59d0d87817..e3f2e60b59 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java @@ -173,7 +173,7 @@ public abstract class WorkspaceComponent implements Component, WsAgentStateHandl if (messageBus != null) { messageBus.cancelReconnection(); } - messageBus = messageBusProvider.createMessageBus(workspace.getId()); + messageBus = messageBusProvider.createMessageBus(); messageBus.addOnOpenHandler(new ConnectionOpenedHandler() { @Override diff --git a/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusImpl.java b/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusImpl.java index 378d58696b..44584c8388 100644 --- a/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusImpl.java +++ b/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusImpl.java @@ -21,8 +21,8 @@ import static com.google.gwt.user.client.Window.Location.getProtocol; */ public class MessageBusImpl extends AbstractMessageBus { - public MessageBusImpl(String workspaceId) { - super((getProtocol().equals("https:") ? "wss://" : "ws://") + getHost() + getRestContext() + "/ws/" + workspaceId); + public MessageBusImpl() { + super((getProtocol().equals("https:") ? "wss://" : "ws://") + getHost() + getRestContext() + "/ws"); } private static native String getRestContext() /*-{ diff --git a/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusProvider.java b/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusProvider.java index 14f5bd3a26..9942f21a70 100644 --- a/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusProvider.java +++ b/ide/commons-gwt/src/main/java/org/eclipse/che/ide/websocket/MessageBusProvider.java @@ -37,12 +37,10 @@ public class MessageBusProvider { * Creates new instance of {@link MessageBusImpl} and connects to web socket via special url. The method returns new * instance each time it is called. Message bus is created only one time when we start workspace. * - * @param workspaceId - * workspace id which need for path to connect to web socket * @return instance of {@link MessageBusImpl} */ - public MessageBus createMessageBus(String workspaceId) { - this.messageBus = new MessageBusImpl(workspaceId); + public MessageBus createMessageBus() { + this.messageBus = new MessageBusImpl(); return messageBus; }