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.dspace.webmvc.utils.Authenticate.java

/**
 * Log the user out/*from   ww  w .j a v  a 2 s  . c  o  m*/
 * 
 * @param context
 *            DSpace context
 * @param request
 *            HTTP request
 */
public static void loggedOut(Context context, HttpServletRequest request) {
    HttpSession session = request.getSession();

    context.setCurrentUser(null);
    request.removeAttribute("isadmin");
    request.removeAttribute("dspace.current.user");
    session.removeAttribute("dspace.current.user.id");

    // Keep the user's locale setting if set
    Locale sessionLocale = getSessionLocale(request);

    // Invalidate session unless dspace.cfg says not to
    if (ConfigurationManager.getBooleanProperty("webui.session.invalidate", true)) {
        session.invalidate();
    }

    // Restore the session locale
    if (sessionLocale != null) {
        //Config.set(request.getSession(), Config.FMT_LOCALE, sessionLocale);
        session.setAttribute("FMT_LOCALE", sessionLocale);
    }
}

From source file:org.apache.beehive.netui.pageflow.MultipartRequestUtils.java

/**
 * Create an implementation of a {@link MultipartRequestHandler} for this
 * mulitpart request./* w w w.  ja v a2s.  c  o  m*/
 *
 * @param request the current request object
 * @return the handler
 * @throws ServletException if an error occurs loading this file.  These exception messages
 * are not internationalized as Struts does not internationalize them either.
 */
// @Struts: org.apache.struts.util.RequestUtils.getMultipartHandler
private static final 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) RequestUtils.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(
                    "InstantiaionException 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 = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    multipartClass = moduleConfig.getControllerConfig().getMultipartClass();

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

        if (multipartHandler != null)
            return multipartHandler;
    }

    return multipartHandler;
}

From source file:com.threewks.thundr.request.servlet.ServletSupport.java

/**
 * Set the request attributes to the given set.
 * /*  w  w w . j a va2  s.co  m*/
 * @param request
 * @param attributes
 */
public static void setAttributes(HttpServletRequest request, Map<String, Object> attributes) {
    if (request != null) {
        List<String> existing = list(iterable(request.getAttributeNames()));
        List<String> toRemove = list(existing).removeItems(attributes.keySet());
        for (String remove : toRemove) {
            request.removeAttribute(remove);
        }
        addAttributes(request, attributes);
    }
}

From source file:org.jaffa.presentation.portlet.CustomRequestProcessor.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>
 *
 * @param request The HTTP request for which the multipart handler should
 *                be found./*  www. j  av a 2 s.c o m*/
 * @return the multipart handler to use, or null if none is
 *         found.
 *
 * @exception 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) RequestUtils.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) RequestUtils.applicationInstance(multipartClass);

        } catch (ClassNotFoundException cnfe) {
            throw new ServletException("Cannot find multipart class \"" + multipartClass + "\""
                    + ", exception: " + cnfe.getMessage());

        } catch (InstantiationException ie) {
            throw new ServletException("InstantiationException when instantiating " + "multipart class \""
                    + multipartClass + "\", exception: " + ie.getMessage());

        } catch (IllegalAccessException iae) {
            throw new ServletException("IllegalAccessException when instantiating " + "multipart class \""
                    + multipartClass + "\", exception: " + iae.getMessage());
        }

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

    return multipartHandler;
}

From source file:com.glaf.core.res.MessageUtils.java

/**
 * Adds the specified messages keys into the appropriate request attribute
 * for use by the &lt;html:messages&gt; tag (if messages="true" is set), if
 * any messages are required. Initialize the attribute if it has not already
 * been. Otherwise, ensure that the request attribute is not set.
 * //from  ww  w.  ja  v  a 2 s . c om
 * @param request
 *            The servlet request we are processing
 * @param messages
 *            Messages object
 * @since Struts 1.2.1
 */
