Example usage for javax.servlet.http HttpSession removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

From source file:com.autentia.tnt.util.JPivotUtils.java

/**
 * Ejecuta una query MDX sobre un cubo OLAP utilizando el datasource por defecto. <br>
 * El resultado lo almacena en el contexto de sesin para que pueda ser recogido y pintado por las etiquetas de JPivot.
 * //from   w  ww. j  a va 2s . co m
 * @param mdxQuery query a ejecutar
 * @param cubeSchema URL del que representa el cubo OLAP
 * @return
 * @throws SAXException
 * @throws IOException
 * @throws OlapException
 */
public static OlapModel executeOlapQuery(String mdxQuery, URL schema, HttpSession session)
        throws SAXException, IOException, OlapException {

    final RequestContext context = RequestContext.instance();

    // final URL schema = JpivotUtils.class.getResource(cubeSchema);//new URL("file:///"+cubeSchema);//

    final MondrianModelFactory.Config cfg = new MondrianModelFactory.Config();
    cfg.setMdxQuery(mdxQuery);
    cfg.setSchemaUrl(schema.toExternalForm());
    cfg.setDataSource(DATA_SOURCE);

    final MondrianModel mondrianModel = MondrianModelFactory.instance(cfg);
    final OlapModel olapModel = (OlapModel) mondrianModel.getTopDecorator();
    olapModel.setLocale(context.getLocale());
    // olapModel.setLocale(FacesContext.getCurrentInstance().getViewRoot().getLocale());
    olapModel.setServletContext(context.getSession().getServletContext());
    // olapModel.setServletContext((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext());

    // olapModel.
    olapModel.initialize();

    if (log.isDebugEnabled()) {
        java.util.Enumeration attributeNames = session.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            String name = (String) attributeNames.nextElement();
            log.debug("--- name: " + name + "; type:" + session.getAttribute(name).getClass() + " ---");
        }
    }

    // borramos de la sesion los datos que ha metido JPivot
    // y el model de la consulta que volveremos a meter
    // Esto es necesario porque los tags de JPivot no machacan los
    // valores si ya estn en sesin; por lo que al cambiar de informe
    // sigue mostrando el informe selecionado previamente
    session.removeAttribute(JPivotUtils.QUERY_SESSION_NAME);
    session.removeAttribute(JPivotUtils.TABLE_SESSION_NAME);
    session.removeAttribute(JPivotUtils.NAVI_SESSION_NAME);
    session.removeAttribute(JPivotUtils.SORTFORM_SESSION_NAME);
    session.removeAttribute(JPivotUtils.PRINT_SESSION_NAME);
    session.removeAttribute(JPivotUtils.PRINTFORM_SESSION_NAME);
    session.removeAttribute(JPivotUtils.CHART_SESSION_NAME);
    session.removeAttribute(JPivotUtils.CHARTFORM_SESSION_NAME);
    session.removeAttribute(JPivotUtils.TOOLBAR_SESSION_NAME);

    session.setAttribute(JPivotUtils.QUERY_SESSION_NAME, olapModel);
    return olapModel;
}

From source file:com.stormpath.tooter.controller.PasswordController.java

@RequestMapping(value = "/password/reset", method = RequestMethod.POST)
public String processChangePassword(@ModelAttribute("customer") User user, BindingResult result,
        HttpSession session) {

    changePasswordValidator.validate(user, result);

    if (result.hasErrors()) {
        return "changePassword";
    }/*from w w  w . j av  a 2s.c  om*/

    String sptoken = user.getSptoken();

    if (!StringUtils.hasText(sptoken)) {
        //invalid page access - should have an sptoken from the setup form.
        return "redirect:/password/forgot";
    }

    try {
        //New password was specified - verify the reset token and apply the new password:
        Account account = stormpath.getApplication().verifyPasswordResetToken(sptoken);

        //token is valid, set the password and sync to Stormpath:
        account.setPassword(user.getPassword());
        account.save();

        //remove any stale value:
        session.removeAttribute("stormpathAccount");

    } catch (ResourceException re) {
        result.addError(new ObjectError("password",
                re.getCode() == 404 ? "The provided password reset token is invalid." : re.getMessage()));
        re.printStackTrace();
        return "changePassword";
    }

    //form success
    return "redirect:/login/message?loginMsg=passChanged";
}

