RetryHandler / RetryHandlerOption 与 msgraph-sdk-java v6.x
I am currently working on a task to upgrade our application from msgraph-sdk-java 5.80.0 to 6.5.1. We have in this application one Graph class to provide all needed functions, like getting applications, service principals, settings owners, etc.
For our use case, we need a RetryHandler if the return code of a request is 404. We achieved this with version 5.x by implementing a RetryHandler and configuring it with the graph client instantiation.
With the new version 6.x, the approach is to configure this per request by passing a RetryHandlerOption to the default RetryHandler Middleware. This leads me to the first question:
Is it indeed not an option anymore, to configure a RetryHandler "globally" at client instantiation? In our Graph class, we have tons of requests - and it seems quite a pain to add the RetryHandlerOption to every one of these. I looked at the default RetryHandler Middleware and thought about taking the same approach as before by implementing our own RetryHandler. But there are package-private classes in use and simply copying from the default one, seems not to be possible.
And now to my second question: When I configure a RetryHandlerOption I get a java.lang.UnsupportedOperationException
. I tried to begin with a minimal setup:
The client class (client initialisation & test function):
private final val clientSecretCredential: ClientSecretCredential? =
ClientSecretCredentialBuilder()
.clientId(azureConfig.graphApiClientId)
.clientSecret(azureConfig.graphApiClientSecret)
.tenantId(azureConfig.tenantId)
.build()
private val authProvider = AzureIdentityAuthenticationProvider(clientSecretCredential, azureConfig.allowedHosts, azureConfig.scopeGraphApi)
private final val msGraphApiDebugger = MsGraphApiDebugger()
private final val retryHandler = RetryHandler()
private final val httpClient = GraphClientFactory.create()
.addInterceptor(msGraphApiDebugger)
.addInterceptor(retryHandler)
.build()
fun getApplicationByObjectId(objectId: String): Application {
val retryHandlerOption = RetryHandlerOption()
return graphServiceClient.applications().byApplicationId(oid).get { requestConfiguration ->
requestConfiguration.options.add(retryHandlerOption)
}
}
The unit test:
@Test
fun `check that getting an existing app registration returns the app registration`() {
val application = graphApiClient.getApplicationByObjectId("ad86b88a-bd06-4299-a587-1da6c3d0abdd")
assertEquals("Example App Registration Display Name", application.displayName)
}
The exception:
java.lang.UnsupportedOperationException
at java.base/java.util.AbstractList.add(AbstractList.java:155)
at java.base/java.util.AbstractList.add(AbstractList.java:113)
at xx.xxx.xxx.client.MsGraphApiClient.getApplicationByObjectId$lambda$0(MsGraphApiClient.kt:60)
at com.microsoft.kiota.RequestInformation.configure(RequestInformation.java:81)
at com.microsoft.graph.applications.item.ApplicationItemRequestBuilder.toGetRequestInformation(ApplicationItemRequestBuilder.java:335)
at com.microsoft.graph.applications.item.ApplicationItemRequestBuilder.get(ApplicationItemRequestBuilder.java:267)
at xx.xxx.xxx.client.MsGraphApiClient.getApplicationByObjectId(MsGraphApiClient.kt:59)
at xx.xxx.xxx.client.MsGraphApiClientIT.check that getting an existing app registration returns the app registration(MsGraphApiClientIT.kt:16)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Do you have an idea what I am doing wrong?
Regards
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2404
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权