Jax-RS中的可选@PathParam [英] Optional @PathParam in Jax-RS

查看:235
本文介绍了Jax-RS中的可选@PathParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项服务,其中路径的最后部分是可选的,用户可以输入 / mypath / / mypath / param1 /

I have a service where the last part of the path is optional, the user can both enter /mypath/ and /mypath/param1/.

我尝试使用正则表达式来过滤路径的最后部分:

I tried to use a regular expression to filter the last part of the path:

@Path (/ mypath {param1:(/ param1)?})

我正在使用RestEasy作为我的JAX-RS提供程序代码在Tomcat中按预期工作,但当我在JBoss中部署它时,当我不提交可选部分时,我得到405返回代码。

I'm using RestEasy as my JAX-RS provider and the code works as expected in Tomcat but when I deploy it in JBoss I get a 405 return code when I do not submit the optional part.

我在这里做错了什么或者这是不可能以便携的方式完成这个?

Am I doing something wrong here or it's not possible to accomplish this in a portable way?

推荐答案

问题是冒号之前缺少空格:

The problem was the lack of whitespace before the colon:

@Path("/mypath{param1: (/param1)?}")

应该是:

@Path("/mypath{param1 : (/param1)?}")

显然这是一个错误,因为规范使冒号周围的空格可选。我还发现我不是第一个被这个错误所困扰

Apparently it's a bug, because the specification makes the whitespace around the colon optional. I also found that I'm not the first bitten by this bug.

这篇关于Jax-RS中的可选@PathParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