You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2018/04/06 11:38:07 UTC

[ambari] branch trunk updated: AMBARI-23411 Invalid websocket client port when connected over https

This is an automated email from the ASF dual-hosted git repository.

atkach pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 49f93b1  AMBARI-23411 Invalid websocket client port when connected over https
49f93b1 is described below

commit 49f93b17903d803d8df430e50d8f2cd7604361ad
Author: Andrii Tkach <at...@apache.org>
AuthorDate: Fri Mar 30 13:21:27 2018 +0300

    AMBARI-23411 Invalid websocket client port when connected over https
---
 ambari-web/app/utils/stomp_client.js       | 39 ++++++++++++++++++++++--------
 ambari-web/test/utils/stomp_client_test.js |  9 +++++++
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/ambari-web/app/utils/stomp_client.js b/ambari-web/app/utils/stomp_client.js
index 36377c4..c8e47cf 100644
--- a/ambari-web/app/utils/stomp_client.js
+++ b/ambari-web/app/utils/stomp_client.js
@@ -39,12 +39,22 @@ module.exports = Em.Object.extend({
   /**
    * @type {string}
    */
-  webSocketUrl: '{protocol}://{hostname}:8080/api/stomp/v1/websocket',
+  webSocketUrl: '{protocol}://{hostname}:{port}/api/stomp/v1/websocket',
 
   /**
    * @type {string}
    */
-  sockJsUrl: '{protocol}://{hostname}:8080/api/stomp/v1',
+  sockJsUrl: '{protocol}://{hostname}:{port}/api/stomp/v1',
+
+  /**
+   * @const
+   */
+  PORT: '8080',
+
+  /**
+   * @const
+   */
+  SECURE_PORT: '8443',
 
   /**
    * sockJs should use only alternative options as transport in case when websocket supported but connection fails
@@ -106,23 +116,32 @@ module.exports = Em.Object.extend({
   /**
    *
    * @param {boolean} useSockJS
-   * @returns {*}
+   * @returns {SockJS|WebSocket}
    */
   getSocket: function(useSockJS) {
-    const hostname = window.location.hostname;
-    const isSecure = window.location.protocol === 'https:';
-
     if (!WebSocket || useSockJS) {
       this.set('isWebSocketSupported', false);
-      const protocol = isSecure ? 'https' : 'http';
-      const sockJsUrl = this.get('sockJsUrl').replace('{hostname}', hostname).replace('{protocol}', protocol);
+      const sockJsUrl = this.getSocketUrl(this.get('sockJsUrl'), false);
       return new SockJS(sockJsUrl, null, {transports: this.get('sockJsTransports')});
     } else {
-      const protocol = isSecure ? 'wss' : 'ws';
-      return new WebSocket(this.get('webSocketUrl').replace('{hostname}', hostname).replace('{protocol}', protocol));
+      return new WebSocket(this.getSocketUrl(this.get('webSocketUrl'), true));
     }
   },
 
+  /**
+   *
+   * @param {string} template
+   * @param {boolean} isWebsocket
+   * @returns {string}
+   */
+  getSocketUrl: function(template, isWebsocket) {
+    const hostname = window.location.hostname;
+    const isSecure = window.location.protocol === 'https:';
+    const protocol = isWebsocket ? (isSecure ? 'wss' : 'ws') : (isSecure ? 'https' : 'http');
+    const port = isSecure ? this.get('SECURE_PORT') : this.get('PORT');
+    return template.replace('{hostname}', hostname).replace('{protocol}', protocol).replace('{port}', port);
+  },
+
   onConnectionSuccess: function() {
     this.set('isConnected', true);
   },
diff --git a/ambari-web/test/utils/stomp_client_test.js b/ambari-web/test/utils/stomp_client_test.js
index 3f2e8ba..f816fc2 100644
--- a/ambari-web/test/utils/stomp_client_test.js
+++ b/ambari-web/test/utils/stomp_client_test.js
@@ -73,6 +73,15 @@ describe('App.StompClient', function () {
     });
   });
 
+  describe('#getSocketUrl', function() {
+    it('should return socket url for websocket', function() {
+      expect(stomp.getSocketUrl('{protocol}://{hostname}:{port}', true)).to.equal('ws://:8080');
+    });
+    it('should return socket url for sockjs', function() {
+      expect(stomp.getSocketUrl('{protocol}://{hostname}:{port}', false)).to.equal('http://:8080');
+    });
+  });
+
   describe('#onConnectionSuccess', function() {
     it('isConnected should be true', function() {
       stomp.onConnectionSuccess();

-- 
To stop receiving notification emails like this one, please contact
atkach@apache.org.