Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:gr.abiss.calipso.userDetails.util.SecurityUtil.java

public static void logout(HttpServletRequest request, HttpServletResponse response,
        UserDetailsConfig userDetailsConfig) {
    addCookie(request, response, userDetailsConfig.getCookiesBasicAuthTokenName(), null, true,
            userDetailsConfig);/*from   w  w  w. ja  v a 2 s. co m*/
    addCookie(request, response, COOKIE_NAME_SESSION, null, true, userDetailsConfig);
    HttpSession session = request.getSession();
    if (session == null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("logout, no session to clear");
        }
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("logout, invalidating session");
        }
        session.invalidate();
    }
}

From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.LanguageSetter.java

public static String getLanguageFromLayoutParam(HttpServletRequest req, RequestContext context)
        throws ServletException {
    logger.debug("# getLanguageFromLayoutParam ...");
    User user = context.getUser();//w w w.j  a  va 2s  .  c o  m
    String userId = context.getUserId();
    String urlLang = req.getParameter(SHARE_LANG);
    HttpSession currentSession = req.getSession();
    String sessionLang = (String) currentSession.getAttribute(SHARE_LANG);
    if (logger.isTraceEnabled()) {
        logger.trace("urlLang : " + urlLang);
        logger.trace("sessionLang : " + sessionLang);
    }

    // set language

    String language = null;
    // is no user or guest use browser language
    if (user != null && !userId.toLowerCase().equals("guest")) {
        if (urlLang != null) {
            language = urlLang;
            if (logger.isDebugEnabled()) {
                logger.debug("Use language in url :" + urlLang);
            }
        } else if (sessionLang != null && currentSession.getAttribute(userSessionok) != null) {
            // only if language already loaded from preference
            if (logger.isDebugEnabled()) {
                logger.debug("Use language stored in session :" + sessionLang);
            }
            language = sessionLang;

        } else {
            // initialize user language
            try {
                language = getUserLanguage(userId, req);
                logger.debug("Use language from user preferences :" + language);

            } catch (ConnectorServiceException e) {
                throw new ServletException(e);
            } catch (JSONException e) {
                throw new ServletException(e);
            }
            if (language == null) {
                // language not yet set so use default from browser
                language = getLanguageFromBrowser(req);
                logger.debug("Use language from browser :" + language);
            }
            currentSession.setAttribute(userSessionok, true);
        }
    } else {
        // language not yet set so use default from browser
        language = getLanguageFromBrowser(req);
        logger.debug("no user or Guest, use language from browser :" + language);
    }

    return language;

}

From source file:com.jdon.strutsutil.FormBeanUtil.java

/**
 * ActionForm?struts_config.xmlattribute
 * /*from  w ww.  j  a v  a 2  s .  c  o m*/
 * @param form
 * @param mapping
 * @param request
 */
public static void saveActionForm(ActionForm form, ActionMapping mapping, HttpServletRequest request) {
    if ((form != null) && (mapping.getAttribute() != null)) {
        if ("request".equals(mapping.getScope())) {
            request.setAttribute(mapping.getAttribute(), form);
        } else {
            HttpSession session = request.getSession();
            session.setAttribute(mapping.getAttribute(), form);
            request.setAttribute(mapping.getAttribute(), form);
        }
    }
}

From source file:org.tapestry.surveys.DoSurveyAction.java

public static TapestrySurveyMap getSurveyMapAndStoreInSession(HttpServletRequest request,
        List<SurveyResult> surveyResults, List<SurveyTemplate> surveyTemplates) {
    TapestrySurveyMap userSurveys = (TapestrySurveyMap) request.getSession()
            .getAttribute("session_survey_list");

    //if survey list not in the session, retrieve from server
    if (userSurveys == null) {
        userSurveys = new TapestrySurveyMap(getSurveyResultsList(surveyResults, surveyTemplates));
        request.getSession().setAttribute("session_survey_list", userSurveys);
    }//from w  w w.  ja v a 2s  . c om

    return (userSurveys);
}

From source file:edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder.java

