卷曲Jersey端点会产生“找不到当前请求的范围”

时间:2019-04-02 17:13:30

标签: java curl jersey dropwizard

将Dropwizard服务器与在Jersey服务器上注册的自定义JAX-RS资源一起使用时,我遇到了一个真正莫名其妙的错误。以下是正确的:

  1. 卷曲一个不存在的端点会产生一个404,正如预期的那样。
  2. 使用错误的方法(例如POST而不是GET)卷曲现有端点会产生405,正如预期的那样。
  3. 使用正确的方法卷曲现有端点将产生消息“找不到当前请求的范围”。
  4. 我的端点处理程序代码从未被触摸过,这可以通过在代码中设置断点来验证。
  5. 令人惊奇的是,如果我将整个路径注释移到我的处理程序方法上而不是部分移到整个类上,则会得到一个404。

以下是给出奇怪错误消息的格式的示例:

@Produces({MediaType.APPLICATION_JSON})
@Path("application/api/v1/")
public class GetConfigurationResource extends MyResource<Arg, Result> {

  @GET
  @Path("getConfiguration/{uuid}")
  public Response handleHttpRequest(
      @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam("uuid") String uuid) {
    return super.handleHttpRequest(headers, new Arg(), new Result());
  }
}

下面是提供404的示例:

@Produces({MediaType.APPLICATION_JSON})
public class GetConfigurationResource extends MyResource<Arg, Result> {

  @GET
  @Path("application/api/v1/getConfiguration/{uuid}")
  public Response handleHttpRequest(
      @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam("uuid") String uuid) {
    return super.handleHttpRequest(headers, new Arg(), new Result());
  }
}

这是curl命令:

curl -X GET http://127.0.0.1:8080/application/api/v1/getConfiguration/5

即使在我的应用程序中使用像这样的玩具类,我也可以重现此错误。每个端点都给出相同的结果。

简单的Google搜索错误消息绝对不会产生任何结果。因此,这似乎是一个全新的错误。我想知道是什么原因可能导致这种情况,以及如何在Dropwizard / Jersey中调试此问题。

0 个答案:

没有答案
相关问题