How to allow slashes in path param in jax-rs endpoint

萝らか妹 提交于 2019-12-10 23:32:18

问题


I have an endpoint as:

@Path("/products")

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

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

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);
}

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


回答1:


Using @Path("{productId : .+}") should work.



来源:https://stackoverflow.com/questions/43984969/how-to-allow-slashes-in-path-param-in-jax-rs-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!