我正在使用Azure Java SDK版本1.15.1。由于我需要使用非默认的Java TrustStore连接到Azure,因此我创建了自己的自定义信任存储文件,将其加载到TrustManager中,然后创建如下的OkHttpClient.Builder:
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder().sslSocketFactory(sslSocketFactory, trustManager);
然后,我将创建一个Retrofit Builder,并使用所有这些来创建我的Azure连接对象:
retrofit2.Retrofit.Builder retrofitBuilder = new retrofit2.Retrofit.Builder();
retrofitBuilder.baseUrl("https://management.azure.com");
com.microsoft.rest.RestClient restClient = new RestClient.Builder(httpClientBuilder, retrofitBuilder)
.withCredentials(credentials)
.withBaseUrl("https://management.azure.com")
.withResponseBuilderFactory(new ServiceResponseBuilder.Factory())
.withSerializerAdapter(new JacksonAdapter())
.build();
Azure azureConnection = Azure.authenticate(restClient, tenantId).withSubscription(subscription);
这对于从Azure检索各种数据(网络,安全组等)非常有用。
但是,如果我想使用此连接来创建新的安全组:
newSecGroup = azureConnection.getAzureConnection().networkSecurityGroups()
.define(groupName)
.withRegion(regionName)
.withExistingResourceGroup(resourceGroupName)
.withTag("MyCustomTag", groupName)
.create();
它引发以下异常,这实际上并不能帮助我找到根本原因-也许有人可以指出我正确的方向? 谢谢 库尔特
Error when trying to create a new Security Group within resource groupksembatest, region eastus with name Cloud__Web Server for policy Web Server: com.microsoft.azure.CloudException
at com.microsoft.azure.AzureClient.createExceptionFromResponse(AzureClient.java:740)
at com.microsoft.azure.AzureClient.access$100(AzureClient.java:33)
at com.microsoft.azure.AzureClient$3.call(AzureClient.java:160)
at com.microsoft.azure.AzureClient$3.call(AzureClient.java:157)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(CallArbiter.java:120)
at retrofit2.adapter.rxjava.CallArbiter.emitResponse(CallArbiter.java:102)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:46)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeSingle.call(OnSubscribeSingle.java:81)
at rx.internal.operators.OnSubscribeSingle.call(OnSubscribeSingle.java:27)
at rx.internal.operators.SingleToObservable.call(SingleToObservable.java:39)
at rx.internal.operators.SingleToObservable.call(SingleToObservable.java:27)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.DeferredScalarSubscriber.subscribeTo(DeferredScalarSubscriber.java:153)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:32)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:22)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: retrofit2.Response.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:118)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:73)
... 45 more
答案 0 :(得分:0)
弄清可以在RestClient上启用调试日志记录后,
com.microsoft.rest.RestClient restClient = new RestClient.Builder(httpClientBuilder, retrofitBuilder)
.withCredentials(credentials)
.withBaseUrl("https://management.azure.com")
.withResponseBuilderFactory(new ServiceResponseBuilder.Factory())
.withSerializerAdapter(new JacksonAdapter())
.withLogLevel(com.microsoft.rest.LogLevel.BODY_AND_HEADERS)
.build();
很容易找到并解决我的问题。只是事实是,我要创建的Network Security Group的名称中有一个空白,而Azure不允许这样做。 HTTP响应比我从Java API错误跟踪获得的“ CloudException”更清晰。