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:gov.nih.nci.caarray.web.fileupload.MonitoredMultiPartRequest.java

/**
 * Release the progress monitor for the upload associated with the given request.
 *
 * @param request the current HTTP request
 *///from  ww  w  .  j ava2 s .c om
public static void releaseProgressMonitor(HttpServletRequest request) {
    String uploadKey = getUploadKey(request);
    request.getSession().removeAttribute(uploadKey);
}

From source file:be.fedict.eid.idp.sp.protocol.openid.AuthenticationRequestServlet.java

/**
 * Used by the {@link AuthenticationResponseServlet} for processing the
 * returned OpenID response/* w ww . j  av a  2s.co  m*/
 * 
 * @param request
 *            HTTP Servlet Request, used to get the OpenID
 *            {@link ConsumerManager} from the {@link ServletContext}
 * @return the OpenID {@link ConsumerManager}
 */
public static ConsumerManager getConsumerManager(HttpServletRequest request) {
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    ConsumerManager consumerManager = (ConsumerManager) servletContext.getAttribute(CONSUMER_MANAGER_ATTRIBUTE);
    if (null == consumerManager) {
        throw new IllegalStateException("no ConsumerManager found in ServletContext");
    }
    return consumerManager;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils.java

public static EditConfigurationVTwo getEditConfiguration(HttpServletRequest request) {
    HttpSession session = request.getSession();
    EditConfigurationVTwo editConfiguration = EditConfigurationVTwo.getConfigFromSession(session, request);
    return editConfiguration;
}

From source file:com.opencnc.controllers.ModeloController.java

/**
 * *****************************************************************************
 * Crea los modelos por usuario./* w  w w  . j a va  2 s .  co m*/
 * *****************************************************************************
 * @param request
 * @param response
 * @return
 * @throws Exception 
 */
@RequestMapping("/modelo/crearModelo")
static ModelAndView crearModelo(HttpServletRequest request, HttpServletResponse response) throws Exception {

    HttpSession sess = request.getSession();
    if (sess != null) {
        Modelo md = new Modelo();
        ModelAndView m = new ModelAndView("/modelo/crearModelo");
        m.addObject("modelo", md);
        Session s = HibernateUtil.getSessionFactory().openSession();
        //Usuario us = (Usuario)request.getAttribute("usuario");
        Usuario us = (Usuario) sess.getAttribute("usuario");

        Criteria c = s.createCriteria(TipoMaquina.class);
        Criteria ma = s.createCriteria(UnidadMedida.class);
        Criteria user = s.createCriteria(Usuario.class);

        List<UnidadMedida> lm = ma.list();
        List<TipoMaquina> l = c.list();
        //List<Usuario> luser = user.list();
        Integer luser = us.getUsuarioId();

        m.addObject("listaTipoMaquina", l);
        m.addObject("listaUnidadMedida", lm);
        m.addObject("listaUsuarios", luser);
        m.addObject("nombreUsuario", us.getNombre());
        //HttpSession session = request.getSession();
        //m.addObject("numUsuarioId", us.getUsuarioId());
        return m;
    } else {
        request.removeAttribute("usuario");
        return new ModelAndView("redirect:/usuario/login.htm");
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java

public static String getSessionAttributes(HttpServletRequest req) {
    String val = "<table>";
    Enumeration names = req.getSession().getAttributeNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        val += "\n\t<tr><td><h3>" + name + "</h3><td><pre>";
        String value = null;/*from w  ww.ja  v  a2 s. c o  m*/
        try {
            Object obj = req.getSession().getAttribute(name);
            value = (obj instanceof Model || obj instanceof ModelCom) ? "[Jena model object]"
                    : (obj == null) ? "[null]" : StringEscapeUtils.escapeHtml(obj.toString());
        } catch (Exception ex) {
            value = "unable to get value";
        } catch (Error er) {
            value = "unable to get value";
        } catch (Throwable th) {
            value = "unable to get value";
        }
        val += value + "</pre></td></tr>\n";
    }
    return val + "</table>";
}

From source file:com.manydesigns.elements.messages.SessionMessages.java

protected static BlockingQueue<String> getQueue(String queueName) {
    HttpServletRequest req = ElementsThreadLocals.getHttpServletRequest();
    if (req == null) {
        logger.debug("No request available. Returning dummy queue.");
        return new LinkedBlockingQueue<String>();
    }/*from w w w  .jav a2  s  .co  m*/
    HttpSession session = req.getSession();
    BlockingQueue<String> infoQueue;
    synchronized (session) {
        infoQueue = (BlockingQueue) session.getAttribute(queueName);
        if (infoQueue == null) {
            // install a new queue
            infoQueue = new LinkedBlockingQueue<String>();
            session.setAttribute(queueName, infoQueue);
        }
    }
    return infoQueue;
}

From source file:cn.bc.web.util.DebugUtils.java

public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) {
    @SuppressWarnings("rawtypes")
    Enumeration e;/*from w w w  .j a va  2 s.c om*/
    String name;
    StringBuffer html = new StringBuffer();

    //session
    HttpSession session = request.getSession();
    html.append("<div><b>session:</b></div><ul>");
    html.append(createLI("Id", session.getId()));
    html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString()));
    html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString()));

    //session:attributes
    e = session.getAttributeNames();
    html.append("<li>attributes:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, String.valueOf(session.getAttribute(name))));
    }
    html.append("</ul></li>\r\n");
    html.append("</ul>\r\n");

    //request
    html.append("<div><b>request:</b></div><ul>");
    html.append(createLI("URL", request.getRequestURL().toString()));
    html.append(createLI("QueryString", request.getQueryString()));
    html.append(createLI("Method", request.getMethod()));
    html.append(createLI("CharacterEncoding", request.getCharacterEncoding()));
    html.append(createLI("ContentType", request.getContentType()));
    html.append(createLI("Protocol", request.getProtocol()));
    html.append(createLI("RemoteAddr", request.getRemoteAddr()));
    html.append(createLI("RemoteHost", request.getRemoteHost()));
    html.append(createLI("RemotePort", request.getRemotePort() + ""));
    html.append(createLI("RemoteUser", request.getRemoteUser()));
    html.append(createLI("ServerName", request.getServerName()));
    html.append(createLI("ServletPath", request.getServletPath()));
    html.append(createLI("ServerPort", request.getServerPort() + ""));
    html.append(createLI("Scheme", request.getScheme()));
    html.append(createLI("LocalAddr", request.getLocalAddr()));
    html.append(createLI("LocalName", request.getLocalName()));
    html.append(createLI("LocalPort", request.getLocalPort() + ""));
    html.append(createLI("Locale", request.getLocale().toString()));

    //request:headers
    e = request.getHeaderNames();
    html.append("<li>Headers:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, request.getHeader(name)));
    }
    html.append("</ul></li>\r\n");

    //request:parameters
    e = request.getParameterNames();
    html.append("<li>Parameters:<ul>\r\n");
    while (e.hasMoreElements()) {
        name = (String) e.nextElement();
        html.append(createLI(name, request.getParameter(name)));
    }
    html.append("</ul></li>\r\n");

    html.append("</ul>\r\n");

    //response
    html.append("<div><b>response:</b></div><ul>");
    html.append(createLI("CharacterEncoding", response.getCharacterEncoding()));
    html.append(createLI("ContentType", response.getContentType()));
    html.append(createLI("BufferSize", response.getBufferSize() + ""));
    html.append(createLI("Locale", response.getLocale().toString()));
    html.append("<ul>\r\n");
    return html;
}

