私が経由ApplicationGatewayBackendHealthServer
オブジェクトを取得することができなかったことを実現することがないようなので、私はアズールのJava SDKのクラスApplicationGatewayBackendHealthServer
方法health()
を経由して、あなたのパイプラインコマンドの健康値を取得しようとしたが、失敗しましたルートクラスAzure
からの実装パスです。
Azure REST API docsでコマンドの応答を取得するために関連するREST APIを検索しようとしましたが、既存のREST APIが失敗しました。あなたは詳細ログAzureCLI
のazure.details.log
から欲しいと私はAzureCLI
&他のSDKのソースコードを検索するにはしようとした
は、最終的に私は、REST APIを得ました。
必要なREST APIは、次のとおりです。ヘッダAuthorization: Bearer <accessToken>
と上記のREST APIのPOST
要求を行う
https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/applicationGateways/<applicationGateway-name>/backendhealth?api-version=<api-version>
、あなたはヘッダAuthorization: Bearer <accessToken>
とGET
要求を経由して、以下のようなレスポンスヘッダlocation
から次の動的なREST APIを取得することができます。
https://management.azure.com/subscriptions/<subscriptionId>/providers/Microsoft.Network/locations/<region>/operationResults/<objectId, such as f7bfd1fd-e3ea-42f7-9711-44f3229ff877>?api-version=<api-version>
ここに私のサンプルコードです。第二ステップの動的REST APIを使用して
// Get the response header `location` from 1st step REST API
OkHttpClient client = new OkHttpClient();
String url = String.format("https://management.azure.com/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/applicationGateways/%s/backendhealth?api-version=%s", subscriptionId, resourceGroupName, appGatewayName, apiVersion);
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, "");
Request request = new Request.Builder().url(url).header("Authorization", "Bearer "+accessToken).post(body).build();
Response response = client.newCall(request).execute();
String location = response.header("Location");
System.out.println(location);
:第一段階のREST APIを使用して
String AUTHORITY = "https://login.windows.net/<tenantId>";
String clientId = "<client-id on management portal(old), or application-id on Azure new portal>";
String clientSecret = "<client-secret-key>";
String subscriptionId = "<subscriptionId>";
String resourceGroupName = "<resource-group-name>";
String appGatewayName = "<applicationgateway-name>";
String apiVersion = "2016-09-01";
// Getting access token
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
ClientCredential credential = new ClientCredential(clientId, clientSecret);
Future<AuthenticationResult> future = context.acquireToken("https://management.azure.com/", credential, null);
result = future.get();
String accessToken = result.getAccessToken();
System.out.println(accessToken);
// Get the response content as the same as the azure-cli command `azure network applicationgateway backend-health show`
Request request2 = new Request.Builder().url(location).header("Authorization", "Bearer " + accessToken).build();
// Notice for the below code, see under the code
Response response2 = client.newCall(request2).execute();
System.out.println(response2.body().string());
お知らせ:私はPOSTMAN
を介してコンテンツを取得することができた 、私は第2ステップのための応答内容null
を持っていますg OKHttp
/Apache HttpClient
/HttpURLConnection
(Java版)私は&が何故起こったのか分かりません。なぜなら、Golang/Jqueryで実装されたコードさえもうまくいきます。これは、JavaでHTTPプロトコルスタックの実装が原因であると思われます。
上記のREST APIのアクセス許可に関するエラー情報がある場合は、https://github.com/JamborYao/ArmManagementを参照して解決してください。
あなたのお役に立てば幸いです。第2段階の問題を解決できる場合は、解決策を私たちと共有してください。私はそれを解決するために引き続き努力します。
完全な答えをPeterに感謝します。それはとても役に立ちます。 –
Javaでは、これは、あなたがAzureコンソールにWebアプリケーションを作成した場合に起こります。アプリがネイティブの場合はすべて正常です。 –
@AurelAvramescu素晴らしい!あなたの共有に感謝します。 –