如何获取请求的URL?

时间:2010-09-30 19:28:07

标签: java jersey jax-rs

我正在使用Jeresy Jax-RS来构建一个Web服务。现在我需要使用端口#获取请求的URL(如果存在)。

因此,如果我的服务在http://www.somelocation.com/web/services上运行,我想要捕获www.somelocation.com

我该怎么做?

1 个答案:

答案 0 :(得分:27)

您可以在操作中添加UriInfo参数。从那里你可以访问URL:

@POST
@Consumes({"application/xml", "application/json"})
public Response create(@Context UriInfo uriInfo, Customer customer) {
    ...
}