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:com.vmware.appfactory.file.upload.ProgressReporter.java

/**
 * Removes the ProgressListener from the HttpSession associated with the input parameter uploadId.
 *
 * @param request//w w w . j  a  v  a  2 s  .c o m
 * @param uploadId
 */
public static void removeProgressListener(HttpServletRequest request, String uploadId) {
    if (uploadId != null) {
        String sessionKey = createSessionKey(uploadId);
        request.getSession().removeAttribute(sessionKey);
        _log.trace("Remove session attr with key: " + sessionKey);
    }
}

From source file:io.lavagna.web.helper.UserSession.java

public static void invalidate(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) {
    req.getSession().invalidate();
    Cookie c = getCookie(req, "LAVAGNA_REMEMBER_ME");
    if (c != null) {
        deleteTokenIfExist(c.getValue(), userRepository);
        c.setMaxAge(0);//from w w  w.j  a  v  a 2s  .c o  m
        c.setValue(null);
        resp.addCookie(c);
    }
}

From source file:edu.umich.its.lti.google.GoogleConfigJsonWriter.java

/**
 *  Getting the shared folder id from the Session instead of setting service as call to Setting service intermittently not fetching correct value.
 * @param tcSessionData//from w  w  w.  ja v a2  s  .com
 * @param result
 * @param request
 */
static private void appendLinkedFolders(TcSessionData tcSessionData, StringBuilder result,
        HttpServletRequest request) {
    // setting mapping
    result.append("[");
    try {
        String link = (String) request.getSession()
                .getAttribute(GoogleLtiServlet.SETTING_SERVICE_VALUE_IN_SESSION);
        if (link != null) {
            result.append("\"").append(escapeQuotesForJson(TcSiteToGoogleStorage.parseLink(link).getFolderId()))
                    .append("\"");
        }
    } catch (Exception e) {
        M_log.error("Failed to load the string that has the Shared folder information", e);
    }
    result.append("]");
}

From source file:com.util.ConvertJspToStringHtml.java

public static String generateHtml(String url, HttpServletRequest request, HttpServletResponse response) {
    String html = null;//w  w  w.  j  a  v  a2  s .c o  m
    try {
        BufferedHttpResponseWrapper wrapper = new BufferedHttpResponseWrapper(response);
        ServletContext context = request.getSession().getServletContext();
        String urlEncode = response.encodeRedirectURL(url);
        RequestDispatcher dispatcher = context.getRequestDispatcher(urlEncode);
        dispatcher.include(request, wrapper);
        //            html = ASCII2Unicode(StringEscapeUtils.unescapeHtml(wrapper.getOutput()));

        html = html.replaceAll("\\r\\n|\\r|\\n", "");
        html = html.replaceAll(" ", "");
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return html;
}

From source file:edu.ucsd.library.xdre.web.MarcModsImportController.java

public static Map<String, String> getCountryCodes(HttpServletRequest request) throws DocumentException {
    Map<String, String> countryCodes = new TreeMap<>();
    File dataFile = new File(
            request.getSession().getServletContext().getRealPath("files/country-code-iso-3166-all.xml"));
    SAXReader reader = new SAXReader();
    Document dataDoc = reader.read(dataFile);
    List<Node> nodes = dataDoc.selectNodes("//country");
    for (Node node : nodes) {
        String name = node.selectSingleNode("@name").getStringValue().trim();
        String alpha2 = node.selectSingleNode("@alpha-2").getStringValue().trim();
        countryCodes.put(name, alpha2);/*  w  w  w.  j  a v  a  2s.  co m*/
    }

    return countryCodes;
}

From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale.java

/**
 * Do we need to override the Locale in the current request? return the
 * first of these to be found:/*from   w  w  w  . j  a v  a2  s.c  o  m*/
 * <ul>
 * <li>The forced Locale in the servlet context</li>
 * <li>The selected Locale in the session</li>
 * <li>The first of the selectable Locales</li>
 * <li>null</li>
 * </ul>
 */
public static Locale getOverridingLocale(HttpServletRequest req) {
    HttpSession session = req.getSession();
    ServletContext ctx = session.getServletContext();

    Object ctxInfo = ctx.getAttribute(ATTRIBUTE_NAME);
    if (ctxInfo instanceof ContextSelectedLocale) {
        Locale forcedLocale = ((ContextSelectedLocale) ctxInfo).getForcedLocale();
        if (forcedLocale != null) {
            log.debug("Found forced locale in the context: " + forcedLocale);
            return forcedLocale;
        }
    }

    Object sessionInfo = session.getAttribute(ATTRIBUTE_NAME);
    if (sessionInfo instanceof SessionSelectedLocale) {
        Locale selectedLocale = ((SessionSelectedLocale) sessionInfo).getSelectedLocale();
        if (selectedLocale != null) {
            log.debug("Found selected locale in the session: " + selectedLocale);
            return selectedLocale;
        }
    }

    if (ctxInfo instanceof ContextSelectedLocale) {
        List<Locale> selectableLocales = ((ContextSelectedLocale) ctxInfo).getSelectableLocales();
        if (selectableLocales != null && !selectableLocales.isEmpty()) {
            Locale defaultLocale = selectableLocales.get(0);
            log.debug("Using first selectable locale as default: " + defaultLocale);
            return defaultLocale;
        }
    }

    return null;
}

From source file:eionet.gdem.web.struts.stylesheet.StylesheetListLoader.java

public static void clearPermissions(HttpServletRequest httpServletRequest) {
    httpServletRequest.getSession().removeAttribute(STYLESHEET_PERMISSIONS_ATTR);
}

From source file:eionet.gdem.web.struts.stylesheet.StylesheetListLoader.java

public static void clearLists(HttpServletRequest httpServletRequest) {
    httpServletRequest.getSession().getServletContext().removeAttribute(STYLESHEET_LIST_ATTR);
    httpServletRequest.getSession().getServletContext().removeAttribute(STYLESHEET_GENERATED_LIST_ATTR);
    httpServletRequest.getSession().getServletContext().removeAttribute(CONVERSION_SCHEMAS_ATTR);
}

From source file:net.shibboleth.idp.oidc.util.OIDCUtils.java

/**
 * Put session attribute.//  w w w  .j a va  2  s.  c om
 *
 * @param request   the request
 * @param parameter the parameter
 * @param value     the value
 */
public static void putSessionAttribute(final HttpServletRequest request, final String parameter,
        final Object value) {
    final HttpSession session = request.getSession();
    session.setAttribute(parameter, value);
}

From source file:com.sifcoapp.report.util.ReportConfigUtil.java

public static String getJasperFilePath(HttpServletRequest request, String compileDir, String jasperFile) {
    return request.getSession().getServletContext().getRealPath(compileDir + jasperFile);
}