当前位置: 首页>>代码示例>>Java>>正文


Java ServletRequest.removeAttribute方法代码示例

本文整理汇总了Java中javax.servlet.ServletRequest.removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.removeAttribute方法的具体用法?Java ServletRequest.removeAttribute怎么用?Java ServletRequest.removeAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletRequest的用法示例。


在下文中一共展示了ServletRequest.removeAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTimeout

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void onTimeout(AsyncEvent event) throws IOException {
  // in this time, maybe:
  // 1.invocation in executor's queue
  // 2.already executing in executor
  // 3.already send response
  // to avoid concurrent, must lock request
  ServletRequest request = event.getSuppliedRequest();
  HttpServletRequestEx requestEx = (HttpServletRequestEx) request.getAttribute(RestConst.REST_REQUEST);

  synchronized (requestEx) {
    ServletResponse response = event.getAsyncContext().getResponse();
    if (!response.isCommitted()) {
      LOGGER.error("Rest request timeout, method {}, path {}.", requestEx.getMethod(), requestEx.getRequestURI());
      // invocation in executor's queue
      response.setContentType(MediaType.APPLICATION_JSON);

      // we don't know if developers declared one statusCode in contract
      // so we use cse inner statusCode here
      ((HttpServletResponse) response).setStatus(ExceptionFactory.PRODUCER_INNER_STATUS_CODE);
      PrintWriter out = response.getWriter();
      out.write(TIMEOUT_MESSAGE);
      response.flushBuffer();
    }

    request.removeAttribute(RestConst.REST_REQUEST);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:29,代码来源:RestAsyncListener.java

示例2: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * This {@code doFilter} implementation stores a request attribute for
 * "already filtered", proceeding without filtering again if the attribute is already
 * there.
 * @param request the request
 * @param response the response
 * @param filterChain the filter chain
 * @throws ServletException if request is not HTTP request
 * @throws IOException in case of I/O operation exception
 */
public final void doFilter(ServletRequest request, ServletResponse response,
		FilterChain filterChain) throws ServletException, IOException {

	if (!(request instanceof HttpServletRequest)
			|| !(response instanceof HttpServletResponse)) {
		throw new ServletException(
				"OncePerRequestFilter just supports HTTP requests");
	}
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpServletResponse httpResponse = (HttpServletResponse) response;
	boolean hasAlreadyFilteredAttribute = request
			.getAttribute(this.alreadyFilteredAttributeName) != null;

	if (hasAlreadyFilteredAttribute) {

		// Proceed without invoking this filter...
		filterChain.doFilter(request, response);
	}
	else {
		// Do invoke this filter...
		request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
		try {
			doFilterInternal(httpRequest, httpResponse, filterChain);
		}
		finally {
			// Remove the "already filtered" request attribute for this request.
			request.removeAttribute(this.alreadyFilteredAttributeName);
		}
	}
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:41,代码来源:OncePerRequestFilter.java

示例3: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * This {@code doFilter} implementation stores a request attribute for
 * "already filtered", proceeding without filtering again if the
 * attribute is already there.
 * @see #getAlreadyFilteredAttributeName
 * @see #shouldNotFilter
 * @see #doFilterInternal
 */
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
		throw new ServletException("OncePerRequestFilter just supports HTTP requests");
	}
	HttpServletRequest httpRequest = (HttpServletRequest) request;
	HttpServletResponse httpResponse = (HttpServletResponse) response;

	String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
	boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;

	if (hasAlreadyFilteredAttribute || skipDispatch(httpRequest) || shouldNotFilter(httpRequest)) {

		// Proceed without invoking this filter...
		filterChain.doFilter(request, response);
	}
	else {
		// Do invoke this filter...
		request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
		try {
			doFilterInternal(httpRequest, httpResponse, filterChain);
		}
		finally {
			// Remove the "already filtered" request attribute for this request.
			request.removeAttribute(alreadyFilteredAttributeName);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:OncePerRequestFilter.java

示例4: doFilter

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * This {@code doFilter} implementation stores a request attribute for
 * "already filtered", proceeding without filtering again if the
 * attribute is already there.
 *
 * @see #getAlreadyFilteredAttributeName
 * @see #doFilterInternal
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {
    String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
    if (request.getAttribute(alreadyFilteredAttributeName) != null) {
        log.trace("Filter '{}' already executed.  Proceeding without invoking this filter.", getName());
        filterChain.doFilter(request, response);
    } else {
        if (!isEnabled(request, response)) {
            log.debug("Filter '{}' is not enabled for the current request.  Proceeding without invoking this filter.",
                    getName());
            filterChain.doFilter(request, response);
        } else {
            // Do invoke this filter...
            log.trace("Filter '{}' not yet executed.  Executing now.", getName());
            request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);

            try {
                // TODO Maybe do some checks before cast?
                doFilterInternal((HttpServletRequest) request, (HttpServletResponse) response, filterChain);
            } finally {
                // Once the request has finished, we're done and we don't
                // need to mark as 'already filtered' any more.
                request.removeAttribute(alreadyFilteredAttributeName);
            }
        }
    }
}
 
开发者ID:atbashEE,项目名称:atbash-octopus,代码行数:36,代码来源:OncePerRequestFilter.java

示例5: removeActionDefinition

import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
 * Remove Definition stored in jsp context.
 * Mainly used by Struts to pass a definition defined in an Action to the forward.
 */
public static void removeActionDefinition(
    ServletRequest request,
    ComponentDefinition definition) {

    request.removeAttribute(ACTION_DEFINITION);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:DefinitionsUtil.java


注:本文中的javax.servlet.ServletRequest.removeAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。