Example usage for javax.servlet.http HttpSession getId

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

Introduction

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

Prototype

public String getId();

Source Link

Document

Returns a string containing the unique identifier assigned to this session.

Usage

From source file:org.apache.struts.webapp.example.LogoffAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Extract attributes we will need
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(Constants.USER_KEY);

    // Process this user logoff
    if (user != null) {
        if (log.isDebugEnabled()) {
            log.debug(/*  ww w. j a  v a 2s .  com*/
                    "LogoffAction: User '" + user.getUsername() + "' logged off in session " + session.getId());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("LogoffActon: User logged off in session " + session.getId());
        }
    }
    session.removeAttribute(Constants.SUBSCRIPTION_KEY);
    session.removeAttribute(Constants.USER_KEY);
    session.invalidate();

    // Forward control to the specified success URI
    return (mapping.findForward("success"));

}

From source file:com.github.mrstampy.gameboot.web.WebProcessor.java

@Override
public SystemIdKey getSystemId(HttpSession httpSession) {
    return systemIds.get(httpSession.getId());
}

From source file:Binder.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    HttpSession session = req.getSession(true);
    SessionObject o = new SessionObject(getServletContext());
    session.setAttribute("Binder.object", o);
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Session Binder</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("Object bound to session " + session.getId());

    out.println("</body>");
    out.println("</html>");
    out.flush();/*from  w w w  .jav  a2  s  .  c om*/
}

From source file:airport.web.controller.ServicesController.java

@RequestMapping(value = "/service/statistics/common", produces = "application/json")
public Statistics serviceStatisticsCommon(HttpServletRequest request, HttpServletResponse response) {
    User user = new User();
    HttpSession httpSession = request.getSession();
    user.setId(httpSession.getId());

    if (!serviceUsers.checkUserOnline(user)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        if (LOG.isInfoEnabled()) {
            LOG.info("the user isn't authorized. Session id : " + httpSession.getId()
                    + ". URL : /service/statistics/common");
        }//from   w w w  . ja va2  s . com

        return null;
    }

    if (LOG.isInfoEnabled()) {
        LOG.info("user get common statistics. Session id : " + httpSession.getId() + ". User : " + user
                + ". URL : /service/statistics/common");
    }

    return serviceStatistics.getStatisticsAll();
}

From source file:airport.web.controller.ServicesController.java

@RequestMapping(value = "/service/statistics/private", produces = "application/json")
public Statistics serviceStatisticsPrivate(HttpServletRequest request, HttpServletResponse response) {
    User user = new User();
    HttpSession httpSession = request.getSession();
    user.setId(httpSession.getId());

    if (!serviceUsers.checkUserOnline(user)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        if (LOG.isInfoEnabled()) {
            LOG.info("the user isn't authorized. Session id : " + httpSession.getId()
                    + ". URL : /service/statistics/private");
        }//  ww w  .j a  v a 2s .  c  o  m

        return null;
    }

    if (LOG.isInfoEnabled()) {
        LOG.info("user get private statistics. Session id : " + httpSession.getId() + ". User : " + user
                + ". URL : /service/statistics/private");
    }

    return serviceStatistics.getStatisticsUser(user);
}

From source file:airport.web.controller.ServicesController.java

@RequestMapping(value = "/service/runaways", produces = "application/json")
public List<Runaway> getRuaways(HttpServletRequest request, HttpServletResponse response) {
    User user = new User();
    HttpSession httpSession = request.getSession();
    user.setId(httpSession.getId());

    if (!serviceUsers.checkUserOnline(user)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        if (LOG.isInfoEnabled()) {
            LOG.info("the user isn't authorized. Session id : " + httpSession.getId()
                    + ". URL : /service/statistics/private");
        }//w ww . jav  a2s .co  m

        return null;
    }

    if (LOG.isInfoEnabled()) {
        LOG.info("user get private statistics. Session id : " + httpSession.getId() + ". User : " + user
                + ". URL : /service/statistics/private");
    }

    return serviceDispatcher.getAllRunaways();
}

