调试RestEasy RestClient

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

我正在quarkus中使用该框架为mandrill API构建一个REST客户端

@RegisterRestClient
@Path("1.0")
@Produces("application/json")
@Consumes("application/json")
public interface MailService {
    @POST
    @Path("/messages/send-template.json")
    JsonObject ping(JsonObject mandrillInput);
}  

这是我的application.properties的相关部分

com.example.service.MailService/mp-rest/url=https:/mandrillapp.com/api

还有我的示例资源

@Path("/hello")
public class ExampleResource {

    @Inject
    @RestClient
    MailService mailService;

    @Produces(MediaType.TEXT_PLAIN)
    @GET
    public String hello() {
        System.out.print("In the API");
        JsonObject key = Json.createObjectBuilder().add("key", "ABCD").build();
        System.out.println("The json built is "+key);
        JsonObject response = mailService.ping(key);
        System.out.println("The response is " + response);
        return "hello";
    }
}  

[我所看到的是,如果我正在调用的API(在这种情况下为Mandrill)返回错误响应(例如,如果我的密钥错误),那么我用来存储响应的变量将无法获得响应。取而代之的是,我向我的应用程序展示的REST API包含了Mandrill的响应。这是预期的行为吗?如何在Quarkus中调试其他客户端实现的输出?

完整项目here被调用的REST API是here

resteasy quarkus quarkus-rest-client
1个回答
1
投票

如果要在发生错误时能够获取响应的正文,建议您使用javax.ws.rs.core.Response作为响应类型。

您还可以走另一条路线,并使用ExceptionMapper处理异常

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