来自 Quarkus 休息客户端的 Azure 全局端点错误

问题描述 投票:0回答:1

我有一个 Quarkus Rest 客户端接口,我试图从中调用 azure 全局端点来配置和注册设备。然而,我收到 404 错误,因为注入的参数和值看起来正确,端点的路径也是如此,但仍然不确定为什么收到 404。这是我指的是从我的客户端进行调用的 azure 端点的文档通过将组注册 ID 传递到有效负载中来注册设备 -> https://learn.microsoft.com/en-us/rest/api/iot-dps/device/runtime-registration/register-device?view=rest -iot-dps-device-2021-10-01#deviceregistration。对于授权,我使用生成 SAS 令牌。我是否遗漏了文档中的任何内容或者该文档已过时?

import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(configKey = "dps-api")
@Path("/registrations")
public interface AzureRestClient {

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/{registrationId}/register?api-version=2021-10-01")
    Response registerDevice(RegistrationPayload payload, @PathParam("registrationId") String registrationId,
            @HeaderParam("Authorization") String authorization);

}

应用程序属性 quarkus.rest-client.dps-api.url=https://global.azure-devices-provisioning.net/{idScope}

错误

Caused by: org.jboss.resteasy.reactive.ClientWebApplicationException: Received: 'Not Found, status code 404' when invoking REST Client method: 'com.my.clients.AzureRestClient#registerDevice'
    at org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.unwrapException(RestClientRequestContext.java:205)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.handleException(AbstractResteasyReactiveContext.java:331)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:175)
    at org.jboss.resteasy.reactive.client.impl.RestClientRequestContext$1.lambda$execute$0(RestClientRequestContext.java:324)
    at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:270)
    at io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:252)
    at io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:50)
    at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    ... 2 more
azure quarkus java-21 azure-iot-dps
1个回答
0
投票

您需要在接口的 @Path 上提供 idScope。

或者当它是一个常量时,在application.props中:

idScope=${ID_SCOPE:123456} quarkus.rest-client.dps-api.url=https://global.azure-devices-provisioning.net/${idScope}

不管怎样,404表示你的网址错误。

© www.soinside.com 2019 - 2024. All rights reserved.