use of com.microsoft.rest.interceptors.RequestIdHeaderInterceptor in project autorest-clientruntime-for-java by Azure.
the class RequestIdHeaderInterceptorTests method sameRequestIdForRetry.
@Test
public void sameRequestIdForRetry() throws Exception {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new RequestIdHeaderInterceptor()).withInterceptor(new RetryHandler()).withInterceptor(new Interceptor() {
private String firstRequestId = null;
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (request.header(REQUEST_ID_HEADER) != null) {
if (firstRequestId == null) {
firstRequestId = request.header(REQUEST_ID_HEADER);
return new Response.Builder().code(500).request(request).protocol(Protocol.HTTP_1_1).build();
} else if (request.header(REQUEST_ID_HEADER).equals(firstRequestId)) {
return new Response.Builder().code(200).request(request).protocol(Protocol.HTTP_1_1).build();
}
}
return new Response.Builder().code(400).request(request).protocol(Protocol.HTTP_1_1).build();
}
}).build();
AzureServiceClient serviceClient = new AzureServiceClient(restClient) {
};
Response response = serviceClient.restClient().httpClient().newCall(new Request.Builder().get().url("http://localhost").build()).execute();
Assert.assertEquals(200, response.code());
}
use of com.microsoft.rest.interceptors.RequestIdHeaderInterceptor in project autorest-clientruntime-for-java by Azure.
the class RequestIdHeaderInterceptorTests method newRequestIdForEachCall.
@Test
public void newRequestIdForEachCall() throws Exception {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new RequestIdHeaderInterceptor()).withInterceptor(new Interceptor() {
private String firstRequestId = null;
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (request.header(REQUEST_ID_HEADER) != null) {
if (firstRequestId == null) {
firstRequestId = request.header(REQUEST_ID_HEADER);
return new Response.Builder().code(200).request(request).protocol(Protocol.HTTP_1_1).build();
} else if (!request.header(REQUEST_ID_HEADER).equals(firstRequestId)) {
return new Response.Builder().code(200).request(request).protocol(Protocol.HTTP_1_1).build();
}
}
return new Response.Builder().code(400).request(request).protocol(Protocol.HTTP_1_1).build();
}
}).build();
AzureServiceClient serviceClient = new AzureServiceClient(restClient) {
};
Response response = serviceClient.restClient().httpClient().newCall(new Request.Builder().get().url("http://localhost").build()).execute();
Assert.assertEquals(200, response.code());
response = serviceClient.restClient().httpClient().newCall(new Request.Builder().get().url("http://localhost").build()).execute();
Assert.assertEquals(200, response.code());
}
use of com.microsoft.rest.interceptors.RequestIdHeaderInterceptor in project autorest.java by Azure.
the class SubscriptionInMethodTests method setup.
@BeforeClass
public static void setup() {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost:3000").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(new TokenCredentials(null, UUID.randomUUID().toString())).withInterceptor(new RequestIdHeaderInterceptor()).build();
client = new AutoRestAzureSpecialParametersTestClientImpl(restClient);
client.withSubscriptionId("1234-5678-9012-3456");
}
use of com.microsoft.rest.interceptors.RequestIdHeaderInterceptor in project autorest.java by Azure.
the class SubscriptionInCredentialsTests method setup.
@BeforeClass
public static void setup() {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost:3000").withCredentials(new TokenCredentials(null, UUID.randomUUID().toString())).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new RequestIdHeaderInterceptor()).build();
client = new AutoRestAzureSpecialParametersTestClientImpl(restClient);
client.withSubscriptionId("1234-5678-9012-3456");
}
Aggregations