英文:
REST request to AWS from Quarkus backend
问题
我需要发送一个HTTP请求到AWS IoT核心以更新设备影子。此请求应通过Quarkus后端发送。当前问题是如何将身份验证标头附加到请求。目前在此代码中存在身份验证问题。
这是用于发送请求的类:
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("/things/abc")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient(baseUri = "https://a144gttuytyty10wv7-ats.iot.us-east-1.amazonaws.com")
public interface OrganizationProxy {
@GET
@Path("/shadow?name=shadow-version-1")
Uni<JsonObject> getOrg();
}
这是用于测试样本GET请求的客户端类:
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/organizations")
@ApplicationScoped
public class OrganizationResource {
@Inject
@RestClient
OrganizationProxy organizationProxy;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<JsonObject> get() {
return organizationProxy.getOrg();
}
}
我已经尝试附加身份验证标头,但我没有找到在程序中如何执行此操作的方法。我的最终目标是向AWS IoT核心设备API发送请求并获取响应。
英文:
I have to send a HTTP request to AWS IoT core to update device shadow. This request should send through Quarkus backend. The current problem is how to Append Authentication headers to the request. Currently there is a authentication problem with this code.
This is the Class used to send the request
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.json.JsonObject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path("/things/abc")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient(baseUri = "https://a144gttuytyty10wv7-ats.iot.us-east-1.amazonaws.com")
public interface OrganizationProxy {
@GET
@Path("/shadow?name=shadow-version-1")
Uni<JsonObject> getOrg();
}
This is the client class for test sample get request
import io.smallrye.mutiny.Uni;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/organizations")
@ApplicationScoped
public class OrganizationResource {
@Inject
@RestClient
OrganizationProxy organizationProxy;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<JsonObject> get() {
return organizationProxy.getOrg();
}
}
I already try to append the Authentication headers. But I didn't found a way to how to do this in the program. My final goal is to send a request to this AWS IoT core device API and get a response.
答案1
得分: 0
你打算使用基于X509证书的身份验证还是使用IAM访问密钥和密钥(参见客户端身份验证)?我建议利用现有的SDK而不是自行构建。例如,你可以将此库添加为Maven依赖项:
<dependency>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>aws-iot-device-sdk</artifactId>
<version>1.11.5</version>
</dependency>
然后直接使用这些类。请参阅https://github.com/aws/aws-iot-device-sdk-java-v2获取示例。
英文:
Do you plan to use X509 certificate-based authentication or leveraging IAM access key and secret (see Client authentication)?
I recommend to leverage an existing SDK instead of building on your own. E.g. you can add this library as a Maven dependency
<dependency>
<groupId>software.amazon.awssdk.iotdevicesdk</groupId>
<artifactId>aws-iot-device-sdk</artifactId>
<version>1.11.5</version>
</dependency>
and directly use the classes. See https://github.com/aws/aws-iot-device-sdk-java-v2 for samples.
答案2
得分: 0
我连接到了AWS IoT Core设备影子的REST端点,使用了AWS SignV4。
https://github.com/kavishkamk/AWS-IoT-Core-REST-endpont-with-AWSV4
英文:
I connected with AWS Iot Core Device Shadow Rest end point with AWS SignV4.
https://github.com/kavishkamk/AWS-IoT-Core-REST-endpont-with-AWSV4
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论