List of usage examples for javax.servlet ServletRequest removeAttribute
public void removeAttribute(String name);
From source file:org.acmsl.commons.utils.http.HttpServletUtils.java
/** * Removes an object from the repository. * @param key the key.//from ww w . j a v a2 s . c om * @param request the request. * @param session the session. * @param context the context. * @return <code>true</code> if the object has been removed successfully. */ public boolean remove(@NotNull final String key, @Nullable final ServletRequest request, @Nullable final HttpSession session, @Nullable final ServletContext context) { boolean result = false; // Thanks Sun for had missed an interface for // all classes that export setAttribute(). if (request != null) { request.removeAttribute(key); result = true; } if (session != null) { session.removeAttribute(key); result = true; } if (context != null) { context.removeAttribute(key); result = true; } return result; }
From source file:org.ajax4jsf.webapp.BaseFilter.java
/** * Execute the filter./*from ww w .ja va 2 s . c o m*/ */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long startTimeMills = 0; // Detect case of request - normal, AJAX, AJAX - JavaScript // TODO - detect first processing in filter. HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; if (log.isDebugEnabled()) { startTimeMills = System.currentTimeMillis(); log.debug(Messages.getMessage(Messages.FILTER_START_INFO, new Date(startTimeMills), httpServletRequest.getRequestURI())); } if (request.getAttribute(FILTER_PERFORMED) != Boolean.TRUE) { // mark - and not processing same request twice. try { request.setAttribute(FILTER_PERFORMED, Boolean.TRUE); String ajaxPushHeader = httpServletRequest.getHeader(AJAX_PUSH_KEY_HEADER); // check for a push check request. if (httpServletRequest.getMethod().equals("HEAD") && null != ajaxPushHeader) { PushEventsCounter listener = eventsManager.getListener(ajaxPushHeader); // To avoid XmlHttpRequest parsing exceptions. httpServletResponse.setContentType("text/plain"); if (listener.isPerformed()) { listener.processed(); httpServletResponse.setStatus(HttpServletResponse.SC_OK); httpServletResponse.setHeader(AJAX_PUSH_STATUS_HEADER, AJAX_PUSH_READY); if (log.isDebugEnabled()) { log.debug("Occurs event for a id " + ajaxPushHeader); } } else { // Response code - 'No content' httpServletResponse.setStatus(HttpServletResponse.SC_ACCEPTED); if (log.isDebugEnabled()) { log.debug("No event for a id " + ajaxPushHeader); } } httpServletResponse.setContentLength(0); } else // check for resource request if (!getResourceService().serviceResource(httpServletRequest, httpServletResponse)) { // Not request to resource - perform filtering. // first stage - detect/set encoding of request. Same as in // Myfaces External Context. setupRequestEncoding(httpServletRequest); processUploadsAndHandleRequest(httpServletRequest, httpServletResponse, chain); } } finally { // Remove filter marker from response, to enable sequence calls ( for example, forward to error page ) request.removeAttribute(FILTER_PERFORMED); Object ajaxContext = request.getAttribute(AjaxContext.AJAX_CONTEXT_KEY); if (null != ajaxContext && ajaxContext instanceof AjaxContext) { ((AjaxContext) ajaxContext).release(); request.removeAttribute(AjaxContext.AJAX_CONTEXT_KEY); } } } else { if (log.isDebugEnabled()) { log.debug(Messages.getMessage(Messages.FILTER_NO_XML_CHAIN_2)); } chain.doFilter(request, response); } if (log.isDebugEnabled()) { startTimeMills = System.currentTimeMillis() - startTimeMills; log.debug(Messages.getMessage(Messages.FILTER_STOP_INFO, "" + startTimeMills, httpServletRequest.getRequestURI())); } }
From source file:org.apache.catalina.core.ApplicationDispatcher.java
/** * Ask the resource represented by this RequestDispatcher to process * the associated request, and create (or append to) the associated * response./* ww w . j ava2 s. c o m*/ * <p> * <strong>IMPLEMENTATION NOTE</strong>: This implementation assumes * that no filters are applied to a forwarded or included resource, * because they were already done for the original request. * * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ private void invoke(ServletRequest request, ServletResponse response) throws IOException, ServletException { // Checking to see if the context classloader is the current context // classloader. If it's not, we're saving it, and setting the context // classloader to the Context classloader ClassLoader oldCCL = Thread.currentThread().getContextClassLoader(); ClassLoader contextClassLoader = context.getLoader().getClassLoader(); if (oldCCL != contextClassLoader) { Thread.currentThread().setContextClassLoader(contextClassLoader); } else { oldCCL = null; } // Initialize local variables we may need HttpServletRequest hrequest = null; if (request instanceof HttpServletRequest) hrequest = (HttpServletRequest) request; HttpServletResponse hresponse = null; if (response instanceof HttpServletResponse) hresponse = (HttpServletResponse) response; Servlet servlet = null; IOException ioException = null; ServletException servletException = null; RuntimeException runtimeException = null; boolean unavailable = false; // Check for the servlet being marked unavailable if (wrapper.isUnavailable()) { log(sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); if (hresponse == null) { ; // NOTE - Not much we can do generically } else { long available = wrapper.getAvailable(); if ((available > 0L) && (available < Long.MAX_VALUE)) hresponse.setDateHeader("Retry-After", available); hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, sm.getString("applicationDispatcher.isUnavailable", wrapper.getName())); } unavailable = true; } // Allocate a servlet instance to process this request try { if (!unavailable) { // if (debug >= 2) // log(" Allocating servlet instance"); servlet = wrapper.allocate(); // if ((debug >= 2) && (servlet == null)) // log(" No servlet instance returned!"); } } catch (ServletException e) { log(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), e); servletException = e; servlet = null; } catch (Throwable e) { log(sm.getString("applicationDispatcher.allocateException", wrapper.getName()), e); servletException = new ServletException( sm.getString("applicationDispatcher.allocateException", wrapper.getName()), e); servlet = null; } // Get the FilterChain Here ApplicationFilterFactory factory = ApplicationFilterFactory.getInstance(); ApplicationFilterChain filterChain = factory.createFilterChain(request, wrapper, servlet); // Call the service() method for the allocated servlet instance try { String jspFile = wrapper.getJspFile(); if (jspFile != null) request.setAttribute(Globals.JSP_FILE_ATTR, jspFile); else request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT, servlet, request, response); // for includes/forwards if ((servlet != null) && (filterChain != null)) { filterChain.doFilter(request, response); } // Servlet Service Method is called by the FilterChain request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); } catch (ClientAbortException e) { request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); ioException = e; } catch (IOException e) { request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); log(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), e); ioException = e; } catch (UnavailableException e) { request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); log(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), e); servletException = e; wrapper.unavailable(e); } catch (ServletException e) { request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); Throwable rootCause = e; Throwable rootCauseCheck = null; // Extra aggressive rootCause finding do { try { rootCauseCheck = (Throwable) PropertyUtils.getProperty(rootCause, "rootCause"); if (rootCauseCheck != null) rootCause = rootCauseCheck; } catch (ClassCastException ex) { rootCauseCheck = null; } catch (IllegalAccessException ex) { rootCauseCheck = null; } catch (NoSuchMethodException ex) { rootCauseCheck = null; } catch (java.lang.reflect.InvocationTargetException ex) { rootCauseCheck = null; } } while (rootCauseCheck != null); log(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), rootCause); servletException = e; } catch (RuntimeException e) { request.removeAttribute(Globals.JSP_FILE_ATTR); support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT, servlet, request, response); log(sm.getString("applicationDispatcher.serviceException", wrapper.getName()), e); runtimeException = e; } // Release the filter chain (if any) for this request try { if (filterChain != null) filterChain.release(); } catch (Throwable e) { log.error(sm.getString("standardWrapper.releaseFilters", wrapper.getName()), e); //FIXME Exception handling needs to be simpiler to what is in the StandardWrapperValue } // Deallocate the allocated servlet instance try { if (servlet != null) { wrapper.deallocate(servlet); } } catch (ServletException e) { log(sm.getString("applicationDispatcher.deallocateException", wrapper.getName()), e); servletException = e; } catch (Throwable e) { log(sm.getString("applicationDispatcher.deallocateException", wrapper.getName()), e); servletException = new ServletException( sm.getString("applicationDispatcher.deallocateException", wrapper.getName()), e); } // Reset the old context class loader if (oldCCL != null) Thread.currentThread().setContextClassLoader(oldCCL); // Rethrow an exception if one was thrown by the invoked servlet if (ioException != null) throw ioException; if (servletException != null) throw servletException; if (runtimeException != null) throw runtimeException; }
From source file:org.apache.struts.tiles.DefinitionsUtil.java
/** * Remove Definition stored in jsp context. * Mainly used by Struts to pass a definition defined in an Action to the forward. *///from w w w . j a va 2 s . c om public static void removeActionDefinition(ServletRequest request, ComponentDefinition definition) { request.removeAttribute(ACTION_DEFINITION); }
From source file:org.apache.tapestry.jsp.URLRetriever.java
/** * Invokes the servlet to retrieve the URL. The URL is inserted * into the output (as with/*from w ww .java2 s.com*/ * {@link RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}). * * **/ public void insertURL(String servletPath) throws JspException { if (LOG.isDebugEnabled()) LOG.debug("Obtaining Tapestry URL for service " + _serviceName + " at " + servletPath); ServletRequest request = _pageContext.getRequest(); RequestDispatcher dispatcher = request.getRequestDispatcher(servletPath); if (dispatcher == null) throw new JspException(Tapestry.format("URLRetriever.unable-to-find-dispatcher", servletPath)); request.setAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE, _serviceName); request.setAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE, _serviceParameters); request.setAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE, servletPath); try { _pageContext.getOut().flush(); dispatcher.include(request, _pageContext.getResponse()); } catch (IOException ex) { throw new JspException(Tapestry.format("URLRetriever.io-exception", servletPath, ex.getMessage())); } catch (ServletException ex) { throw new JspException(Tapestry.format("URLRetriever.servlet-exception", servletPath, ex.getMessage())); } finally { request.removeAttribute(Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE); request.removeAttribute(Tapestry.TAG_SUPPORT_SERVLET_PATH_ATTRIBUTE); } }
From source file:org.echocat.jemoni.jmx.support.ServletHealth.java
@Override public void doFilter(@Nonnull ServletRequest request, @Nonnull ServletResponse response, @Nonnull FilterChain chain) throws IOException, ServletException { final StopWatch stopWatch = new StopWatch(); request.setAttribute(CURRENT_REQUEST_STOP_WATCH_ATTRIBUTE_NAME, stopWatch); final ScopeMapping globalMapping = _patternToMapping.get(null); final ScopeMapping specificMapping = request instanceof HttpServletRequest ? getMappingFor(((HttpServletRequest) request).getRequestURI()) : null;//from ww w . j a v a2 s. c o m try { chain.doFilter(request, response); } finally { request.removeAttribute(CURRENT_REQUEST_STOP_WATCH_ATTRIBUTE_NAME); final Duration duration = stopWatch.getCurrentDuration(); final ServletHealthInterceptor interceptor = _interceptor; if (interceptor == null || interceptor.isRecordAllowed(request, globalMapping, specificMapping)) { globalMapping.record(null, duration); if (specificMapping != null) { final String targetName = interceptor != null ? interceptor.getSpecificTargetName(request, specificMapping) : null; specificMapping.record(targetName, duration); } } } }
From source file:org.glimpse.server.ConnectionFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean userOk = false; String connectionId = GlimpseUtils.getConnectionId((HttpServletRequest) request); if (StringUtils.isNotEmpty(connectionId)) { if (logger.isDebugEnabled()) { logger.debug("Connection id found : <" + connectionId + ">"); }/* w w w.j a v a 2s . com*/ UserManager userManager = WebApplicationContextUtils.getWebApplicationContext(servletContext) .getBean(UserManager.class); String userId = userManager.getUserId(connectionId); if (StringUtils.isNotBlank(userId)) { if (logger.isDebugEnabled()) { logger.debug("User id is : <" + userId + ">"); } request.setAttribute(GlimpseUtils.REQUEST_ATTRIBUTE_USER_ID, userId); UserAttributes userAttributes = userManager.getUserAttributes(userId); request.setAttribute(GlimpseUtils.REQUEST_ATTRIBUTE_USER_ATTRIBUTES, userAttributes); userOk = true; } } if (!userOk) { logger.debug("No valid connection id found"); request.removeAttribute(GlimpseUtils.REQUEST_ATTRIBUTE_USER_ID); request.removeAttribute(GlimpseUtils.REQUEST_ATTRIBUTE_USER_ATTRIBUTES); } chain.doFilter(request, response); }
From source file:org.jasig.ssp.security.uportal.KeepSessionAliveFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { boolean overrideInterval = isIntervalOverridden(request); if (!(overrideInterval) && interval < 0) { chain.doFilter(request, response); return;/* w ww .j a v a 2s . co m*/ } final HttpServletRequest httpServletRequest = (HttpServletRequest) request; final HttpServletResponse httpServletResponse = (HttpServletResponse) response; final HttpSession session = httpServletRequest.getSession(false); if (session == null) { chain.doFilter(request, response); return; } Long lastUpdate = (Long) session.getAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY); if (overrideInterval || lastUpdate != null) { if (overrideInterval || ((System.currentTimeMillis() - lastUpdate.longValue()) >= interval)) { final CrossContextRestApiInvoker rest = new SimpleCrossContextRestApiInvoker(); //ensures request is GET going into REST Invoker HttpServletGetRequestWrapper wrap = new HttpServletGetRequestWrapper(httpServletRequest); final Object origWebAsyncManager = wrap.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE); request.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE); try { final Map<String, String[]> params = new HashMap<String, String[]>(); final RestResponse rr = rest.invoke(wrap, httpServletResponse, "/ssp-platform/api/session.json", params); session.setAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY, System.currentTimeMillis()); } finally { request.setAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, origWebAsyncManager); } } } else { session.setAttribute(SESSION_KEEP_ALIVE_ATTRIBUTE_KEY, System.currentTimeMillis()); } chain.doFilter(request, response); }
From source file:org.jsecurity.web.session.DefaultWebSessionManager.java
protected Serializable start(ServletRequest request, ServletResponse response, InetAddress inetAddress) { Serializable sessionId = super.start(inetAddress); storeSessionId(sessionId, request, response); request.removeAttribute(JSecurityHttpServletRequest.REFERENCED_SESSION_ID_SOURCE); request.setAttribute(JSecurityHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE); return sessionId; }
From source file:org.opencms.jsp.CmsJspTagEditable.java
/** * Returns the current initialized instance of the direct edit provider parameters from the given page context.<p> * /*from w w w .j a v a2 s . com*/ * Also removes the parameters from the given page context.<p> * * @param context the current JSP page context * * @return the current initialized instance of the direct edit provider parameters */ protected static CmsDirectEditParams getDirectEditProviderParams(PageContext context) { // get the current request ServletRequest req = context.getRequest(); // get the direct edit params from the request attributes CmsDirectEditParams result = (CmsDirectEditParams) req .getAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS); if (result != null) { req.removeAttribute(I_CmsDirectEditProvider.ATTRIBUTE_DIRECT_EDIT_PROVIDER_PARAMS); } return result; }