From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java

public String loadHome(BaseDBForm form) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logDB.isDebugEnabled())
            logDB.debug("||" + form.getFormName()
                    + "|loadHome|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }// w  ww . j av  a 2s  .  c o m

    session.removeAttribute(DisplayConstants.CURRENT_ACTION);
    session.removeAttribute(DisplayConstants.CURRENT_FORM);
    session.removeAttribute(DisplayConstants.SEARCH_RESULT);
    session.removeAttribute(DisplayConstants.CREATE_WORKFLOW);

    if (logDB.isDebugEnabled())
        logDB.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + form.getFormName() + "|loadHome|Success|Load the Home Page||");

    return ForwardConstants.LOAD_HOME_SUCCESS;
}

From source file:com.google.ie.web.controller.UserController.java

/**
 * Log off the user.Inavidate the current session and remove the cookies
 * /*  w  w w .  j ava2 s  .c o m*/
 * @param request {@link HttpServletRequest} object
 * @param response {@link HttpServletResponse} object
 */
@RequestMapping("/logoff")
private void logOffUser(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) {
    /* Invalidate the session if exists */
    if (httpSession != null) {
        httpSession.setAttribute(WebConstants.USER, null);
        LOGGER.info("Removing cookies from the browser");

        // Clean up stale session state if any
        for (Step2.AxSchema schema : Step2.AxSchema.values()) {
            httpSession.removeAttribute(schema.getShortName());
        }
        httpSession.removeAttribute(OpenIdConstants.REQUEST_TOKEN);
        httpSession.removeAttribute(OpenIdConstants.ACCESS_TOKEN);
        httpSession.removeAttribute(OpenIdConstants.ACCESS_TOKEN_SECRET);
        httpSession.removeAttribute(OpenIdConstants.ACCESSOR);

        /* Remove the cookies */
        removeCookieFromSystem(request, response);
        /* Invalidate the session */
        httpSession.invalidate();

    }
}

From source file:edu.wisc.my.stats.web.DynamicMultiPageFormController.java

/**
 * Adds the page number as a request attribute using the key returned by 
 * {@link #getPageSessionAttributeName(HttpServletRequest)}. If this is
 * a session for the page number is also added to the session using the
 * same key./* w  w  w  . j  ava 2  s  . c  o  m*/
 * 
 * @param request The request to set the page value on.
 * @param page The page value to set on the request and possibly session.
 * @param setInSession If true and is a session form the page will be stored in the session, if false and is a session form the page will be removed from the session.
 */
protected final void addPageNumberToRequest(HttpServletRequest request, int page, boolean setInSession) {
    // Set page session attribute, expose overriding request attribute.
    final Integer pageInteger = new Integer(page);
    final String pageAttrName = this.getPageSessionAttributeName(request);

    if (this.isSessionForm()) {
        final HttpSession session = request.getSession();

        if (setInSession) {
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Setting page session attribute [" + pageAttrName + "] to: " + pageInteger);
            }

            session.setAttribute(pageAttrName, pageInteger);
        } else {
            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Removing page session attribute [" + pageAttrName + "]");
            }

            session.removeAttribute(pageAttrName);
        }
    }

    request.setAttribute(pageAttrName, pageInteger);
}

From source file:info.magnolia.blossom.sample.module.NavigationBar.java

@RequestMapping("/navbar")
public String render(Node page, ModelMap model, HttpSession session) throws RepositoryException {

    Node currentContentNode = MgnlContext.getAggregationState().getCurrentContentNode();
    Node containingPage = currentContentNode.getParent().getParent();
    String requestOrigin = (String) session.getAttribute(REQUEST_ORIGIN_PROPERTY);
    String expectedPrevious = PropertyUtil.getString(currentContentNode, PREVIOUS_PAGE_PROPERTY);
    String next = PropertyUtil.getString(currentContentNode, NEXT_PAGE_PROPERTY);

    boolean inEdit = PropertyUtil.getBoolean(currentContentNode, IN_EDIT_PROPERTY, true);
    String path = containingPage.getPath();
    if (expectedPrevious != null && !inEdit && !expectedPrevious.equals(requestOrigin)) {
        //Redirect to Origin of Flow
        String originOfFlow = PropertyUtil.getString(currentContentNode, REQUEST_ORIGIN_PROPERTY) + ".html";
        session.removeAttribute(REQUEST_ORIGIN_PROPERTY);
        return "redirect:" + originOfFlow;
    }//  w  w  w.j  a v a2s  . c o  m

    session.removeAttribute(REQUEST_ORIGIN_PROPERTY);
    session.setAttribute(REQUEST_ORIGIN_PROPERTY, path);
    model.put(PREVIOUS_PAGE_PROPERTY, expectedPrevious);
    model.put(NEXT_PAGE_PROPERTY, next);

    return "components/navbar.jsp";
}

