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

2019-07-14 05:44发布

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条回答
干净又极端
2楼-- · 2019-07-14 06:35

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

查看更多
登录 后发表回答