Example usage for javax.servlet.http HttpSession getMaxInactiveInterval

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

Introduction

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

Prototype

public int getMaxInactiveInterval();

Source Link

Document

Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.

Usage

From source file:com.mobileman.projecth.web.controller.InitController.java

private static void initApplication(HttpServletRequest request) {
    // workaround for OpenSessionInView spring class
    webApplicationContext = RequestContextUtils.getWebApplicationContext(request);
    OpenSessionFilter.setWebApplicationContext(webApplicationContext);
    //load menus/*from w  w w.  j  a  v  a2  s  . c  om*/
    HttpSession session = request.getSession();
    session.getServletContext().setAttribute("menu", new Menu(request));
    //session timeout seconds
    session.getServletContext().setAttribute("session_timeout_seconds", session.getMaxInactiveInterval());
}

From source file:org.openmrs.module.clinicalsummary.web.controller.evaluator.EvaluateReminderController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(final @RequestParam(required = false, value = "cohort") Integer cohortId,
        final HttpSession session) {
    int maxInactiveInterval = session.getMaxInactiveInterval();
    session.setMaxInactiveInterval(-1);/*from  ww w  .j  a  v  a  2s.  c o  m*/
    Cohort cohort = Context.getCohortService().getCohort(cohortId);
    ReminderCohortEvaluatorInstance.getInstance().evaluate(new Cohort(cohort.getMemberIds()));
    session.setMaxInactiveInterval(maxInactiveInterval);
    return "redirect:evaluateReminder.form";
}

From source file:org.openmrs.module.clinicalsummary.web.controller.evaluator.EvaluatePatientsController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(final @RequestParam(required = false, value = "cohort") Integer cohortId,
        final @RequestParam(required = false, value = "summaryId") Integer summaryId,
        final HttpSession session) {
    int maxInactiveInterval = session.getMaxInactiveInterval();
    session.setMaxInactiveInterval(-1);//w  ww  . jav  a  2  s  .  c o m

    Summary summary = Context.getService(SummaryService.class).getSummary(summaryId);
    Cohort cohort = Context.getCohortService().getCohort(cohortId);

    SummaryCohortEvaluatorInstance instance = SummaryCohortEvaluatorInstance.getInstance();
    instance.evaluate(new Cohort(cohort.getMemberIds()), Arrays.asList(summary));

    session.setMaxInactiveInterval(maxInactiveInterval);
    return "redirect:evaluatePatients.form";
}

From source file:org.openmrs.module.clinicalsummary.web.controller.evaluator.EvaluateCohortController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(
        final @RequestParam(required = false, value = "patientIdentifiers") String patientIdentifiers,
        final @RequestParam(required = false, value = "locationId") String locationId,
        final @RequestParam(required = false, value = "obsStartDate") Date startDate,
        final @RequestParam(required = false, value = "obsEndDate") Date endDate, final HttpSession session) {

    int maxInactiveInterval = session.getMaxInactiveInterval();
    session.setMaxInactiveInterval(-1);/*from   w w w  . j av  a 2s. c  om*/

    if (StringUtils.isBlank(locationId) && StringUtils.isBlank(patientIdentifiers)) {
        session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "clinicalsummary.invalid.parameters");
    } else {
        Cohort cohort = new Cohort();
        if (StringUtils.isNotBlank(patientIdentifiers)) {
            String[] patientIdentifier = StringUtils.split(patientIdentifiers);
            cohort = Context.getPatientSetService().convertPatientIdentifier(Arrays.asList(patientIdentifier));
        } else if (StringUtils.isNotBlank(locationId)) {
            Location location = Context.getLocationService().getLocation(NumberUtils.toInt(locationId, -1));
            cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, startDate, endDate);
        }
        SummaryCohortEvaluatorInstance instance = SummaryCohortEvaluatorInstance.getInstance();
        instance.evaluate(cohort);
    }
    session.setMaxInactiveInterval(maxInactiveInterval);
    return "redirect:evaluateCohort.form";
}

From source file:org.openmrs.module.clinicalsummary.web.controller.evaluator.EvaluateRuleController.java