From source file:edu.txstate.dmlab.clusteringwiki.web.IndexController.java

@RequestMapping("index.*")
public String getIndexPage(HttpServletRequest request, HttpServletResponse response, Model model) {
    if (request.getParameter("test") != null) {
        String executionId = request.getParameter("test").toLowerCase();
        if (executionId.equals("train")) {
            //user is requesting the training track.  Generate a new unique ID for this test
            executionId = testExecutionDao.addTrainingTest();
            return "redirect:index.html?test=" + executionId;
        }/*from   www . j  a v  a 2 s.com*/
        if (isValidExecutionId(executionId)) {
            //starting test
            final HttpSession session = request.getSession(true);
            if (session.getAttribute("testId") != null && !session.getAttribute("testId").equals(executionId)) {
                request.setAttribute("message", "A test is already in progress in this session.<br>"
                        + "Please finish the current test of stop the test from the top menu before starting another.");
                return "pageError";
            }
            session.setAttribute("executionId", executionId);
        } else {
            request.setAttribute("message", "Your test execution id is invalid.  Please try again.");
            return "pageError";
        }
    } else if (request.getParameter("endTest") != null) {
        //end in progress test
        final HttpSession session = request.getSession(false);
        if (session != null)
            session.removeAttribute("executionId");
    }
    return "index";
}

From source file:cn.loveapple.service.controller.member.action.MemberController.java

/**
 * ???????/*from  w ww.  j  av  a 2  s  .co m*/
 * 
 * @param form
 * @param result
 * @return
 */
@RequestMapping(value = "auth", method = RequestMethod.POST)
public String auth(@Valid MemberAuthForm form, BindingResult result, HttpSession session) {
    if (result.hasErrors()) {
        return "member/index";
    }

    LoveappleMemberModel member = memberCoreService.authenticateLoveappleMember(form.getMail(),
            form.getPassword());

    if (member == null) {
        result.reject("loveappleErrors.auth");
        return "member/index";
    }

    session.setAttribute(LOVEAPPLE_MEMBER, member);

    Object refererUrl = session.getAttribute(REFERER_INNER_URL);
    if (log.isDebugEnabled()) {
        log.debug("auth will redirect? [" + refererUrl + "]");
    }
    if (refererUrl != null) {
        session.removeAttribute(REFERER_INNER_URL);
        return "redirect:" + refererUrl;
    }
    return "redirect:/member/core/info/" + member.getKey().getId();
}

From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java

/**
 * now that we have a session we try to create a monitor with id token
 * if it already exists, an exception will be thrown
 *//*from   w  w w.j av  a  2 s  . co m*/
private void establishNewMonitor(@NotNull HttpServletResponse response,
        @NotNull HttpServletRequestWrapper requestWrapper, @NotNull String token, @NotNull HttpSession session)
        throws IOException {
    PrintWriter outWriter = null;
    GroovyMonitor monitor = null;
    String monitorArgs = parseArgs(requestWrapper);
    try {
        monitor = createMonitor(requestWrapper, session, token, monitorArgs, response);
        response.setStatus(HttpServletResponse.SC_OK);
        if (monitor != null)
            // keep output stream open
            monitor.waitLoop();
    } finally {
        if (monitor != null) {
            synchronized (session) {
                try {
                    session.removeAttribute(monitor.getToken());
                } catch (IllegalStateException e) {
                    // intentionally nothing; denotes that the session has been invalidated
                    // by another thread
                }
            }
        }
    }
}