java - Dropwizard Rest API 端点操作

标签 java rest dropwizard

我有一个 dropwizard 应用程序来 POST/GET 查询信息。我有一个 @POST 方法,它使用我的查询及其 11 个参数填充 arrayList。为简洁起见,我将示例缩减为仅显示 3 个参数。

@Path("/query")
public class QueryResource

@GET
@Produces(MediaType.APPLICATION_JSON)
@Timed
public List<Query> getQueries() {
    List<Query> queries = new ArrayList<Query>();
    logger.info("Calling get queries with {} method.");
    queries.add(new Query("b622d2c6-03b2-4488-9d5d-46814606e550", "eventTypeThing", "action"));
    return queries;

我可以通过 ARC 发送 get 请求,它将成功返回查询的 json 表示形式。

当我尝试对特定 queryId 发出 @GET 请求并返回其特定参数时,我遇到了问题。因此,

@GET
@Path("/{queryId}/action")
public Response getAction(@PathParam("queryId") String queryId, @PathParam("action") String action){
    logger.info("Get action by queryId {}");
    String output = "Get action: " + action;
    return Response.status(200).entity(output).build();

在其余客户端上,我向 https://localhost/query/b622d2c6-03b2-4488-9d5d-46814606e550/action

发出获取请求

我期望返回该特定 queryId 的操作类型,但实际上返回 null。

最佳答案

您没有在方法的 @Path 注释中将“action”声明为正确的参数。您需要将其更改为:

@Path("/{queryId}/{action}")

关于java - Dropwizard Rest API 端点操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49985751/

相关文章:

java - 有没有自动生成屏幕抓取Java代码的工具

java - 使用 MetricsServlet 获取 Cassandra 中的指标

dropwizard - 为什么没有应用我的 dropwizard 日志记录配置?

javascript - 如何从浏览器读取excel文件?

java - 在项目之间共享常量

java - GregorianCalendar 输出 : The date is java. util.GregorianCalendar[time=1141556400000,areFieldsSet=true,areAllFieldsSet=true

rest - 如何使用管道 |在 postman 参数中

web-services - 使用 REST API 和 SugarCRM 将目标添加到目标列表

python - 哪些工具可用于为 Flask 编写的 REST API 自动生成文档?

postgresql - (JDBI/Dropwizard) 从 PostgreSQL 检索自动递增的 id 时出现 PSQLException