public static void addMessages(HttpServletRequest request, ViewMessages messages) {
    if (messages == null) {
        // bad programmer! *slap*
        return;
    }

    // get any existing messages from the request, or make a new one
    ViewMessages viewMessages = (ViewMessages) request.getAttribute(Globals.MESSAGE_KEY);

    if (viewMessages == null) {
        viewMessages = new ViewMessages();
    }

    // add incoming messages
    viewMessages.add(messages);

    // if still empty, just wipe it out from the request
    if (viewMessages.isEmpty()) {
        request.removeAttribute(Globals.MESSAGE_KEY);
        return;
    }

    log.debug("save viewMessages...");

    // Save the messages
    request.setAttribute(Globals.MESSAGE_KEY, viewMessages);
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Clear the Servlet spec's error attributes as {@link javax.servlet.http.HttpServletRequest}
 * attributes under the keys defined in the Servlet 2.3 specification:
 * {@code javax.servlet.error.status_code},
 * {@code javax.servlet.error.exception_type},
 * {@code javax.servlet.error.message},//from   w w  w  . j a  v  a2s.  c om
 * {@code javax.servlet.error.exception},
 * {@code javax.servlet.error.request_uri},
 * {@code javax.servlet.error.servlet_name}.
 * @param request current servlet request
 */
public static void clearErrorRequestAttributes(HttpServletRequest request) {
    request.removeAttribute(ERROR_STATUS_CODE_ATTRIBUTE);
    request.removeAttribute(ERROR_EXCEPTION_TYPE_ATTRIBUTE);
    request.removeAttribute(ERROR_MESSAGE_ATTRIBUTE);
    request.removeAttribute(ERROR_EXCEPTION_ATTRIBUTE);
    request.removeAttribute(ERROR_REQUEST_URI_ATTRIBUTE);
    request.removeAttribute(ERROR_SERVLET_NAME_ATTRIBUTE);
}

From source file:org.codehaus.groovy.grails.web.util.WebUtils.java

private static void cleanupIncludeRequestAttributes(HttpServletRequest request, Map<String, Object> toRestore) {
    request.removeAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE);
    request.removeAttribute(INCLUDE_CONTEXT_PATH_ATTRIBUTE);
    request.removeAttribute(INCLUDE_SERVLET_PATH_ATTRIBUTE);
    request.removeAttribute(INCLUDE_PATH_INFO_ATTRIBUTE);
    request.removeAttribute(INCLUDE_QUERY_STRING_ATTRIBUTE);

    for (Map.Entry<String, Object> entry : toRestore.entrySet()) {
        request.setAttribute(entry.getKey(), entry.getValue());
    }/*  w ww  . ja v  a  2  s. c o m*/
}

From source file:org.jahia.services.applications.pluto.JahiaPortletUtil.java

/**
 * Remove from request useless attributes
 *
 * @param portalRequest//from w  w  w . java 2 s  .c  om
 * @return
 */
public static Map<String, Object> filterJahiaAttributes(HttpServletRequest portalRequest) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    @SuppressWarnings("unchecked")
    List<String> names = EnumerationUtils.toList(portalRequest.getAttributeNames());
    for (String key : names) {
        if (isSpringAttribute(key)) {
            Object value = portalRequest.getAttribute(key);
            map.put(key, value);
            portalRequest.removeAttribute(key);
        }
    }

    return map;
}

From source file:org.dd4t.mvc.utils.RenderUtils.java

public static void removeViewModelsFromRequest(final HttpServletRequest request) {
    final ComponentPresentation componentPresentation = ComponentUtils.getComponentPresentation(request);
    if (componentPresentation != null && componentPresentation.getAllViewModels() != null) {
        LOG.debug("Removing STM entries");
        for (final Map.Entry<String, BaseViewModel> modelEntry : componentPresentation.getAllViewModels()
                .entrySet()) {//from   w  w  w.ja  v  a2 s .  com
            request.removeAttribute(modelEntry.getKey());
        }
    }
}

From source file:com.ibm.jaggr.core.impl.layer.LayerTest.java

static private LayerImpl newLayerImpl(String layerKey, IAggregator aggregator) {
    @SuppressWarnings("serial")
    LayerImpl result = new LayerImpl(layerKey, ++id) {
        @Override// w  ww .j a v a2s.co  m
        public InputStream getInputStream(HttpServletRequest request, HttpServletResponse response)
                throws IOException {
            request.removeAttribute(AbstractHttpTransport.LAYERCONTRIBUTIONSTATE_REQATTRNAME);
            return super.getInputStream(request, response);
        }
    };
    result.setLayerBuildsAccessor(new LayerBuildsAccessor(id,
            (ConcurrentLinkedHashMap<String, CacheEntry>) ((LayerCacheImpl) aggregator.getCacheManager()
                    .getCache().getLayers()).getLayerBuildMap(),
            aggregator.getCacheManager(), new ReentrantReadWriteLock(), null, null));
    result.setReportCacheInfo(true);
    return result;
}