如何在jax-rs端点的路径参数中允许斜线 [英] How to allow slashes in path param in jax-rs endpoint

查看:160
本文介绍了如何在jax-rs端点的路径参数中允许斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的端点为:

@Path("/products")

    @Produces({ MediaType.APPLICATION_JSON })
    public interface Products {

        @PUT
        @Path("/{productId}")
        ....
    }

我为此服务实现了一个jax-rs客户端,并将其导入了我正在从中调用的另一个服务中.

I have a jax-rs client implemented for this service and have it imported in the another service that I am calling this from.

所以我要从第二个服务中按如下方式致电客户端

So I am calling the client as below from my second service

public String updateProduct(String productId){
..
  return client.target(this.getBaseUrl()).path("products/").path(productId).request(MediaType.APPLICATION_JSON_TYPE).put(Entity.json(""), String.class);
}

如果我有带有斜杠的产品,说"控制/注册应用程序",则该服务似乎不能很好地使用它.在对服务进行调用之前,我确实对productId进行了编码,然后在收到后对其进行解码.但这似乎不起作用,并且找不到404.有任何想法吗?预先感谢

If I have a product with slashes say "control/register app" , the service does not seem to take it well. I did encode the productId before making a call to the service and then decoded it once received. But that doesnt seem to work and I get a 404 not found. Any ideas? Thanks in advance

推荐答案

使用@Path("{productId : .+}")应该可以.

这篇关于如何在jax-rs端点的路径参数中允许斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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