From cf23e0f222b047eb12e03edb8d593d75ca591cd9 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 29 Aug 2012 07:57:23 +0000
Subject: [PATCH] SP-239, SWE-6: bug fixed: Remove file part from URL to get
 the application URL

SVN: 26474
---
 .../web/client/application/ui/webapp/WebAppUrl.java | 12 +++++++++---
 .../client/application/ui/webapp/WebAppUrlTest.java | 13 ++++++++++++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
index 4b8a5240540..419a735f993 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
@@ -30,8 +30,8 @@ public class WebAppUrl
 
     private URLMethodWithParameters builder;
 
-    public WebAppUrl(String openbisProtocol, String openbisHost, String applicationURL,
-            String webAppCode, String sessionId)
+    public WebAppUrl(String openbisProtocol, String openbisHost, String url, String webAppCode,
+            String sessionId)
     {
         if (openbisProtocol == null)
         {
@@ -41,7 +41,7 @@ public class WebAppUrl
         {
             throw new IllegalArgumentException("OpenBIS host cannot be null");
         }
-        if (applicationURL == null)
+        if (url == null)
         {
             throw new IllegalArgumentException("OpenBIS applicationURL cannot be null");
         }
@@ -53,6 +53,12 @@ public class WebAppUrl
         {
             throw new IllegalArgumentException("Session id cannot be null");
         }
+        String applicationURL = url;
+        if (url.endsWith("/") == false)
+        {
+            int lastIndexFileDelim = url.lastIndexOf('/');
+            applicationURL = url.substring(0, lastIndexFileDelim + 1);
+        }
         builder =
                 new URLMethodWithParameters(openbisProtocol + "//" + openbisHost + applicationURL
                         + "webapp/" + webAppCode + "/");
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlTest.java
index 4fb09ffcaa0..29e12192869 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlTest.java
@@ -30,7 +30,7 @@ public class WebAppUrlTest
 {
 
     @Test
-    public void testUrlWithoutParameters()
+    public void testApplicationUrlWithoutParameters()
     {
         WebAppUrl url =
                 new WebAppUrl("http:", "localhost:8888", "/openbis/", "webapp1", "mysessionid");
@@ -39,6 +39,17 @@ public class WebAppUrlTest
                 url.toString());
     }
 
+    @Test
+    public void testFileUrlWithoutParameters()
+    {
+        WebAppUrl url =
+                new WebAppUrl("http:", "localhost:8888", "/openbis/index.html", "webapp1",
+                        "mysessionid");
+        assertEquals(
+                "http://localhost:8888/openbis/webapp/webapp1/?webapp-code=webapp1&session-id=mysessionid",
+                url.toString());
+    }
+
     @Test
     public void testUrlWithNullParameters()
     {
-- 
GitLab