使用以下 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 返回码:
java.lang.NumberFormatException: For input string: "206862?confirme=true"
liberty v16.0.0.3 似乎无法将正确的值分配给正确的 PathParams/QueryParams,即使它能够根据 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() 方法中添加了资源类?我不认为这对于 2.0 是必需的,但对于 1.1 可能是必需的。
- 您是否有任何其他供应商、过滤器、拦截器等可能会使用该 URL?
希望这对你有帮助,安迪
关于java - WebSphere 自由 v16.0.0。 3 JAX-RS : QueryParams/PathParams mapping issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41044238/