Java Code Examples for com.microsoft.rest.RestClient#Builder

The following examples show how to use com.microsoft.rest.RestClient#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderRegistrationInterceptor.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Response intercept(Chain chain) throws IOException {
    Response response = chain.proceed(chain.request());
    if (!response.isSuccessful()) {
        String content = Utils.getResponseBodyInString(response.body());
        AzureJacksonAdapter jacksonAdapter = new AzureJacksonAdapter();
        CloudError cloudError = jacksonAdapter.deserialize(content, CloudError.class);
        if (cloudError != null && "MissingSubscriptionRegistration".equals(cloudError.code())) {
            Pattern pattern = Pattern.compile("/subscriptions/([\\w-]+)/", Pattern.CASE_INSENSITIVE);
            Matcher matcher = pattern.matcher(chain.request().url().toString());
            matcher.find();
            RestClient.Builder restClientBuilder = new RestClient.Builder();
            restClientBuilder.withBaseUrl("https://" + chain.request().url().host())
                    .withCredentials(credentials)
                    .withSerializerAdapter(jacksonAdapter)
                    .withResponseBuilderFactory(new AzureResponseBuilder.Factory());
            if (credentials.proxy() != null) {
                restClientBuilder.withProxy(credentials.proxy());
            }
            RestClient restClient = restClientBuilder.build();
            ResourceManager resourceManager = ResourceManager.authenticate(restClient)
                    .withSubscription(matcher.group(1));
            pattern = Pattern.compile(".*'(.*)'");
            matcher = pattern.matcher(cloudError.message());
            matcher.find();
            Provider provider = registerProvider(matcher.group(1), resourceManager);
            while (provider.registrationState().equalsIgnoreCase("Unregistered")
                    || provider.registrationState().equalsIgnoreCase("Registering")) {
                SdkContext.sleep(5 * 1000);
                provider = resourceManager.providers().getByName(provider.namespace());
            }
            // Retry
            response = chain.proceed(chain.request());
        }
    }
    return response;
}
 
Example 2
Source File: SqlServerTest.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) {
    if (!isMocked) {
    return super.buildRestClient(builder.withReadTimeout(150, TimeUnit.SECONDS) , isMocked);
}
    return super.buildRestClient(builder, isMocked);
}
 
Example 3
Source File: SqlSampleTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) {
    if (!isMocked) {
        return super.buildRestClient(builder, isMocked);
    }
    return super.buildRestClient(builder.withReadTimeout(200, TimeUnit.SECONDS), isMocked);
}
 
Example 4
Source File: ServiceBusOperationsTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) {
    if (!isMocked) {
        return super.buildRestClient(builder, isMocked);
    }
    return super.buildRestClient(builder.withReadTimeout(100, TimeUnit.SECONDS), isMocked);
}
 
Example 5
Source File: TestBase.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) {
    return builder.build();
}
 
Example 6
Source File: KeyVaultClientIntegrationTestBase.java    From azure-keyvault-java with MIT License 4 votes vote down vote up
protected RestClient buildRestClient(RestClient.Builder builder) {
	return builder.build();
}
 
Example 7
Source File: KeyVaultClientIntegrationTestBase.java    From azure-keyvault-java with MIT License 4 votes vote down vote up
protected RestClient buildRestClient(RestClient.Builder builder) {
	return builder.build();
}
 
Example 8
Source File: TestBase.java    From autorest-clientruntime-for-java with MIT License 4 votes vote down vote up
protected RestClient buildRestClient(RestClient.Builder builder, boolean isMocked) {
    return builder.build();
}