Java WebSphereLiberty v16.0.0。3 JAX-RS:QueryParams/PathParams映射问题
使用以下REST服务定义:Java WebSphereLiberty v16.0.0。3 JAX-RS:QueryParams/PathParams映射问题,java,jax-rs,websphere,websphere-liberty,Java,Jax Rs,Websphere,Websphere Liberty,使用以下REST服务定义: @GET @Path("/selection/{typeAssignation}/{numeroEmploye}") public Response obtenirChoixSecteurs(@PathParam("typeAssignation") String typeAssignation, @PathParam("numeroEmploye") Long numeroEmploye,
@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似乎无法为正确的PathParams/QueryParams分配正确的值,即使它能够根据URL选择正确的方法
同样的代码在WAS v8.5.5.9中运行得非常好这是嵌入Liberty(vs
wink
in WAS)的cxf
中的一个bug吗?我怀疑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();
}
日志(和浏览器)中的输出为:
我想知道您是否更幸运地使用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-RS2.0API,但我使用Liberty 16.0.0.3在jaxrs-1.1和jaxrs-2.0特性上都获得了成功的结果
其他一些想法:
- 是否在应用程序getClasses()方法中添加资源类?我认为这在2.0中不是必需的,但在1.1中可能需要
- 您是否有其他可能使用URL的提供者、筛选器、拦截器等
希望这能有所帮助,Andy我怀疑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();
}
日志(和浏览器)中的输出为:
我想知道您是否更幸运地使用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-RS2.0API,但我使用Liberty 16.0.0.3在jaxrs-1.1和jaxrs-2.0特性上都获得了成功的结果
其他一些想法:
- 是否在应用程序getClasses()方法中添加资源类?我认为这在2.0中不是必需的,但在1.1中可能需要
- 您是否有其他可能使用URL的提供者、筛选器、拦截器等
希望这有帮助,安迪,谢谢你的指点 在WAS v8.5.5中,客户端如下所示:
org.apache.wink.client.Resource resource;
resource = restClient.resource("<...>/selection/HEBDOMADAIRE/206862?confirme=true");
org.apache.wink.client.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?confirme=true”);
将其更改为以下选项使其正常工作
WebTarget webTargetAST = restClient.target(<...>);
WebTarget wt = webTargetAST.path("/selection/HEBDOMADAIRE/206862");
wt = wt.queryParam("confirme","true");
WebTarget-webTargetAST=restClient.target();
WebTarget wt=webTargetAST.path(“/selection/HEBDOMADAIRE/206862”);
wt=wt.queryParam(“确认”、“真实”);
WLP中的JAX-RS似乎对“?”
进行了编码,而wink-in是v8.5.5,没有编码,而且在日志中也不直接“可见”…再次感谢你@Andy,谢谢你的指点
在WAS v8.5.5中,客户端如下所示:
org.apache.wink.client.Resource resource;
resource = restClient.resource("<...>/selection/HEBDOMADAIRE/206862?confirme=true");
org.apache.wink.client.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?confirme=true”);
将其更改为以下选项使其正常工作
WebTarget webTargetAST = restClient.target(<...>);
WebTarget wt = webTargetAST.path("/selection/HEBDOMADAIRE/206862");
wt = wt.queryParam("confirme","true");
WebTarget-webTargetAST=restClient.target();
WebTarget wt=webTargetAST.path(“/selection/HEBDOMADAIRE/206862”);
wt=wt.queryParam(“确认”、“真实”);
WLP中的JAX-RS似乎对“?”
进行了编码,而wink-in是v8.5.5,没有编码,而且在日志中也不直接“可见”…再次感谢不要在回答另一个问题时添加您自己的“答案”,您应该将此作为问题的更新,对Andy的答案添加评论,然后单击答案左侧的复选标记接受他的答案。确定。但是安迪的答案不是我问题的答案,我问题的答案是我自己的答案。。那么这里的“官方程序”是什么?更新后接受我自己的问题??抱歉,我误解了这个问题。是的,如果你的答案是“正确的”,而安迪只是指出了正确的方向,那么我相信你可以接受自己的答案。我很高兴你解决了这个问题。与其在回答另一个问题时添加你自己的“答案”,不如将此作为问题的更新,在Andy的答案中添加评论,然后单击答案左侧的复选标记接受他的答案。确定。但是安迪的答案不是我问题的答案,我问题的答案是我自己的答案。。那么这里的“官方程序”是什么?更新后接受我自己的问题??抱歉,我误解了这个问题。是的,如果你的答案是“正确的”,而安迪只是指出了正确的方向,那么我相信你可以接受自己的答案。我很高兴你解决了这个问题。我不建议在url中接收类型化的值,我会将所有内容设置为字符串,然后进行解析。你建议不使用标准REST API有什么原因吗?否决,因为这根本不能回答我的问题…我不建议在url中接收键入的值,我会将所有内容设置为字符串,然后进行解析。您建议不使用