使用以下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"


自由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 Liberty v16.0.0。 3 JAX-RS:QueryParams/PathParams映射问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41044238/

10-12 14:24