Skip to content

Commit

Permalink
Fix request id to be generated each time
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed May 17, 2016
1 parent 41224f8 commit 29d8857
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public String getBaseUrl() {
* @return a builder for the rest client.
*/
public RestClient.Builder newRestClientBuilder() {
return new RestClient.Builder(baseURL).withMapperAdapter(new AzureJacksonMapperAdapter());
return new RestClient.Builder(baseURL)
.withInterceptor(new RequestIdHeaderInterceptor())
.withMapperAdapter(new AzureJacksonMapperAdapter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public abstract class AzureServiceClient extends ServiceClient {
protected AzureServiceClient(String baseUrl) {
this(new RestClient.Builder(baseUrl)
.withInterceptor(new RequestIdHeaderInterceptor())
.withMapperAdapter(new AzureJacksonMapperAdapter()).build());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*
*/

package com.microsoft.azure;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.UUID;

/**
* An instance of this class puts an UUID in the request header. Azure uses
* the request id as the unique identifier for
*/
public class RequestIdHeaderInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.header("x-ms-client-request-id", UUID.randomUUID().toString())
.build();
return chain.proceed(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public Builder(String baseUrl, OkHttpClient.Builder httpClientBuilder, Retrofit.
// Set up OkHttp client
this.httpClientBuilder = httpClientBuilder
.cookieJar(new JavaNetCookieJar(cookieManager))
.addInterceptor(new RetryHandler())
.addInterceptor(new UserAgentInterceptor());
// Set up rest adapter
this.retrofitBuilder = retrofitBuilder.baseUrl(baseUrl);
Expand Down Expand Up @@ -256,6 +255,7 @@ public RestClient build() {
OkHttpClient httpClient = httpClientBuilder
.addInterceptor(baseUrlHandler)
.addInterceptor(customHeadersInterceptor)
.addInterceptor(new RetryHandler())
.build();
return new RestClient(httpClient,
retrofitBuilder
Expand Down

0 comments on commit 29d8857

Please sign in to comment.