Search in sources :

Example 11 with AzureJacksonAdapter

use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.

the class ManageSqlFirewallRules method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 12 with AzureJacksonAdapter

use of com.microsoft.azure.serializer.AzureJacksonAdapter 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");
}
Also used : AutoRestAzureSpecialParametersTestClientImpl(fixtures.azurespecials.implementation.AutoRestAzureSpecialParametersTestClientImpl) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) RequestIdHeaderInterceptor(com.microsoft.rest.interceptors.RequestIdHeaderInterceptor) TokenCredentials(com.microsoft.rest.credentials.TokenCredentials) BeforeClass(org.junit.BeforeClass)

Example 13 with AzureJacksonAdapter

use of com.microsoft.azure.serializer.AzureJacksonAdapter in project autorest.java by Azure.

the class LROsTests 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 AutoRestLongRunningOperationTestServiceImpl(restClient);
    client.getAzureClient().setLongRunningOperationRetryTimeout(0);
}
Also used : AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) AutoRestLongRunningOperationTestServiceImpl(fixtures.lro.implementation.AutoRestLongRunningOperationTestServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 14 with AzureJacksonAdapter

use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-tools-for-java by Microsoft.

the class IntegrationTestBase method createRestClient.

private RestClient createRestClient(ApplicationTokenCredentials credentials) throws Exception {
    RestClient restClient;
    if (IS_MOCKED) {
        credentials = new TestCredentials();
        restClient = new RestClient.Builder().withBaseUrl(MOCK_URI + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
        return restClient;
    } else {
        restClient = new RestClient.Builder().withBaseUrl(GLOBAL_ENDPOINT).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
        return restClient;
    }
}
Also used : AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient)

Example 15 with AzureJacksonAdapter

use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-tools-for-java by Microsoft.

the class IntegrationTestBase method createRestClient.

private RestClient createRestClient(ApplicationTokenCredentials credentials) {
    final RestClient client;
    ApplicationTokenCredentials cred = credentials;
    if (IS_MOCKED) {
        cred = new TestCredentials();
        client = new RestClient.Builder().withBaseUrl(MOCK_URI + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
    } else {
        client = new RestClient.Builder().withBaseUrl(GLOBAL_ENDPOINT).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
    }
    return client;
}
Also used : AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials)

Aggregations

AzureJacksonAdapter (com.microsoft.azure.serializer.AzureJacksonAdapter)15 RestClient (com.microsoft.rest.RestClient)15 AzureResponseBuilder (com.microsoft.azure.AzureResponseBuilder)11 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)6 File (java.io.File)5 Azure (com.microsoft.azure.management.Azure)4 RequestIdHeaderInterceptor (com.microsoft.rest.interceptors.RequestIdHeaderInterceptor)4 BeforeClass (org.junit.BeforeClass)4 Response (okhttp3.Response)3 MappingBuilder (com.github.tomakehurst.wiremock.client.MappingBuilder)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)2 TokenCredentials (com.microsoft.rest.credentials.TokenCredentials)2 AutoRestAzureSpecialParametersTestClientImpl (fixtures.azurespecials.implementation.AutoRestAzureSpecialParametersTestClientImpl)2 Interceptor (okhttp3.Interceptor)2 Request (okhttp3.Request)2 Test (org.junit.Test)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CloudError (com.microsoft.azure.CloudError)1 Provider (com.microsoft.azure.management.resources.Provider)1 ProviderRegistrationInterceptor (com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor)1