开发者

How to get session object while working on webservices?

How to get session object while working on webservices?

Services are called between two programs. How to get user session object while workin with 开发者_高级运维webservices. It is not possible to get session using request object as there will not be request or response when we talk about services.


If you're working with JAX-WS to create your web services, then you can access the HttpServletRequest object (and hence your HttpSession object) via the WebServiceContext.

@WebService(...)
public class MyService {
    @Resource
    private WebServiceContext ctx;

    private HttpSession getSession() {
        HttpServletRequest req = (HttpServletRequest) this.ctx.getMessageContext()
                .get(MessageContext.SERVLET_REQUEST);
        return req.getSession();
    }
}

For a more extensive example, see, e.g., "Maintaining sessions using JAX-WS 2.0" by Art Frechette.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