Example usage for javax.servlet.http HttpServletRequest removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes an attribute from this request.

Usage

From source file:org.fornax.cartridges.sculptor.framework.web.hibernate.DisconnectHibernateInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception exc) {//from w  w  w . j  a v  a2s  .c  om
    Session hibernateSession = (Session) request.getAttribute(HIBERNATE_SESSION_ATTRIBUTE);
    if (hibernateSession != null) {
        request.removeAttribute(HIBERNATE_SESSION_ATTRIBUTE);
        if (hibernateSession.isConnected()) {
            hibernateSession.disconnect();
        }
    }
}

From source file:org.apache.struts.webapp.validator.MultiRegistrationAction.java

/**
 * Convenience method for removing the obsolete form bean.
 *
 * @param mapping The ActionMapping used to select this instance
 * @param request The HTTP request we are processing
 *//* w w w .ja  v a  2s.c  o m*/
protected void removeFormBean(ActionMapping mapping, HttpServletRequest request) {

    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
        if ("request".equals(mapping.getScope())) {
            request.removeAttribute(mapping.getAttribute());
        } else {
            HttpSession session = request.getSession();
            session.removeAttribute(mapping.getAttribute());
        }
    }
}

From source file:uk.ac.ox.oucs.vle.mvc.CourseDispatcherServlet.java

/**
 * this is overridden to ensure that the Native URL is present.
 *///from w  ww  .  java 2 s  .  c  o m
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL);
    try {
        super.service(request, response);
    } finally {
        request.removeAttribute(Tool.NATIVE_URL);
    }

}

From source file:org.silverpeas.processmanager.servlets.SessionSafeFunctionHandler.java

/**
 * Reset token Id./*  w  w  w .j  a va 2 s. c  o m*/
 * @param session the process manager session controller
 * @param request the http servlet request
 */
protected void resetTokenId(ProcessManagerSessionController session, HttpServletRequest request) {
    session.setCurrentTokenId(null);
    request.removeAttribute("currentTokenId");
}

From source file:org.jahia.services.seo.jcr.VanityUrlMapper.java

/**
 * checks if a vanity exists and put the result as an attribute of the request
 * this is used in urlRewriting rules// ww w .jav a  2  s  .c  om
 * @param hsRequest
 *              the request used during urlRewriting operations
 * @param outboundUrl
 *              the url received to be checked
 */
public void checkVanityUrl(HttpServletRequest hsRequest, String outboundContext, String outboundUrl) {
    hsRequest.removeAttribute(VANITY_KEY);

    URLResolverFactory urlResolverFactory = (URLResolverFactory) SpringContextSingleton
            .getBean("urlResolverFactory");
    VanityUrlService vanityUrlService = (VanityUrlService) SpringContextSingleton
            .getBean("org.jahia.services.seo.jcr.VanityUrlService");

    String ctx = StringUtils.defaultIfEmpty(hsRequest.getContextPath(), "");
    String fullUrl = ctx + Render.getRenderServletPath() + outboundUrl;
    hsRequest.setAttribute(VANITY_KEY, fullUrl);

    if (StringUtils.isNotEmpty(outboundUrl) && !Url.isLocalhost(hsRequest.getServerName())) {
        String serverName = null;
        String siteKey = null;
        String contextToCheck = outboundContext;
        int schemaDelimiterIndex = outboundContext.indexOf("://");
        if (schemaDelimiterIndex != -1) {
            try {
                URI uri = new URI(outboundContext);
                siteKey = lookupSiteKeyByServerName(uri.getHost());
                if (siteKey != null) {
                    contextToCheck = uri.getPath();
                    StringBuffer sb = new StringBuffer().append(uri.getScheme()).append("://")
                            .append(uri.getHost());
                    if (uri.getPort() != -1) {
                        sb.append(':').append(uri.getPort());
                    }
                    serverName = sb.toString();
                }
            } catch (URISyntaxException e) {
                // simply continue as siteKey will be determined later
            }
        } else if (StringUtils.isNotEmpty(
                (String) hsRequest.getAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK))) {
            String host = (String) hsRequest.getAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK);
            host = StringUtils.substringBefore(StringUtils.substringAfter(host, "://"), ":");
            siteKey = lookupSiteKeyByServerName(host);
        }
        if (StringUtils.equals(ctx, contextToCheck)) {
            String url = "/render" + outboundUrl;
            try {
                url = URLDecoder.decode(url, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // shouldn't happen
                throw new RuntimeException(e);
            }
            URLResolver urlResolver = urlResolverFactory.createURLResolver(url, hsRequest.getServerName(),
                    hsRequest);
            try {
                JCRNodeWrapper node = urlResolver.getNode();
                if (urlResolver.isMapped()) {
                    RenderContext context = (RenderContext) hsRequest.getAttribute("renderContext");
                    if (siteKey == null) {
                        siteKey = context != null ? context.getSite().getSiteKey()
                                : node.getResolveSite().getSiteKey();
                    }
                    VanityUrl vanityUrl = vanityUrlService.getVanityUrlForWorkspaceAndLocale(node,
                            urlResolver.getWorkspace(), urlResolver.getLocale(), siteKey);
                    if (vanityUrl != null && vanityUrl.isActive()) {
                        //for macros some parameters added (like ##requestParameters## for languageswitcher)
                        String macroExtension = "";
                        if (fullUrl.matches("(.?)*##[a-zA-Z]*##$")) {
                            macroExtension = "##" + StringUtils.substringBetween(fullUrl, "##") + "##";
                        }
                        hsRequest.setAttribute(VANITY_KEY, ctx + Render.getRenderServletPath() + "/"
                                + urlResolver.getWorkspace() + vanityUrl.getUrl() + macroExtension);
                        if (serverName != null) {
                            hsRequest.setAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK,
                                    serverName);
                        }
                    }
                }
            } catch (RepositoryException e) {
                logger.debug("Error when trying to obtain vanity url", e);
                if (serverName != null) {
                    hsRequest.setAttribute(ServerNameToSiteMapper.ATTR_NAME_SERVERNAME_FOR_LINK, serverName);
                }
            }
        }
    }
}

