我正在使用quarkus中的框架为mandrill构建一个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会被Mandrill的响应填充。
这是预期的行为吗?如何在Quarkus中调试rest客户端实现的输出?
正在调用的REST是https://mandrillapp.com/api/docs/users.JSON.html#method=ping2。
发布于 2020-05-06 06:07:10
如果您希望在发生错误时能够获得响应的主体,我建议您使用javax.ws.rs.core.Response作为响应类型。
您还可以选择另一条路由,并使用ExceptionMapper处理异常。
https://stackoverflow.com/questions/61595593
复制相似问题