@RequestMapping(method = RequestMethod.POST)
public String processForm(final @RequestParam(required = false, value = "locationId") String locationId,
        final @RequestParam(required = false, value = "obsStartDate") Date startDate,
        final @RequestParam(required = false, value = "obsEndDate") Date endDate, final HttpSession session) {

    int maxInactiveInterval = session.getMaxInactiveInterval();
    session.setMaxInactiveInterval(-1);//www .  j  a v a2 s .  c o  m
    Location location = Context.getLocationService().getLocation(NumberUtils.toInt(locationId, -1));
    Cohort cohort = Context.getService(CoreService.class).getDateCreatedCohort(location, startDate, endDate);

    Integer counter = 0;
    int firstElement = 0;
    for (Integer patientId : cohort.getMemberIds()) {
        Patient patient = Context.getPatientService().getPatient(patientId);
        SummaryService service = Context.getService(SummaryService.class);
        // reuse index that's already exists but not needed anymore
        List<Index> activeIndexes = Context.getService(IndexService.class).getIndexes(patient);
        List<Summary> summaries = service.getSummaries(patient);
        while (!activeIndexes.isEmpty()) {
            Index activeIndex = activeIndexes.remove(firstElement);
            if (CollectionUtils.isNotEmpty(summaries) && !summaries.contains(activeIndex.getSummary()))
                Context.getService(IndexService.class).deleteIndex(activeIndex);
        }
        counter++;
        if (counter % 20 == 0) {
            Context.flushSession();
            Context.clearSession();
        }
        ResultCacheInstance.getInstance().clearCache(patient);
    }
    session.setMaxInactiveInterval(maxInactiveInterval);
    return "redirect:evaluateRule.form";
}

From source file:com.sentinel.web.controllers.LoginController.java

/**
 * api to set session timeout for current HttpSession. timeoutInSeconds is
 * optional parameter. If not set, will be defaulted to 24 hours (86400s)
 * /*from w w  w  .  j  av a  2s  .c  om*/
 * @param timeoutInSeconds
 * @param httpSession
 * @return
 */
@RequestMapping(method = RequestMethod.PUT, value = "/loginsession/timeout")
public @ResponseBody String setSessionTimeout(
        @RequestParam(value = "timeoutInSeconds", defaultValue = "86400") int timeoutInSeconds,
        HttpSession httpSession) {
    httpSession.setMaxInactiveInterval(timeoutInSeconds);
    return "httpSession timeout set to:" + httpSession.getMaxInactiveInterval();
}

From source file:com.boundlessgeo.geoserver.api.controllers.LoginController.java

/**
 * API endpoint for determining if a user is logged in
 * //from  w  ww.  j ava 2 s .  co m
 * @param req HTTP request
 * @param res HTTP response
 * @return JSON object containing the session id, the session timeout interval, 
 * and the GeoServer user, if applicable.
 */
@RequestMapping()
public @ResponseBody JSONObj handle(HttpServletRequest req, HttpServletResponse res) {
    JSONObj obj = new JSONObj();

    HttpSession session = req.getSession(false);
    if (session != null) {
        obj.put("session", session.getId());
        obj.put("timeout", session.getMaxInactiveInterval());
    }

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    Object principal = auth.getPrincipal();
    if (principal instanceof GeoServerUser) {
        GeoServerUser user = (GeoServerUser) principal;
        obj.put("user", user.getUsername());
        //PKI Authentication
    } else if (auth instanceof PreAuthenticatedAuthenticationToken && principal instanceof String) {
        obj.put("user", principal);
    }

    return obj;
}

From source file:org.seratic.enterprise.tgestiona.web.filter.AppHttpSessionListener.java

@Override
public void sessionDestroyed(HttpSessionEvent se) {
    Log log = LogFactory.getLog("Aplicacion");
    HttpSession session = se.getSession();
    long now = new java.util.Date().getTime();
    boolean timeout = (now - session.getLastAccessedTime()) >= ((long) session.getMaxInactiveInterval()
            * 1000L);//from  w  ww .  ja  v  a2 s  .  c om
    if (timeout) {
        long duration = new Date().getTime() - session.getCreationTime();
        long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
        long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);
        long diffInHours = TimeUnit.MILLISECONDS.toHours(duration);
        SimpleDateFormat formatFechaHora = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        log.info("Sesiones-> Finalizacion automatica de sesion");
        log.info("Sesiones-> Id Sesion: " + session.getId());
        log.info("Sesiones-> Fecha creacion sesion: "
                + formatFechaHora.format(new Date(session.getCreationTime())));
        log.info("Sesiones-> Tiempo conexion sesion, " + diffInHours + " Horas " + diffInMinutes + " Minutos "
                + diffInSeconds + " Segundos.");
        log.info("Sesiones-> Fecha ultima peticion: "
                + formatFechaHora.format(new Date(session.getLastAccessedTime())));
        log.info("Sesiones-> Fecha sesion timeout: " + formatFechaHora
                .format(new Date(session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000)));
    }
}

From source file:SessionTimer.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    HttpSession session = req.getSession();

    out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
    out.println("<BODY><H1>Session Timer</H1>");

    out.println("The previous timeout was " + session.getMaxInactiveInterval());
    out.println("<BR>");

    session.setMaxInactiveInterval(2 * 60 * 60); // two hours

    out.println("The newly assigned timeout is " + session.getMaxInactiveInterval());

    out.println("</BODY></HTML>");
}

From source file:org.romaframework.web.session.HttpAbstractSessionAspect.java

public int getTimeout() {
    HttpSession sess = (HttpSession) getActiveSystemSession();
    if (sess != null)
        return sess.getMaxInactiveInterval() / 60;
    return -1;/*from   w w  w.java  2s.  c  om*/
}