From source file:org.withinsea.izayoi.adapter.springmvc.SpringIzayoiDispatcherFilter.java

@Override
protected void noHandlerFound(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    FilterChain chain = (FilterChain) req.getAttribute(CARRIER_CHAIN_ATTR);
    req.removeAttribute(CARRIER_CHAIN_ATTR);
    if (chain == null) {
        noHandlerFound0(req, resp);/*from   w  w w.j a v  a  2s  .co  m*/
    } else {
        ServletFilterUtils.chain(req, resp, chain, cloister, glowworm, cortile);
    }
}

From source file:org.impalaframework.extension.mvc.flash.FlashHelper.java

void mergeFlashState(HttpServletRequest request, ModelMap modelMap) {
    final Map<String, Object> flashState = (Map<String, Object>) request.getAttribute("flashState");
    if (flashState != null) {
        modelMap.mergeAttributes(flashState);
        request.removeAttribute("flashState");
    }/*  w  w  w. j  av  a 2s. c om*/
}

From source file:org.nuxeo.ecm.webengine.app.WebEngineFilter.java

public void cleanup(Config config, AbstractWebContext ctx, HttpServletRequest request,
        HttpServletResponse response) {//from   ww  w  . j  ava  2  s.  c o  m
    try {
        closeTx(config, request);
    } finally {
        request.removeAttribute(WebContext.class.getName());
    }
}

From source file:org.apache.struts.util.RequestUtils.java

/**
 * <p>Try to locate a multipart request handler for this request. First,
 * look for a mapping-specific handler stored for us under an attribute.
 * If one is not present, use the global multipart handler, if there is
 * one.</p>/*from  w w  w.  j a v a  2  s  . c om*/
 *
 * @param request The HTTP request for which the multipart handler should
 *                be found.
 * @return the multipart handler to use, or null if none is found.
 * @throws ServletException if any exception is thrown while attempting to
 *                          locate the multipart handler.
 */
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException {
    MultipartRequestHandler multipartHandler = null;
    String multipartClass = (String) request.getAttribute(Globals.MULTIPART_KEY);

    request.removeAttribute(Globals.MULTIPART_KEY);

    // Try to initialize the mapping specific request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, "
                    + "defaulting to global multipart class");
        } catch (InstantiationException ie) {
            log.error(
                    "InstantiationException when instantiating " + "MultipartRequestHandler \"" + multipartClass
                            + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage());
        } catch (IllegalAccessException iae) {
            log.error(
                    "IllegalAccessException when instantiating " + "MultipartRequestHandler \"" + multipartClass
                            + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage());
        }

        if (multipartHandler != null) {
            return multipartHandler;
        }
    }

    ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);

    multipartClass = moduleConfig.getControllerConfig().getMultipartClass();

    // Try to initialize the global request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"", cnfe);
        } catch (InstantiationException ie) {
            throw new ServletException(
                    "InstantiationException when instantiating " + "multipart class \"" + multipartClass + "\"",
                    ie);
        } catch (IllegalAccessException iae) {
            throw new ServletException(
                    "IllegalAccessException when instantiating " + "multipart class \"" + multipartClass + "\"",
                    iae);
        }

        if (multipartHandler != null) {
            return multipartHandler;
        }
    }

    return multipartHandler;
}

From source file:cz.jirutka.spring.exhandler.RestHandlerExceptionResolver.java

protected ResponseEntity<?> handleException(Exception exception, HttpServletRequest request) {
    // See http://stackoverflow.com/a/12979543/2217862
    // This attribute is never set in MockMvc, so it's not covered in integration test.
    request.removeAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);

    RestExceptionHandler<Exception, ?> handler = resolveExceptionHandler(exception.getClass());

    LOG.debug("Handling exception {} with response factory: {}", exception.getClass().getName(), handler);
    return handler.handleException(exception, request);
}