我有一个无状态 EJB,并且我通过注释 @WebService 为其定义了一个 Web 服务端点(如下所示)。我使用 HTTP session 和 WebServiceContext 管理身份验证和 session 。代码运行正常。
@Stateless
@WebService
public class UserManager implements UserManagerRemote{
@Resource
private WebServiceContext webServiceContext;
@Override @WebMethod
public boolean login(String username, String password){
if(!checkUser(username, password))
return false;
HttpSession session = HttpServletRequest)webServiceContext.getMessageContext().
get(MessageContext.SERVLET_REQUEST)).getSession();
session.setAttribute("username", username);
return true;
}
@Override @WebMethod
public int doSomthing(){
HttpSession session = ((HttpServletRequest)webServiceContext.getMessageContext().
get(MessageContext.SERVLET_REQUEST)).getSession();
if(session == null)
return -1;
//do the thing and return the result
return 1;
}
}
我需要做的是更改 EJB Web 服务端点的 http session 超时。我已经尝试了所有方法,但由于该程序在 glassfish 上部署为 ejb-jar,因此没有 web.xml。如何更改 EJB Web 服务端点的 http session 超时? 附:我无法使用有状态 EJB,因为我将使用 Web 服务端点。
最佳答案
我已经解决了!我找不到任何用于更改 session 超时的全局参数,但可以通过 HttpSession.setMaxInactiveInterval(int Interval) 为每个单独的 session 更改它。虽然基于Java documentation该方法以秒为单位获取间隔,但显然它以毫秒为单位。
关于java - 如何更改无状态 EJB 的 Web 服务端点的 http session 超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16272988/