use of com.microsoft.azure.serializer.AzureJacksonAdapter 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.azure.serializer.AzureJacksonAdapter 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.azure.serializer.AzureJacksonAdapter in project photon-model by vmware.
the class AzureSdkClients method buildRestClient.
/**
* Build Azure RestClient with specified executor service and credentials using
* {@link RestClient.Builder}.
*/
private static RestClient buildRestClient(ApplicationTokenCredentials credentials, ExecutorService executorService) {
final Retrofit.Builder retrofitBuilder;
{
retrofitBuilder = new Retrofit.Builder();
if (executorService != null) {
RxJavaCallAdapterFactory rxWithExecutorCallFactory = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.from(executorService));
retrofitBuilder.addCallAdapterFactory(rxWithExecutorCallFactory);
}
}
final RestClient.Builder restClientBuilder = new RestClient.Builder(new OkHttpClient.Builder(), retrofitBuilder);
restClientBuilder.withBaseUrl(AzureUtils.getAzureBaseUri());
restClientBuilder.withCredentials(credentials);
restClientBuilder.withSerializerAdapter(new AzureJacksonAdapter());
restClientBuilder.withLogLevel(getRestClientLogLevel());
restClientBuilder.withInterceptor(new ResourceManagerThrottlingInterceptor());
if (executorService != null) {
restClientBuilder.withCallbackExecutor(executorService);
}
restClientBuilder.withResponseBuilderFactory(new Factory());
return restClientBuilder.build();
}
use of com.microsoft.azure.serializer.AzureJacksonAdapter 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.azure.serializer.AzureJacksonAdapter in project autorest.java by Azure.
the class PagingTests method setup.
@BeforeClass
public static void setup() {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost:3000").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).build();
client = new AutoRestPagingTestServiceImpl(restClient);
;
}
Aggregations