jacek-lewandowski commented on code in PR #2458:
URL: https://github.com/apache/cassandra/pull/2458#discussion_r1259492824


##########
src/java/org/apache/cassandra/locator/AbstractCloudMetadataServiceConnector.java:
##########
@@ -22,25 +22,55 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Map;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 
+import org.apache.cassandra.exceptions.ConfigurationException;
+
 import static java.nio.charset.StandardCharsets.UTF_8;
 
 abstract class AbstractCloudMetadataServiceConnector
 {
+    static final String METADATA_URL_PROPERTY = "metadata_url";
+
+    public static class DefaultCloudMetadataServiceConnector extends 
AbstractCloudMetadataServiceConnector
+    {
+        protected DefaultCloudMetadataServiceConnector(String 
metadataServiceUrl)
+        {
+            super(metadataServiceUrl);
+        }
+    }
+
     protected final String metadataServiceUrl;
 
+    @VisibleForTesting // for mockito
+    protected String getMetadataServiceUrl()
+    {
+        return metadataServiceUrl;
+    }
+
     protected AbstractCloudMetadataServiceConnector(String metadataServiceUrl)
     {
+        try
+        {
+            URL url = new URL(metadataServiceUrl);
+            url.toURI();
+        }
+        catch (MalformedURLException | IllegalArgumentException | 
URISyntaxException ex)
+        {
+            throw new ConfigurationException(String.format("URL you provided 
(%s) is not valid!", metadataServiceUrl), ex);
+        }
         this.metadataServiceUrl = metadataServiceUrl;
     }
 
     public String apiCall(String query) throws IOException
     {
-        return apiCall(metadataServiceUrl, query, 200);
+        return apiCall(getMetadataServiceUrl(), query, 200);
     }
 
     public String apiCall(String url, String query, int expectedResponseCode) 
throws IOException

Review Comment:
   I think this method should be converted into:
   
   ```
   apiCall(String query, Map<String, String> extraHeaders)
   ```
   
   and then used, for example in Google snitch. 
   
   In general, we should avoid using `apiCall` which accepts url - it should be 
reserved only for extensions. That is, the other `apiCall` overloads should be 
made final. 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to