【发布时间】:2020-05-04 15:16:34
【问题描述】:
我正在使用 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 中调试 REST 客户端实现的输出?
被调用的 REST API 是 https://mandrillapp.com/api/docs/users.JSON.html#method=ping2
【问题讨论】:
-
您能否添加一些示例代码来显示您所描述的内容?问是因为我真的不明白问题是什么。
-
@geoand 更新了示例
-
我明白了,谢谢@bobby。发生错误时您的行为是什么?抛出异常还是其他什么?
-
@geoand 如果我使用示例中的无效密钥,则 mailService.ping() 永远不会返回。我看到的是 API 的调用者(我使用 curl)得到了 mandrill 返回的响应。我没有看到在 quarkus 控制台中打印任何异常。我的假设是 mandrill 的失败响应将填充到响应对象中。但事实并非如此
标签: resteasy quarkus quarkus-rest-client