public static void checkIndexOnRootLogin(HttpServletRequest req) {
    HttpSession session = req.getSession();
    ServletContext context = session.getServletContext();
    IndexBuilder indexBuilder = (IndexBuilder) context.getAttribute(IndexBuilder.class.getName());

    log.debug("Checking if the index is empty");
    if (indexBuilder.indexer.isIndexEmpty()) {
        log.info("Search index is empty. Running a full index rebuild.");
        indexBuilder.doIndexRebuild();// w  w w  . j  av a 2 s. c  o  m
    }
}

From source file:com.ineunet.knife.upload.WebPaths.java

/**
 * @param request HttpServletRequest/*from ww w .  jav a2 s  .  c  o m*/
 */
public static void init(HttpServletRequest request) {
    if (request == null) {
        return;
    }
    if (inited)
        return;
    // init rootUrl
    String reqUrl = request.getRequestURL().toString();
    String reqUri = request.getRequestURI();
    int index = reqUrl.length() - reqUri.length();
    rootUrl = reqUrl.substring(0, index) + request.getContextPath();

    // init rootPath
    rootPath = request.getSession().getServletContext().getRealPath("/");

    // set flag
    inited = true;
}

From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java

/**
 * A utlity method to check the valid value againts the dropdown options
 * Author for method: /*from  ww  w. ja va  2  s.com*/
 * @param input - the data to be validated
 * @param source - the source against which the input to be validated
 * @param request - http request
 * @return boolean
 */
public static boolean isValidValue(String input, String source, HttpServletRequest request) {
    String trimInput = input.trim();

    // validate for intentCode
    List dropDownList = (List) request.getSession().getAttribute(source);
    String nv = null;
    boolean validValue = true;
    if (trimInput != null && trimInput.length() > 0 && dropDownList != null) {
        // assign the value to false
        validValue = false;

        for (int i = 0; i < dropDownList.size(); i++) {
            nv = ((DropdownOption) dropDownList.get(i)).getValue();
            if (nv.equals(input)) {
                validValue = true;
                break;
            }
        }
    }
    return validValue;
}

From source file:com.jaspersoft.jasperserver.war.common.JasperServerUtil.java

public static TimeZone getTimezone(HttpServletRequest request) {
    String timeZoneId = (String) request.getSession()
            .getAttribute(JasperServerConstImpl.getUserTimezoneSessionAttr());
    return getTimezone(timeZoneId);
}

From source file:cz.incad.kramerius.k5.k5velocity.K5APIRetriever.java

public static String getAsString(String queryString, HttpServletRequest req) throws IOException {

    org.apache.velocity.tools.generic.ResourceTool rt = new ResourceTool();
    Map<String, String> c = new HashMap<String, String>();
    c.put("bundles", "res.configuration");
    rt.configure(c);/*from   ww w  .j  av a2  s  . c  o m*/
    String k5addr = rt.get("k5addr").toString() + queryString;

    ForwardServlet.TypeOfCall tc = disectTypeOfCall(queryString);
    User user = tc.getUser((CallUserController) req.getSession().getAttribute(CallUserController.KEY));

    LOGGER.info("requesting url " + k5addr);

    StringWriter sw = new StringWriter();
    InputStream inputStream = null;
    if (user != null) {
        inputStream = RESTHelper.inputStream(k5addr, user.getUserName(), user.getPassword());
    } else {
        inputStream = RESTHelper.inputStream(k5addr);
    }
    org.apache.commons.io.IOUtils.copy(inputStream, sw, "UTF-8");
    return sw.toString();
}

From source file:com.hangum.tadpole.session.manager.SessionManager.java

/**
 * logout  ./*from   w  w w  . j  a  v a2  s . co  m*/
 */
public static void logout() {
    HttpServletRequest request = RWT.getRequest();
    try {
        HttpSession sStore = request.getSession();
        sStore.setAttribute(NAME.USER_SEQ.toString(), 0);
        sStore.invalidate();
    } catch (Throwable e) {
        // ignore exception
    }

    // fixed https://github.com/hangum/TadpoleForDBTools/issues/708
    // ps - ? session id    ? ? ?. - hangum
    String[] arryRequestURL = StringUtils.split(request.getRequestURL().toString(), ";");
    String browserText = MessageFormat.format("parent.window.location.href = \"{0}\";", arryRequestURL[0]);
    JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
    executor.execute("setTimeout('" + browserText + "', 100)");

}