Example usage for javax.servlet.http HttpSession setAttribute

List of usage examples for javax.servlet.http HttpSession setAttribute

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession setAttribute.

Prototype

public void setAttribute(String name, Object value);

Source Link

Document

Binds an object to this session, using the name specified.

Usage

From source file:org.jbpcc.admin.jsf.JsfUtil.java

/**
 * Convenience method for setting Session variables.
 * /*from ww w . j  a v a2  s .  c  om*/
 * @param ctx
 *            FacesContext
 * @param key
 *            object key
 * @param object
 *            value to store
 */
public static void storeOnSession(SessionObjectKey sessionConstants, Object object) {
    FacesContext ctx = getCurrentFacesContext();
    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(true);
    session.setAttribute(sessionConstants.getKey(), object);
}

From source file:com.impetus.kwitter.KwitterUtils.java

public static Twitter getTwitterService() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    Twitter twitter = (Twitter) session.getAttribute("twitter");
    if (twitter == null) {
        BeanFactory beanfactory = new ClassPathXmlApplicationContext("appContext.xml");
        twitter = (Twitter) beanfactory.getBean("twitter");
        session.setAttribute("twitter", twitter);
    }/*from w  w w.  j a v a2  s .  c  om*/
    return twitter;
}

From source file:edu.stanford.muse.webapp.Accounts.java

/** adds alternateEmailAddrs if specified in the request to the session. alternateEmailAddrs are simply appended to. */
public static void updateUserInfo(HttpServletRequest request) {
    HttpSession session = request.getSession();

    String ownerName = request.getParameter("name");
    if (!Util.nullOrEmpty(ownerName))
        session.setAttribute("ownerName", ownerName);

    String archiveTitle = request.getParameter("archiveTitle");
    if (!Util.nullOrEmpty(archiveTitle))
        session.setAttribute("archiveTitle", archiveTitle);

    String alt = request.getParameter("alternateEmailAddrs");
    if (Util.nullOrEmpty(alt))
        return;/*from ww w . j a  v a 2 s  . c om*/

    String sessionAlt = (String) JSPHelper.getSessionAttribute(session, "alternateEmailAddrs");
    if (Util.nullOrEmpty(sessionAlt))
        session.setAttribute("alternateEmailAddrs", alt); // this will be removed when we fetch and index email
    else
        session.setAttribute("alternateEmailAddrs", sessionAlt + " " + alt);
    // could also uniquify the emailAddrs here
}

From source file:de.dominikschadow.javasecurity.csrf.CSRFTokenHandler.java

public static String getToken(HttpSession session)
        throws ServletException, NoSuchAlgorithmException, NoSuchProviderException {
    if (session == null) {
        throw new ServletException(MISSING_SESSION);
    }/*from   www  .  j  a  v a 2  s. c  o m*/

    String token = (String) session.getAttribute(CSRF_TOKEN);

    if (StringUtils.isEmpty(token)) {
        token = getToken();
        session.setAttribute(CSRF_TOKEN, token);
    }

    return token;
}

From source file:com.alibaba.citrus.turbine.util.CsrfToken.java

public static void setTokensInSession(HttpSession session, String tokenKey, List<String> tokens) {
    if (tokens.isEmpty()) {
        session.removeAttribute(tokenKey);
    } else {//  w w  w.  j av a  2  s.  c  o  m
        session.setAttribute(tokenKey, StringUtil.join(tokens, CSRF_TOKEN_SEPARATOR));
    }
}

From source file:edu.stanford.muse.webapp.GroupsConfig.java

/** loads session with the given name, and puts it into the given http session. returns true if it succeeded */
public static boolean load(HttpSession session, String title) {
    boolean success = true;
    String cacheDir = (String) JSPHelper.getSessionAttribute(session, "cacheDir");
    Archive archive = JSPHelper.getArchive(session);
    String filename = "";
    if (cacheDir == null) {
        cacheDir = DEFAULT_CACHE_DIR;/*from w w w .ja v  a2  s  .c  o m*/
        session.setAttribute("cacheDir", cacheDir);
    }

    filename = cacheDir + File.separatorChar + title + GROUPING_SUFFIX;
    if (!new File(filename).exists())
        return false;

    JSPHelper.log.info("Loading grouping from " + filename);

    // keep reading till eof exception
    try {
        GroupAssigner ga = (GroupAssigner) Util.readObjectFromFile(filename);
        archive.setGroupAssigner(ga);
    } catch (Exception e) {
        JSPHelper.log.warn("Warning unable to load groups: " + Util.stackTrace(e));
        success = false;
    }

    return success;
}

From source file:com.liusoft.dlog4j.UserLoginManager.java

/**
 * ?//  www . j  a  v  a  2  s .  c o m
 * 
 * @param req
 * @param ubean
 */
public static void updateLoginUser(HttpServletRequest req, UserBean ubean) {
    HttpSession ssn = req.getSession(true);
    if (ssn != null && ubean != null) {
        ssn.setAttribute(SESSION_USER_KEY, SessionUserObject.copyFrom(ubean));
    }
}

From source file:com.ixcode.framework.model.lookup.LookupHandler.java

/**
 * Cleans out the session ready for some new lookups to be defined.
 *//*w ww .ja va  2  s. c o  m*/
public static void initialseLookupContext(HttpSession session) {
    if (log.isDebugEnabled()) {
        log.debug("<initialseLookupContext> : Created a new lookup context");
    }
    session.removeAttribute(SESSION_ATTR_LOOKUP_CONTEXT);
    session.setAttribute(SESSION_ATTR_LOOKUP_CONTEXT, new LookupContext());
}

From source file:de.anycook.session.Session.java

/**
 * Ueberprueft, ob bereits eine INstanz von Sessionhandler in der Session gespeichert ist, wenn
 * wird eine neue erzeugt./*  ww w .  j  av a 2 s  . c o m*/
 *
 * @param session HttpSession des Users
 * @return instanz von Sessionhandler
 */
static public Session init(HttpSession session) {
    if (session.getAttribute("shandler") != null) {
        return (Session) session.getAttribute("shandler");
    }

    Session shandler = new Session();
    session.setAttribute("shandler", shandler);

    return shandler;
}

From source file:org.artifactory.webapp.servlet.RequestUtils.java

public static boolean setAuthentication(HttpServletRequest request, Authentication authentication,
        boolean createSession) {
    HttpSession session = request.getSession(createSession);
    if (session == null) {
        return false;
    }//  w w w  .  j a v a  2 s. c om
    session.setAttribute(LAST_USER_KEY, authentication);
    return true;
}