goelrajat commented on a change in pull request #142: KNOX-1996: Adding changes 
to remove extra / while generating backedn …
URL: https://github.com/apache/knox/pull/142#discussion_r322075403
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java
 ##########
 @@ -173,12 +174,41 @@ private synchronized String getMatchedBackendURL(final 
String path) {
 
     /* URL used to connect to websocket backend */
     String backendURL = urlFromServiceDefinition(serviceRegistryService, 
entry, path);
+    LOG.logMessage("Url obtained from services definition: " + backendURL);
 
     StringBuilder backend = new StringBuilder();
     try {
-
-      /* if we do not find websocket URL we default to HTTP */
-      if (!StringUtils.containsAny(backendURL, WEBSOCKET_PROTOCOL_STRING, 
SECURE_WEBSOCKET_PROTOCOL_STRING)) {
+      if (StringUtils.containsAny(backendURL, WEBSOCKET_PROTOCOL_STRING, 
SECURE_WEBSOCKET_PROTOCOL_STRING)) {
+        LOG.logMessage("ws or wss protocol found in service url");
+        URI serviceUri = new URI(backendURL);
+        backend.append(serviceUri);
+        /* Avoid Zeppelin Regression - as this would require ambari changes 
and break current knox websocket use case*/
+        if (!StringUtils.endsWith(backend.toString(), "/ws") && 
!StringUtils.endsWith(backend.toString(), "/websocket")
+                   && pathService.length > 0 && pathService[1] != null) {
+          String newPathSuffix = pathService[1];
+          if ((backend.toString().endsWith("/")) && 
(pathService[1].startsWith("/"))) {
+            newPathSuffix = pathService[1].substring(1);
+          }
+          backend.append(newPathSuffix);
+        }
+      } else if (StringUtils.containsAny(requestURI.toString(), 
WEBSOCKET_PROTOCOL_STRING, SECURE_WEBSOCKET_PROTOCOL_STRING)) {
 
 Review comment:
   This is for enhancement mentioned in Jira comments: 'Adding changes to use 
'ws or wss' as protocol in case request URI is a websocket request but service 
definition in Knox is defined as 'http or https'. This is needed for our 
usecase where it is not feasible to define a separate Role/Service in Knox for 
websocket calls. My service uses SockJS library for websocket connection and 
websocket connections are initiated internally from within the library. URI for 
some of the HTTP calls is same as websocket calls except for the protocol.'

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to