关于 CXF、JAX-RS Web 服务的请求和会话的问题

发布于 2024-08-21 11:27:19 字数 437 浏览 7 评论 0原文

我有一个使用 CXF、JAX-RS 和 Spring 设置的 Web 服务。我有以下方法:

@GET
@Path("/getPayload")
@Produces("application/XML")
public Response makePayload(){
    Payload payload = new Payload();
    payload.setUsersOnline(new Long(200));

    return Response.ok().entity(payload).build();
}

如何访问 makePayload() 中的 HttpRequest 对象?

对此方法的调用是否会生成一个会话?如果是,我可以获得它的句柄吗?该会话对于来自同一客户端的所有后续请求是否会持续存在?

I have a webservice set up using CXF, JAX-RS and Spring. I have the following method:

@GET
@Path("/getPayload")
@Produces("application/XML")
public Response makePayload(){
    Payload payload = new Payload();
    payload.setUsersOnline(new Long(200));

    return Response.ok().entity(payload).build();
}

How can I get access to the HttpRequest object in my makePayload()?

Will a call to this method generate a Session, and if so, can I get a handle to it and will that session be persistent for all subsequent requests from the same client?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2024-08-28 11:27:19

@Context 可用于获取与请求或响应相关的上下文 Java 类型:

@GET
@Path("/getPayload")
@Produces("application/XML")
public Response makePayload(@Context Request request) {
    //...
}

@Context can be used to obtain contextual Java types related to the request or response:

@GET
@Path("/getPayload")
@Produces("application/XML")
public Response makePayload(@Context Request request) {
    //...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文