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:org.consultjr.mvc.core.components.ApplicationInterceptor.java

private HttpSession getSession(HttpServletRequest request) {
    return request.getSession();
}

From source file:com.cloudbees.demo.beesshop.cart.ShoppingCartRepository.java

@Nonnull
public ShoppingCart getCurrentShoppingCart(@Nonnull HttpServletRequest request) {
    HttpSession session = request.getSession();
    ShoppingCart shoppingCart = (ShoppingCart) session.getAttribute(ShoppingCart.class.getName());
    if (shoppingCart == null) {
        shoppingCart = new ShoppingCart();
        session.setAttribute(ShoppingCart.class.getName(), shoppingCart);
    }//  w w w  .  j a v  a 2  s  .  c  o  m
    return shoppingCart;
}

From source file:com.zuoxiaolong.blog.common.authorization.AuthorizationInterceptor.java

private void checkLogin(HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (ObjectUtils.isEmpty(session.getAttribute("username"))) {
        throw new BusinessException(ExceptionType.AUTHORIZATION_ERROR);
    }//from w w  w .j  av  a2 s.  c o  m
}

From source file:de.berlios.jhelpdesk.web.tools.ThemeCustomResolever.java

public String resolveThemeName(HttpServletRequest req) {
    User currentUser = (User) req.getSession().getAttribute("user");
    if (currentUser != null) {
        return currentUser.getPreferredTheme();
    }//from w  w w.ja  va  2  s.c  om

    Cookie themeCookie = WebUtils.getCookie(req, "jhd_theme");
    if (themeCookie != null) {
        return themeCookie.getValue();
    }
    return defaultThemeName;
}

From source file:fi.vm.sade.organisaatio.resource.SessionResource.java

/**
 * Palauttaa session erntymisen aikarajan sekunteina.
 *
 * @param req HTTP kutsu, jossa on session id
 * @return session erntymisen aikaraja sekunteina
 *//*  w w w. j a  v a 2  s  . c o  m*/
@GET
@Path("/maxinactiveinterval")
@PreAuthorize("isAuthenticated()")
@Produces(MediaType.TEXT_PLAIN)
public String maxInactiveInterval(@Context HttpServletRequest req) {
    return Integer.toString(req.getSession().getMaxInactiveInterval());
}

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

/**
 * Add the headers required for the browser to popup an authentication
 * dialog for a specified realm, and send the
 * {@link HttpServletResponse.SC_UNAUTHORIZED} HTTP response code.
 * //from w  w  w. j  a  v a  2s. co m
 * @param request request
 * @param response response
 * @param realm realm.
 * @throws IOException
 */
public static void sendAuthorizationError(HttpServletRequest request, HttpServletResponse response,
        String realm) throws IOException {
    /*
     * If this is for the default realm (i.e Adito Authentication, we
     * need to set up an authentication scheme
     */
    if (realm.equals(WebDAVAuthenticationModule.DEFAULT_REALM)) {
        configureAuthenticationScheme(request, response);
    }

    // Configure the response

    if (log.isDebugEnabled())
        log.debug("Sending auth request for realm " + realm);
    response.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    request.getSession().setAttribute(DAVTransaction.ATTR_EXPECTING_REALM_AUTHENTICATION, realm);

}

From source file:com.vtxii.smallstuff.etl.filewatcher.FileWatcherController.java

@RequestMapping(value = "/status", method = RequestMethod.GET)
public @ResponseBody String handleStatusRequest(HttpServletRequest request) {
    Monitor monitor = (Monitor) request.getSession().getServletContext().getAttribute(ContextListener.MONITOR);
    logger.debug("handling status request with monitor: {}", monitor);
    return monitor.getStatus();
}

From source file:edu.ijse.tcd.controller.LogInController.java

@RequestMapping(value = "logout", method = RequestMethod.GET)
public String logout(ModelMap map, HttpServletRequest request) {
    HttpSession hs = request.getSession();
    hs.removeAttribute("user");
    return "login";
}

From source file:be.fedict.eid.applet.service.impl.HttpServletProtocolContext.java

/**
 * Main constructor./*from w  w w .  j ava2s  .c o  m*/
 * 
 * @param request
 */
public HttpServletProtocolContext(HttpServletRequest request) {
    this.session = request.getSession();
}

From source file:com.osbitools.ws.shared.prj.web.GenericPrjMgrWsSrvServlet.java

public DiskFileItemFactory getDiskFileItemFactory(HttpServletRequest req) {
    return (DiskFileItemFactory) req.getSession().getServletContext().getAttribute("dfi");
}