From ca710ebac004dbb9c4f588129f1ba9c616e9f0a7 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 14 Jul 2016 17:08:33 -0700 Subject: [PATCH 1/2] Sync Java runtime with changes in SDK (#1270) * Sync runtime with SDK repo * Reconstruct subtree * Squashed 'src/client/Java/' content from commit 3596f48 git-subtree-dir: src/client/Java git-subtree-split: 3596f488136a865d9ed36f85bc9c181c7138b035 --- .../main/java/com/microsoft/azure/RestClient.java | 13 ++++++------- build-tools/src/main/resources/checkstyle.xml | 1 - .../main/java/com/microsoft/rest/ServiceClient.java | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/RestClient.java b/azure-client-runtime/src/main/java/com/microsoft/azure/RestClient.java index 2cd137953fe7b..0ace881f0ee51 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/RestClient.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/RestClient.java @@ -14,6 +14,12 @@ import com.microsoft.rest.credentials.ServiceClientCredentials; import com.microsoft.rest.retry.RetryHandler; import com.microsoft.rest.serializer.JacksonMapperAdapter; +import okhttp3.ConnectionPool; +import okhttp3.Interceptor; +import okhttp3.JavaNetCookieJar; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import retrofit2.Retrofit; import java.lang.reflect.Field; import java.net.CookieManager; @@ -22,13 +28,6 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import okhttp3.ConnectionPool; -import okhttp3.Interceptor; -import okhttp3.JavaNetCookieJar; -import okhttp3.OkHttpClient; -import okhttp3.logging.HttpLoggingInterceptor; -import retrofit2.Retrofit; - /** * An instance of this class stores the client information for making REST calls. */ diff --git a/build-tools/src/main/resources/checkstyle.xml b/build-tools/src/main/resources/checkstyle.xml index 1875d6f100cab..b7f934898253c 100644 --- a/build-tools/src/main/resources/checkstyle.xml +++ b/build-tools/src/main/resources/checkstyle.xml @@ -231,7 +231,6 @@ --> - diff --git a/client-runtime/src/main/java/com/microsoft/rest/ServiceClient.java b/client-runtime/src/main/java/com/microsoft/rest/ServiceClient.java index 8311a243de139..5d6f0f850336c 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/ServiceClient.java +++ b/client-runtime/src/main/java/com/microsoft/rest/ServiceClient.java @@ -40,6 +40,9 @@ protected ServiceClient(String baseUrl) { /** * Initializes a new instance of the ServiceClient class. * + * @param baseUrl the service base uri + * @param clientBuilder the http client builder + * @param restBuilder the retrofit rest client builder */ protected ServiceClient(String baseUrl, OkHttpClient.Builder clientBuilder, Retrofit.Builder restBuilder) { if (clientBuilder == null) { From 4660eff3a89264a2199fe8780bb34c576f17b1e8 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 14 Jul 2016 17:33:09 -0700 Subject: [PATCH 2/2] Add HTTPS as default scheme --- .../java/com/microsoft/rest/BaseUrlHandler.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/client-runtime/src/main/java/com/microsoft/rest/BaseUrlHandler.java b/client-runtime/src/main/java/com/microsoft/rest/BaseUrlHandler.java index 46eacbd472e23..6d596c092e141 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/BaseUrlHandler.java +++ b/client-runtime/src/main/java/com/microsoft/rest/BaseUrlHandler.java @@ -7,13 +7,13 @@ package com.microsoft.rest; -import java.io.IOException; - import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; +import java.io.IOException; + /** * Handles dynamic replacements on base URL. The arguments must be in pairs * with the string in raw URL to replace as replacements[i] and the dynamic @@ -34,6 +34,7 @@ public Response intercept(Chain chain) throws IOException { for (int i = 0; i < replacements.length; i += 2) { baseUrl = baseUrl.replaceAll("(?i)\\Q" + replacements[i] + "\\E", replacements[i + 1]); } + baseUrl = removeRedundantProtocol(baseUrl); HttpUrl baseHttpUrl = HttpUrl.parse(baseUrl); request = request.newBuilder() .url(baseHttpUrl) @@ -42,4 +43,12 @@ public Response intercept(Chain chain) throws IOException { } return chain.proceed(request); } + + private String removeRedundantProtocol(String url) { + int last = url.lastIndexOf("://") - 1; + while (last >= 0 && Character.isLetter(url.charAt(last))) { + --last; + } + return url.substring(last + 1); + } }