From 7e028dba52c077823e9cd232f49ad9bba21082ce Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Wed, 19 Apr 2023 14:21:45 +0800 Subject: [PATCH] Fixup cache encoding (#64) * Fixup cache encoding --- .../visualvm/helper/HttpRequestSender.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java index a7b6a8f..8cafc74 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/HttpRequestSender.java @@ -37,9 +37,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.util.ArrayList; @@ -311,7 +314,7 @@ public Set getCacheMembers(String sServiceName, String sCacheName, S { URLBuilder urlBuilder = getBasePath().addPathSegment(SERVICES) .addPathSegment(encodeServiceName(sServiceName)).addPathSegment(CACHES) - .addPathSegment(sCacheName).addPathSegment(MEMBERS); + .addPathSegment(encodeCacheName(sCacheName)).addPathSegment(MEMBERS); if (sDomainPartition != null) { urlBuilder.addQueryParameter("domainPartition", sDomainPartition); @@ -986,7 +989,7 @@ public JsonNode getDataForStorageManagerMembers(String sServiceName, String sDom throws Exception { URLBuilder urlBuilder = getBasePath().addPathSegment(SERVICES) - .addPathSegment(encodeServiceName(sServiceName)).addPathSegment(CACHES).addPathSegment(sCacheName) + .addPathSegment(encodeServiceName(sServiceName)).addPathSegment(CACHES).addPathSegment(encodeCacheName(sCacheName)) .addPathSegment(MEMBERS).addQueryParameter(FIELDS, "nodeId,locksGranted,locksPending,listenerRegistrations,maxQueryDurationMillis,maxQueryDescription," + "nonOptimizedQueryAverageMillis,optimizedQueryAverageMillis,indexTotalUnits,indexingTotalMillis," + @@ -1016,7 +1019,7 @@ public JsonNode getDataForCacheMembers(String sServiceName, String sCacheName, S throws Exception { URLBuilder urlBuilder = getBasePath().addPathSegment(SERVICES) - .addPathSegment(encodeServiceName(sServiceName)).addPathSegment(CACHES).addPathSegment(sCacheName) + .addPathSegment(encodeServiceName(sServiceName)).addPathSegment(CACHES).addPathSegment(encodeCacheName(sCacheName)) .addPathSegment(MEMBERS); if (sDomainPartition != null) { @@ -1817,6 +1820,24 @@ private String encodeServiceName(String sServiceName) return sServiceName.replaceAll("\"", ""); } + /** + * Encode a cache name. + * + * @param sCacheName service name to encode + * @return encoded cache name + */ + private String encodeCacheName(String sCacheName) + { + try + { + return URLEncoder.encode(sCacheName, "UTF8"); + } + catch (UnsupportedEncodingException e) + { + return sCacheName; + } + } + /** * Internal class to build a URL. */