diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/BaseHPCCWsClient.java b/wsclient/src/main/java/org/hpccsystems/ws/client/BaseHPCCWsClient.java index 0dfe94b5e..2ee1461a9 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/BaseHPCCWsClient.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/BaseHPCCWsClient.java @@ -1,6 +1,7 @@ package org.hpccsystems.ws.client; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -159,24 +160,44 @@ private String getTargetHPCCBuildVersionString() throws Exception if (wsconn == null) throw new Exception("Cannot get target HPCC build version, client connection has not been initialized."); - String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws + String response = wsconn.sendGetRequest("WsSMC/Activity?rawxml_");//throws IOException if http != ok if (response == null || response.isEmpty()) throw new Exception("Cannot get target HPCC build version, received empty " + wsconn.getBaseUrl() + " wssmc/activity response"); + String header = response.substring(0, 100).trim(); //crude, but can prevent wasteful overhead + if (header.startsWith(" 0 && postfixPath.charAt(0) == slash) + prefixPath = prefixPath + postfixPath.substring(1); + else + prefixPath = prefixPath + postfixPath; + + return prefixPath; + } + + /** + * Infers path style (linux/windows) based on presence of Linux separator + * @param path - the path + * @return - new path comprised of path prefix a path separator and path postfix + * @throws Exception - Invalid paths, indiscernible path style + */ + public static char inferPathSeperatorType(String path) throws Exception + { + if (path.length() == 0) + throw new Exception("Zero len path detected!"); + + return path.contains(Character.toString(LINUX_SEP)) ? LINUX_SEP : WIN_SEP; + } + /** * Removes trailing whitespace characters from a string. * diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java index eef268e47..99876b48a 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/utils/UtilsTest.java @@ -8,6 +8,35 @@ public class UtilsTest { + + @Test + public void testappendPathSections() throws Exception + { + //appendWindowsPathSections + assertEquals(Character.toString(Utils.WIN_SEP), Utils.appendWindowsPathSections("", "")); + assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some\\ ", " \\path\\")); + assertEquals("C:\\some\\path\\", Utils.appendWindowsPathSections("C:\\some", " path\\")); + + //appendLinuxPathSections + assertEquals(Character.toString(Utils.LINUX_SEP), Utils.appendLinuxPathSections("", "")); + assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path ", " relative/path")); + assertEquals("/root/path/relative/path", Utils.appendLinuxPathSections("/root/path/ ", " /relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendLinuxPathSections("/", " /relative/path")); + + //appendPathSections + assertEquals("/relative/path", Utils.appendPathSections("/", " /relative/path")); + assertEquals("/root/path/relative/path", Utils.appendPathSections("/root/path ", " relative/path")); + assertEquals("/root/path/relative/path", Utils.appendPathSections("/root/path/ ", " /relative/path")); + assertEquals("/relative/path", Utils.appendPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendPathSections("/ ", "/relative/path")); + assertEquals("/relative/path", Utils.appendPathSections("/", " /relative/path")); + + assertEquals("C:\\some\\path\\", Utils.appendPathSections("C:\\some\\ ", " \\path\\")); + assertEquals("C:\\some\\path", Utils.appendPathSections("C:\\some", " path")); + } + @Test public void testEnsureTrailingSlashTrailingWhiteSpace() {