From source file:com.vmware.appfactory.file.upload.ProgressReporter.java

/**
 * This method initializes the progress reporting by creating a new uploadId and storing it in the
 * user session for use when a file upload happens.
 *
 * @param request//from  ww w. ja v  a 2  s  . c  o  m
 * @param uploadId
 */
public static void initProgressListener(HttpServletRequest request, String uploadId) {
    if (StringUtils.isEmpty(uploadId)) {
        // If no key, we will not initiate any upload tracking session variable.
        _log.warn("No uploadKey passed, ignore this request.");
        return;
    }
    request.getSession().setAttribute(UPLOAD_REQUEST_ID, uploadId);
    _log.debug("added uploadKey: {} into session", uploadId);
}

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

/**
 * //from   w  ww . j ava 2s  .  c om
 * @param req
 * @return
 */
public static HttpServletRequest getMyRequestInstance(HttpServletRequest req) {
    // we dont use getLanguageFromLayoutParam because this may cause loop getLanguageFromLayoutParam -> alfrescoConnector -> getMyRequestInstance -> getLanguageFromLayoutParam
    String value = (String) req.getSession().getAttribute(LanguageSetter.SHARE_LANG);
    if (StringUtils.trimToNull(value) != null) {
        MyHttpRequestServletAdaptator myreq = new MyHttpRequestServletAdaptator(req);
        String key = ACCEPT_LANGUAGE;

        String replace = value.replace('_', '-');
        logger.debug("getMyRequestInstance set Language to " + replace);
        myreq.setHeader(key, replace);
        return myreq;
    } else {
        logger.debug("getMyRequestInstance no language stored in session use ");
    }

    return req;

}

From source file:net.sf.ginp.config.Configuration.java

/**
 * Sets the default value of configfilelocation.
 * @param req The current servlet request
 *//*from   w  ww. ja v  a 2 s . c o  m*/
public static void setConfigfilelocation(final HttpServletRequest req) {
    setConfigfilelocation(req.getSession().getServletContext().getRealPath(PATH_TO_CONFIG_FROM_WEBROOT));
}