Repository: odpi/egeria-connector-ibm-information-server
Issue: Certain RIDs are not properly path-encoded

There are certain RID formats that can exist, which currently are not URL path-encoded and therefore may cause issues with being interpreted by the REST endpoints.

Examples:

- virtual assets (eg. `extern:fr:7599ac3c8e0d4869b032d151e8ffc86d`)
- embedded columns (eg. `deflated:c2e76d84.78bf4d29.66k77fg69.pm57036.72jftc.1a947bnehtr3q8ajjieqj;column_id;-2855024043478117416`)

Changed files:
test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockConstants.java
igc-clientlibrary/src/main/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/IGCRestClient.java
igc-clientlibrary/src/test/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/ClientTest.java
test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockServerExpectations.java

diff --git a/igc-clientlibrary/src/main/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/IGCRestClient.java b/igc-clientlibrary/src/main/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/IGCRestClient.java
index 1b41f81f..799ef8c9 100644
--- a/igc-clientlibrary/src/main/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/IGCRestClient.java
+++ b/igc-clientlibrary/src/main/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/IGCRestClient.java
@@ -3,7 +3,6 @@
 package org.odpi.egeria.connectors.ibm.igc.clientlibrary;
 
 import java.io.*;
-import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.regex.Matcher;
@@ -47,6 +46,7 @@ import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.util.UriComponents;
 import org.springframework.web.util.UriComponentsBuilder;
+import org.springframework.web.util.UriUtils;
 
 /**
  * Library of methods to connect to and interact with an IBM Information Governance Catalog environment
@@ -672,7 +672,19 @@ public class IGCRestClient {
      * @return Reference - the IGC object representing the asset
      */
     public Reference getAssetById(String rid) {
-        return readJSONIntoPOJO(makeRequest(EP_ASSET + "/" + rid, HttpMethod.GET, null,null));
+        String url = EP_ASSET + "/" + getEncodedPathVariable(rid);
+        String response = makeRequest(url, HttpMethod.GET, null, null);
+        return readJSONIntoPOJO(response);
+    }
+
+    /**
+     * Calculate a path-encoded URL for the provided endpoint.
+     *
+     * @param pathVariable the value within the path to encode
+     * @return String - the encoded endpoint
+     */
+    public static String getEncodedPathVariable(String pathVariable) {
+        return UriUtils.encode(pathVariable, "UTF-8");
     }
 
     /**
@@ -1083,8 +1095,8 @@ public class IGCRestClient {
                     // On v11.5, for virtual assets, the paging URL only has the RID and nothing else -- we must
                     // reconstruct an appropriate paging URL from just this RID and the other parameters received by
                     // the method
-                    requestUrl = EP_ASSET + "/" + sNextURL
-                            + "/" + URLEncoder.encode(propertyName, "UTF-8")
+                    requestUrl = EP_ASSET + "/" + getEncodedPathVariable(sNextURL)
+                            + "/" + getEncodedPathVariable(propertyName)
                             + "?begin=" + (paging.getEndIndex() + 1)
                             + "&pageSize=" + paging.getPageSize();
                 } else {
diff --git a/igc-clientlibrary/src/test/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/ClientTest.java b/igc-clientlibrary/src/test/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/ClientTest.java
index ea8caf96..2f16355b 100644
--- a/igc-clientlibrary/src/test/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/ClientTest.java
+++ b/igc-clientlibrary/src/test/java/org/odpi/egeria/connectors/ibm/igc/clientlibrary/ClientTest.java
@@ -17,6 +17,7 @@ import org.odpi.egeria.connectors.ibm.information.server.mocks.MockConstants;
 import org.odpi.openmetadata.http.HttpHelper;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.FileSystemResource;
+import org.springframework.web.util.UriUtils;
 import org.testng.annotations.*;
 
 import java.io.File;
@@ -391,6 +392,15 @@ public class ClientTest {
 
     }
 
+    @Test
+    public void testRIDEncoding() {
+
+        String rid = "deflated:c2e76d84.78bf4d29.66k77fg69.pm57036.72jftc.1a947bnehtr3q8ajjieqj;column_id;-2855024043478117416";
+        String encoded = igcRestClient.getEncodedPathVariable(rid);
+        assertEquals(encoded, "deflated%3Ac2e76d84.78bf4d29.66k77fg69.pm57036.72jftc.1a947bnehtr3q8ajjieqj%3Bcolumn_id%3B-2855024043478117416");
+
+    }
+
     @AfterSuite
     void stopClient() {
         igcRestClient.disconnect();
diff --git a/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockConstants.java b/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockConstants.java
index 9ea454f8..70efc5e7 100644
--- a/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockConstants.java
+++ b/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockConstants.java
@@ -38,6 +38,7 @@ public class MockConstants {
 
     // RIDs used for specific scenarios to test IGC mappers
     public static final String VIRTUAL_ASSET_TABLE_RID = "extern:fr:7599ac3c8e0d4869b032d151e8ffc86d";
+    public static final String VIRTUAL_ASSET_TABLE_RID_ENCODED = "extern%3Afr%3A7599ac3c8e0d4869b032d151e8ffc86d";
     public static final String NOTE_RID = "b1c497ce.1a21c74f.00270nau6.74dr5d1.dg30je.1sa0foiromdmt9c4ga8v2";
     public static final String TERM_WITH_NOTES_RID = "6662c0f2.e1b1ec6c.00270n9bc.9a0o5ur.hsbem7.o7tuf0mn7hgv85dv4s707";
     public static final String CATEGORY_RID = "6662c0f2.ee6a64fe.o1h6evehs.j0f25pn.ihsrb3.m7984f1jgfencf15nopk0";
diff --git a/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockServerExpectations.java b/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockServerExpectations.java
index b35bceaa..2fa774bd 100644
--- a/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockServerExpectations.java
+++ b/test/src/main/java/org/odpi/egeria/connectors/ibm/information/server/mocks/MockServerExpectations.java
@@ -436,7 +436,7 @@ public class MockServerExpectations implements PluginExpectationInitializer {
 
     private void setVirtualAssets(MockServerClient mockServerClient) {
         String caseName = "VirtualAssets";
-        String rid = MockConstants.VIRTUAL_ASSET_TABLE_RID;
+        String rid = MockConstants.VIRTUAL_ASSET_TABLE_RID_ENCODED;
         mockServerClient
                 .withSecure(true)
                 .when(assetByRidRequest(rid))
@@ -663,7 +663,7 @@ public class MockServerExpectations implements PluginExpectationInitializer {
             String rid = getRidFromFilename(filename);
             mockServerClient
                     .withSecure(true)
-                    .when(assetByRidRequest("extern:fr:" + rid))
+                    .when(assetByRidRequest("extern%3Afr%3A" + rid))
                     .respond(withResponse(getResourceFileContents("virtual_by_rid" + File.separator + rid + ".json")));
         }
     }