WebSphere 自由 v16.0.0。 3 JAX-RS:QueryParams / PathParams 映射问题

WebSphere Liberty v16.0.0. 3 JAX-RS: QueryParams / PathParams mapping issue

具有以下 REST 服务定义:

@GET
@Path("/selection/{typeAssignation}/{numeroEmploye}")
public Response obtenirChoixSecteurs(@PathParam("typeAssignation") String typeAssignation,
                                     @PathParam("numeroEmploye") Long numeroEmploye,
                                     @QueryParam("confirme") @DefaultValue("true") Boolean confirme) 

当使用此 URL 调用服务时:

<...>/selection/HEBDOMADAIRE/206862?confirme=true

Liberty v16.0.0.3 抛出 NumberFormatException 并且客户端收到 HTTP 404 return 代码:

java.lang.NumberFormatException: For input string: "206862?confirme=true"

似乎 liberty v16.0.0.3 无法将正确的值分配给正确的 PathParams / QueryParams,即使它能够 select 基于 URL 的正确方法 相同的代码在 WAS v8.5.5.9
中运行良好 这是嵌入在 Liberty 中的 cxf 中的错误(与 WAS 中的 wink 相比)吗?

我怀疑 GET 请求不知何故搞砸了。当我使用您的方法签名构建 JAX-RS 资源时,一切都按预期工作。我可以重现 NumberFormatException 的唯一方法是在数字末尾放置一个非数字字符(如“<...>/selection/HEBDOMADAIRE/206862_?confirme=true”)。这让我觉得你的问号被转义了。

这是我使用的代码:

@GET
@Path("/selection/{typeAssignation}/{numeroEmploye}")
public Response obtenirChoixSecteurs(@PathParam("typeAssignation") String typeAssignation,
                                     @PathParam("numeroEmploye") Long numeroEmploye,
                                     @QueryParam("confirme") @DefaultValue("true") Boolean confirme) {

    String s =  "obtenirChoixSecteurs typeAssignation='" + typeAssignation + "' numeroEmploye=" + numeroEmploye + " confirme='" + confirme + "'";
    System.out.println(s);
    return Response.ok("success: " + s).build();
}

日志(和浏览器)中的输出是:

obtenirChoixSecteurs typeAssignation='HEBDOMADAIRE' numeroEmploye=206862 confirme='true'

我想知道您是否有更多运气使用 JAX-RS 客户端 API 来调用服务,例如:

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:9080/myApp/rest/res/selection/HEBDOMADAIRE/206862?confirme=true");
    System.out.println( target.request().get(String.class) );

测试客户端需要使用 JAX-RS 2.0 API,但我使用 Liberty 16.0.0.3 获得了 jaxrs-1.1 和 jaxrs-2.0 功能的成功结果

其他一些想法:

  • 您是否在 Application getClasses() 方法中添加资源 class?我不认为这对于 2.0 是必需的,但对于 1.1 可能是必需的。
  • 您是否有任何其他可能正在使用 URL 的提供程序、过滤器、拦截器等?

安迪,希望这对你有所帮助

@Andy,感谢指点
在WAS v8.5.5客户端是这样的:

org.apache.wink.client.Resource resource;
resource = restClient.resource("<...>/selection/HEBDOMADAIRE/206862?confirme=true");

在 WLP v16.0.0.3 中,客户端被转换为 JAX-RS 2.0,如下所示:

  WebTarget  webTargetAST = restClient.target(<...>);
  WebTarget wt = webTargetAST.path("/selection/HEBDOMADAIRE/206862?confirme=true");

将其更改为以下使其生效

  WebTarget  webTargetAST = restClient.target(<...>);
  WebTarget wt = webTargetAST.path("/selection/HEBDOMADAIRE/206862");
  wt = wt.queryParam("confirme","true");

WLP 中的 JAX-RS 似乎对 "?" 进行了编码,而 WAS v8.5.5 中的 wink 则没有,而且日志中也没有直接 "visible"...
再次感谢