[JBoss Seam] - Re: How can I get the session id?
by chicochen
Also, is there a good way to keep http session in jboss seem actions calling via web service method?
@Stateless
| @Name("AuthenticateWebService")
| @WebService(name = "AuthenticateWebService", serviceName = "AuthenticateWebService")
| public class AuthenticateWebService implements AuthenticateWebServiceRemote {
|
| //@In(value = "authenticateAction", create = true)
| //private AuthenticateAction authenticateAction;
|
| @WebMethod
| public String login(String username, String password) {
| Identity.instance().setUsername(username);
| Identity.instance().setPassword(password);
| Identity.instance().login();
|
| if (Identity.instance().isLoggedIn()){
| ResponseInfo rInfo = ResponseInfo.getSuccessInfo();
|
|
|
| String xml = BeanXMLMapping.toXML(rInfo);
| return xml;
| }
| else {
| ResponseInfo rInfo = ResponseInfo.getFailInfo();
| String xml = BeanXMLMapping.toXML(rInfo);
| return xml;
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117252#4117252
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117252
18 years, 3 months
[JBoss Seam] - How can I get the session id?
by chicochen
I use below code, but FacesContext.getCurrentInstance() always return null.
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ExternalContext externalContext = facesContext.getExternalContext();
| HttpSession session = (HttpSession)externalContext.getSession(true);
| String sessionId = session.getId();
package com.eastidea.menglishweb.action;
|
| import javax.faces.context.ExternalContext;
| import javax.faces.context.FacesContext;
| import javax.persistence.EntityManager;
| import javax.persistence.NoResultException;
| import javax.servlet.http.HttpSession;
|
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.security.Identity;
|
| import com.eastidea.menglishweb.action.base.BaseActionImpl;
| import com.eastidea.menglishweb.entity.User;
|
| @Name("authenticateAction")
| public class AuthenticateActionImpl extends BaseActionImpl implements
| AuthenticateAction {
|
| private static final long serialVersionUID = 7601102159656515184L;
|
| @In
| private EntityManager entityManager;
|
| @In
| private Identity identity;
|
| public boolean authenticate() {
| try {
| User user = (User) entityManager
| .createQuery(
| "from User where username = :username and password = :password")
| .setParameter("username", identity.getUsername())
| .setParameter("password", identity.getPassword())
| .getSingleResult();
| setCurrentUser(user);
|
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ExternalContext externalContext = facesContext.getExternalContext();
| HttpSession session = (HttpSession)externalContext.getSession(true);
| String sessionId = session.getId();
|
| return true;
| } catch (NoResultException ex) {
| return false;
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117251#4117251
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117251
18 years, 3 months