Example usage for javax.servlet.http HttpSession getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Usage

From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeCreateAction.java

private static CommandGroup lookupCommandGroup(DynaActionForm form, HttpSession session) {
    CommandGroup result = null;/* w w w. j av a  2 s  .  c o m*/
    String name = form.getString(COMMAND_GROUP);
    if (StringUtils.isBlank(name)) {
        name = (String) session.getAttribute(SELECTED_COMMAND_GROUP_SESSION);
        if (StringUtils.isBlank(name)) {
            name = ModifyProbeCommand.COMMAND_GROUP_DEFAULT;
        }
    }
    session.setAttribute(SELECTED_COMMAND_GROUP_SESSION, name);
    result = MonitoringManager.getInstance().lookupCommandGroup(name);
    assert result != null;
    return result;
}

From source file:edu.cornell.mannlib.vitro.webapp.filestorage.TempFileHolder.java

/**
 * Get the {@link TempFileHolder} which is stored as an attribute on this
 * session, extract the {@link FileInfo} from it, and remove it from the
 * session.//  www.jav  a2s.com
 * 
 * If there is no such attribute, of if it is not a {@link TempFileHolder},
 * return null.
 */
public static FileInfo remove(HttpSession session, String attributeName) {
    if (session == null) {
        throw new NullPointerException("session may not be null.");
    }
    if (attributeName == null) {
        throw new NullPointerException("attributeName may not be null.");
    }
    Object attribute = session.getAttribute(attributeName);
    if (attribute instanceof TempFileHolder) {
        FileInfo fileInfo = ((TempFileHolder) attribute).extractFileInfo();
        session.removeAttribute(attributeName);
        log.debug("remove this file: " + fileInfo);
        return fileInfo;
    } else if (attribute == null) {
        return null;
    } else {
        session.removeAttribute(attributeName);
        return null;
    }
}

From source file:mercury.BaseHandler.java

public static Properties getI18nProperties(final HttpSession session, String module) {
    String lang = (String) (session.getAttribute("I18N"));

    if (lang == null || lang.trim().equals("")) {
        lang = "pt_BR";
        session.setAttribute("I18N", lang);
    }/*from ww w .  ja va2 s  . co  m*/

    String attrName = "I18N_" + module + "." + lang;
    ServletContext sc = session.getServletContext();

    return (Properties) (sc.getAttribute(attrName));
}

From source file:com.bsb.cms.commons.web.MossActionUtils.java

/**
 * ?? ???<s:debug></s:debug> 
 * //  w w w .j  a v a  2 s  .co  m
 * @param req
 */
@SuppressWarnings("all")
@Deprecated
public static void print(HttpServletRequest req) {
    // Application
    Map<String, Object> parameters = new WeakHashMap<String, Object>();

    // attributes in scope RequestParameter
    for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        String[] v = req.getParameterValues(name);
        if (v.length == 1) {
            if (v[0].equals(""))
                continue;
            parameters.put(name, v[0]);
        } else
            parameters.put(name, v);
    }

    // attributes in scope Request
    for (Enumeration e = req.getAttributeNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        Object v = req.getAttribute(name);
        parameters.put(name, v);
    }

    // attributes in scope Session
    HttpSession session = req.getSession();
    for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        Object v = session.getAttribute(name);
        parameters.put(name, v);
    }

    Set keys = parameters.keySet();
    Iterator it = keys.iterator();
    String key;
    Object value;
    while (it.hasNext()) {
        key = (String) it.next();
        value = parameters.get(key);
        System.out.println("key:" + key + ", value:" + value);
    }

}

From source file:eionet.util.SecurityUtil.java

/**
 * Returns current user, or null, if the current session does not have user attached to it.
 *///from w ww . ja  va  2s.  c  o  m
public static final DDUser getUser(HttpServletRequest request) {

    HttpSession session = request.getSession();
    DDUser user = session == null ? null : (DDUser) session.getAttribute(REMOTEUSER);

    if (user == null) {
        String casUserName = session == null ? null : (String) session.getAttribute(CASFilter.CAS_FILTER_USER);
        if (casUserName != null) {
            user = DDCASUser.create(casUserName);
            session.setAttribute(REMOTEUSER, user);
        }
    } else if (user instanceof DDCASUser) {
        String casUserName = (String) session.getAttribute(CASFilter.CAS_FILTER_USER);
        if (casUserName == null) {
            user.invalidate();
            user = null;
            session.removeAttribute(REMOTEUSER);
        } else if (!casUserName.equals(user.getUserName())) {
            user.invalidate();
            user = DDCASUser.create(casUserName);
            session.setAttribute(REMOTEUSER, user);
        }
    }

    if (user != null) {
        return user.isAuthentic() ? user : null;
    } else {
        return null;
    }
}

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

