use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.
the class TestBase method setup.
@Before
public void setup() throws Exception {
addTextReplacementRule("https://management.azure.com/", this.mockUri() + "/");
setupTest(name.getMethodName());
ApplicationTokenCredentials credentials;
RestClient restClient;
String defaultSubscription;
if (IS_MOCKED) {
credentials = new AzureTestCredentials();
restClient = buildRestClient(new RestClient.Builder().withBaseUrl(this.mockUri() + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), true);
defaultSubscription = MOCK_SUBSCRIPTION;
System.out.println(this.mockUri());
out = System.out;
System.setOut(new PrintStream(new OutputStream() {
public void write(int b) {
//DO NOTHING
}
}));
} else {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
credentials = ApplicationTokenCredentials.fromFile(credFile);
restClient = buildRestClient(new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new ProviderRegistrationInterceptor(credentials)).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withReadTimeout(3, TimeUnit.MINUTES).withNetworkInterceptor(this.interceptor()), false);
defaultSubscription = credentials.defaultSubscriptionId();
addTextReplacementRule(defaultSubscription, MOCK_SUBSCRIPTION);
}
initializeClients(restClient, defaultSubscription, credentials.domain());
}
use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.
the class ProviderRegistrationInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
if (!response.isSuccessful()) {
String content = errorBody(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 restClient = new RestClient.Builder().withBaseUrl("https://" + chain.request().url().host()).withCredentials(credentials).withSerializerAdapter(jacksonAdapter).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).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;
}
use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.
the class ManageSqlDatabase 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()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).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();
}
}
use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.
the class ManageSqlDatabaseInElasticPool 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()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).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();
}
}
use of com.microsoft.azure.serializer.AzureJacksonAdapter in project azure-sdk-for-java by Azure.
the class ManageSqlDatabasesAcrossDifferentDataCenters 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()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).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();
}
}
Aggregations