From source file:com.silverpeas.web.UserPriviledgeValidation.java

/**
 * Gets the key of the session of the user calling this web service. The session key is first
 * retrieved from the HTTP header X-Silverpeas-Session. If no such parameter is set, the session
 * is then retrieved from the specified HTTP request. In the case the incoming request isn't sent
 * within an opened HTTP session, then an empty string is returned as no HTTP session was defined
 * for the current request.//w ww.j  av  a2  s .  c  o  m
 *
 * @return the user session key or an empty string if no HTTP session is active for the current
 * request.
 */
private String getUserSessionKey(final HttpServletRequest request) {
    String sessionKey = request.getHeader(HTTP_SESSIONKEY);

    // if no session key is passed among the HTTP headers, check the request is within a session
    if (!isDefined(sessionKey)) {
        HttpSession httpSession = request.getSession(false);
        if (httpSession != null) {
            sessionKey = httpSession.getId();
        }
    }
    return sessionKey;
}

From source file:org.openmrs.web.taglib.DisplayChartTag.java

/**
 * Render graph./*www. j a v  a2s.  com*/
 *
 * @return return result code
 */
public int doStartTag() throws JspException {
    if (chart != null) {
        try {
            HttpSession session = pageContext.getSession();
            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

            Long time = System.currentTimeMillis();
            Double random = Math.random() * 1000.0;
            String key = "chart-" + time + "-" + session.getId() + "-" + random;
            session.setAttribute(key, chart);

            pageContext.getOut()
                    .write("<img src=\"" + request.getContextPath() + "/" + SERVLET_NAME + "?" + CHART_KEY + "="
                            + key + "&mimeType=" + PNG_MIME_TYPE + "&width=" + width + "&height=" + height
                            + "\" />");

        } catch (IOException e) {
            log.error("Unable to generate chart servlet url", e);
        }
    }

    return EVAL_BODY_BUFFERED;
}

From source file:org.jetbrains.webdemo.handlers.ServerHandler.java

@NotNull
private SessionInfo setSessionInfo(final HttpSession session, String originUrl) {
    SessionInfo sessionInfo = new SessionInfo(session.getId());
    UserInfo userInfo = (UserInfo) session.getAttribute("userInfo");

    if (userInfo == null) {
        userInfo = new UserInfo();
        session.setAttribute("userInfo", userInfo);
    }//w w w . java 2 s  . c o  m
    sessionInfo.setUserInfo(userInfo);
    sessionInfo.setOriginUrl(originUrl);
    return sessionInfo;
}

From source file:org.apache.struts.webapp.example2.LogoffAction.java

/**
 * Process the specified HTTP request, and create the corresponding HTTP
 * response (or forward to another web component that will create it).
 * Return an <code>ActionForward</code> instance describing where and how
 * control should be forwarded, or <code>null</code> if the response has
 * already been completed./*from  w ww .  j a v  a  2  s .  co  m*/
 *
 * @param mapping The ActionMapping used to select this instance
 * @param form The optional ActionForm bean for this request (if any)
 * @param request The HTTP request we are processing
 * @param response The HTTP response we are creating
 *
 * @exception Exception if business logic throws an exception
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Extract attributes we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(Constants.USER_KEY);

    // Process this user logoff
    if (user != null) {
        if (log.isDebugEnabled()) {
            log.debug(
                    "LogoffAction: User '" + user.getUsername() + "' logged off in session " + session.getId());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("LogoffActon: User logged off in session " + session.getId());
        }
    }
    session.removeAttribute(Constants.SUBSCRIPTION_KEY);
    session.removeAttribute(Constants.USER_KEY);
    session.invalidate();

    // Forward control to the specified success URI
    return (mapping.findForward("success"));

}