public static Authentication getAuthentication(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return null;
    }/*from  w ww.j a v  a2  s . co m*/
    return (Authentication) session.getAttribute(LAST_USER_KEY);
}

From source file:edu.harvard.i2b2.fhir.server.ws.I2b2Helper.java

static Bundle parsePatientIdToFetchPDO(HttpSession session, String requestUri, String queryString,
        String resourceName, PatientBundleManager service, ProjectPatientMapManager ppmservice,
        String patientId) throws XQueryUtilException, JAXBException, IOException, AuthenticationFailure,
        FhirServerException, InterruptedException {
    AccessToken tok = (AccessToken) session.getAttribute("accessToken");

    //if not specified in call extract from Url
    if (patientId == null) {
        patientId = FhirUtil.extractPatientId(queryString);
    }//from w  w w  .  j ava 2 s  .  com

    logger.info("PatientId:" + patientId);
    //if also not found in url 
    if (patientId == null)
        patientId = FhirUtil.extractPatientIdFromRequestById(requestUri, resourceName);
    logger.info("PatientId:" + patientId);

    if (patientId != null) {
        // filter.put("Patient", "Patient/" + patientId);
        return I2b2Helper.getPdo(tok, patientId, service, ppmservice);
    } else {
        if (resourceName.equals("Patient")) {
            //throw new FhirServerException("Search on patients is not allowed. Patient id needs to be specified");
            return I2b2Helper.initAllPatients(tok, ppmservice);
        }
    }
    return null;
}

From source file:com.lushapp.common.web.utils.WebUtils.java

/**
 * ?sessiont attribute/*from w ww  .ja v a2  s  . co  m*/
 *
 * @param name ??
 * @return T
 */
public static <T> T getSessionAttribute(HttpSession session, String name) {
    return (T) session.getAttribute(name);
}

From source file:com.adito.vfs.webdav.DAVServlet.java

/**
 * Get the {@link DAVProcessor} from the session.
 * /*from w  w  w. j  av a  2s .  c  om*/
 * @param session sesison
 * @return processor
 * @throws CoreException on any error
 * @throws Exception on any error
 */
public static DAVProcessor getDAVProcessor(HttpSession session) throws Exception {
    DAVProcessor processor = (DAVProcessor) session.getAttribute(PROCESSOR_ATTR);
    if (processor == null) {
        VFSRepository repository = VFSRepository.getRepository(session);
        processor = new DAVProcessor(repository);
        processors.add(processor);
        session.setAttribute(PROCESSOR_ATTR, processor);
        session.setAttribute(SESSION_INVALIDATE_LISTENER_ATTR, new SessionInvalidateListener(processor));
        if (log.isInfoEnabled())
            log.info("Initialized repository");
    }
    return processor;
}

From source file:in.mycp.utils.Commons.java

public static User getCurrentUser() {
    SecurityContext securityContext = SecurityContextHolder.getContext();
    HttpSession session = null;
    Object obj = null;//  w  w  w.j  a  va2 s.  c  o m
    try {
        session = WebContextFactory.get().getSession();
        setSessionAttribute("MYCP_SIGNUP_MSG", "");
        obj = session.getAttribute("CurrentUser");
    } catch (Exception e) {
        // e.printStackTrace();
    }
    // if this is after the first call from DWR
    if (obj != null) {
        return (User) obj;
        // if this is teh first call from DWR
    } else if (obj == null && session != null) {
        User currentUser = User.findUsersByEmailEquals(securityContext.getAuthentication().getName())
                .getSingleResult();
        session.setAttribute("CurrentUser", currentUser);
        return currentUser;
        // for non DWR calls
    } else {
        //System.out.println("securityContext.getAuthentication().getName() = " + securityContext.getAuthentication().getName());
        User currentUser = User.findUsersByEmailEquals(securityContext.getAuthentication().getName())
                .getSingleResult();
        return currentUser;
    }
}