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


Java ServletResponse.isCommitted方法代码示例

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


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

示例1: onTimeout

import javax.servlet.ServletResponse; //导入方法依赖的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.ServletResponse; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    String requestURI = getRequestURI(request);

    FacesContext fc = getFacesContext(request, response);
    NavigationHandlerBean navigationHandler = (NavigationHandlerBean) fc.getApplication().getELResolver().getValue(fc.getELContext(), null, "navigationHandler");

    if (getDemoType(requestURI).equals(TYPES.component)){
        IComponentVariantDemo componentVariantDemo = getComponentVariantDemo(requestURI);
        navigationHandler.setCurrentComponentVariantDemo(componentVariantDemo);

        _LOG.log(Level.INFO,"Forwarding request [" + requestURI + "] to view [" + componentVariantDemo.getEntryPagePath()+"]");
        if (!response.isCommitted()) {
            request.getRequestDispatcher("/faces"+componentVariantDemo.getEntryPagePath()).forward(request, response);
        }
    }

    if (getDemoType(requestURI).equals(TYPES.feature)){
        IFeatureDemo featureDemo = getFeatureDemo(requestURI);
        navigationHandler.setCurrentFeatureDemo(featureDemo);

        _LOG.log(Level.INFO,"Forwarding request [" + requestURI + "] to view [" + featureDemo.getPagePath()+"]");
        if (!response.isCommitted()) {
            request.getRequestDispatcher("/faces"+featureDemo.getPagePath()).forward(request, response);
        }
    }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:27,代码来源:PrettyUrlFilter.java

示例3: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
		final FilterChain chain) throws IOException, ServletException {
	if (request instanceof HttpServletRequest) {
		final HttpServletRequest req = ((HttpServletRequest) request);
		final HttpServletResponse res = ((HttpServletResponse) response);
		final String header = req.getHeader(SimpleAuth.HTTP_HEADER);
		if (header != null) {
			final String[] sp = header.split(" ");
			// Authentication: torch TOKEN
			if (sp.length == 2) {
				final String scheme = sp[0], param = sp[1];
				if (SimpleAuth.SCHEME.equals(scheme)) {
					if (sa.verify(param)) {
						chain.doFilter(request, response);
						return;
					}
				}
			}
		}
		if (!res.isCommitted()) {
			final String err = "FORBIDDEN\r\n";
			res.reset();
			res.setStatus(HttpServletResponse.SC_FORBIDDEN);
			res.setContentLength(err.length());
			res.setContentType("text/plain");
			res.setCharacterEncoding("ISO-8859-1");
			res.setHeader("Pragma", "no-cache");
			res.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate");
			res.setHeader(getClass().getSimpleName(), "deny");
			res.getWriter().print(err);
			return;
		}
	}
	if (!response.isCommitted()) {
		response.reset();
	}
	throw new ServletException(new UnsupportedOperationException());
}
 
开发者ID:ggrandes,项目名称:simpleauth,代码行数:40,代码来源:SimpleAuthFilter.java

示例4: forward

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
public void forward(ServletRequest request, ServletResponse response)
{
    if (response.isCommitted())
    {
        throw new IllegalStateException("Cannot perform forward - response is already committed");
    }

    if (!(response instanceof FakeHttpServletResponse))
    {
        throw new IllegalArgumentException("FakeRequestDispatcher requires FakeHttpServletResponse");
    }

    ((FakeHttpServletResponse) response).setForwardedUrl(this.url);

    if (log.isDebugEnabled())
    {
        log.debug("FakeRequestDispatcher: forwarding to URL [" + this.url + "]");
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:20,代码来源:FakeRequestDispatcher.java

示例5: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {
	if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;

		if (response.isCommitted()) {
			if (log.isDebugEnabled()) {
				log.debug(sm.getString("expiresFilter.responseAlreadyCommited", httpRequest.getRequestURL()));
			}
			chain.doFilter(request, response);
		} else {
			XHttpServletResponse xResponse = new XHttpServletResponse(httpRequest, httpResponse);
			chain.doFilter(request, xResponse);
			if (!xResponse.isWriteResponseBodyStarted()) {
				// Empty response, manually trigger
				// onBeforeWriteResponseBody()
				onBeforeWriteResponseBody(httpRequest, xResponse);
			}
		}
	} else {
		chain.doFilter(request, response);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:26,代码来源:ExpiresFilter.java

示例6: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    if (request instanceof HttpServletRequest &&
            response instanceof HttpServletResponse) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        if (response.isCommitted()) {
            if (log.isDebugEnabled()) {
                log.debug(sm.getString(
                        "expiresFilter.responseAlreadyCommited",
                        httpRequest.getRequestURL()));
            }
            chain.doFilter(request, response);
        } else {
            XHttpServletResponse xResponse = new XHttpServletResponse(
                    httpRequest, httpResponse);
            chain.doFilter(request, xResponse);
            if (!xResponse.isWriteResponseBodyStarted()) {
                // Empty response, manually trigger
                // onBeforeWriteResponseBody()
                onBeforeWriteResponseBody(httpRequest, xResponse);
            }
        }
    } else {
        chain.doFilter(request, response);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:30,代码来源:ExpiresFilter.java

示例7: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {

    if (response instanceof HttpServletResponse) {
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        if (response.isCommitted()) {
            throw new ServletException(sm.getString("httpHeaderSecurityFilter.committed"));
        }

        // HSTS
        if (hstsEnabled && request.isSecure()) {
            httpResponse.setHeader(HSTS_HEADER_NAME, hstsHeaderValue);
        }

        // anti click-jacking
        if (antiClickJackingEnabled) {
            httpResponse.setHeader(ANTI_CLICK_JACKING_HEADER_NAME, antiClickJackingHeaderValue);
        }

        // Block content type sniffing
        if (blockContentTypeSniffingEnabled) {
            httpResponse.setHeader(BLOCK_CONTENT_TYPE_SNIFFING_HEADER_NAME,
                    BLOCK_CONTENT_TYPE_SNIFFING_HEADER_VALUE);
        }

        // cross-site scripting filter protection
        if (xssProtectionEnabled) {
            httpResponse.setHeader(XSS_PROTECTION_HEADER_NAME, XSS_PROTECTION_HEADER_VALUE);
        }
    }

    chain.doFilter(request, response);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:HttpHeaderSecurityFilter.java

示例8: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * Rewrites the outgoing stream to make sure URLs and headers
 * are correct. The incoming request is first processed to 
 * identify what resource we want to proxy.
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain filterChain) throws IOException, ServletException {
    
    if (response.isCommitted()) {
        log.info("Not proxying, already committed.");
        return;
    } else if (!(request instanceof HttpServletRequest)) {
        log.info("Request is not HttpRequest, will only handle HttpRequests.");
        return;
    } else if (!(response instanceof HttpServletResponse)) {
        log.info("Request is not HttpResponse, will only handle HttpResponses.");
        return;
    } else {
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        
        Server server = serverChain.evaluate(httpRequest);
        if (server == null) {
            log.info("Could not find a rule for this request, will not do anything.");
            filterChain.doFilter(request, response);
        } else {
            httpRequest.setAttribute("proxyServer", server);
            
            String ownHostName = request.getServerName() + ":" + request.getServerPort();
            UrlRewritingResponseWrapper wrappedResponse;
            wrappedResponse = new UrlRewritingResponseWrapper(httpResponse, server, ownHostName, httpRequest.getContextPath(), serverChain);
            
            filterChain.doFilter(httpRequest, wrappedResponse);

            wrappedResponse.processStream();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:41,代码来源:RewriteFilter.java

示例9: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  try {
    chain.doFilter(request, response);
  } catch (Exception e) {
    LOGGER.log(Level.WARNING, "Servlet threw exception", e);
    if (!response.isCommitted() && response instanceof HttpServletResponse) {
      ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      response.getWriter().write("{\"exception\": true}");
    }
  }
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:12,代码来源:ExceptionFilter.java

示例10: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {

	if (response instanceof HttpServletResponse) {
		HttpServletResponse httpResponse = (HttpServletResponse) response;

		if (response.isCommitted()) {
			throw new ServletException(sm.getString("httpHeaderSecurityFilter.committed"));
		}

		// HSTS
		if (hstsEnabled && request.isSecure()) {
			httpResponse.setHeader(HSTS_HEADER_NAME, hstsHeaderValue);
		}

		// anti click-jacking
		if (antiClickJackingEnabled) {
			httpResponse.setHeader(ANTI_CLICK_JACKING_HEADER_NAME, antiClickJackingHeaderValue);
		}

		// Block content type sniffing
		if (blockContentTypeSniffingEnabled) {
			httpResponse.setHeader(BLOCK_CONTENT_TYPE_SNIFFING_HEADER_NAME,
					BLOCK_CONTENT_TYPE_SNIFFING_HEADER_VALUE);
		}

		// cross-site scripting filter protection
		if (xssProtectionEnabled) {
			httpResponse.setHeader(XSS_PROTECTION_HEADER_NAME, XSS_PROTECTION_HEADER_VALUE);
		}
	}

	chain.doFilter(request, response);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:36,代码来源:HttpHeaderSecurityFilter.java

示例11: doFilter

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
		final FilterChain chain) throws IOException, ServletException {
	if (request instanceof HttpServletRequest) {
		final HttpServletRequest req = (HttpServletRequest) request;
		final String uriReq = req.getRequestURI();
		final String ip = req.getRemoteAddr();
		final Entry<String, Limit> e = limits.floorEntry(uriReq);
		final boolean found = ((e != null) && uriReq.startsWith(e.getKey()));
		final Limit limit = (e != null ? e.getValue() : null);
		boolean recent = false, lock = false;
		try {
			if (!found || (!(recent = limit.seenRecent(ip)) && (lock = limit.tryAcquire()))) {
				chain.doFilter(request, response);
				try {
					Thread.sleep(10);
				} catch (InterruptedException ex) {
					Thread.currentThread().interrupt();
				}
			} else {
				final StringBuilder sb = new StringBuilder();
				sb.append(getClass().getSimpleName());
				sb.append(" cfg=").append(e.getKey());
				sb.append(" uriReq=").append(uriReq);
				if (recent) {
					sb.append(" Lock-by-IP=").append(ip) //
							.append(" time=").append(limit.timeByIP).append("ms");
				} else if (!lock) {
					sb.append(" Lock-by-Concurrent=").append(limit.concurrentMax);
				}
				ctx.log(sb.toString());
				if (!response.isCommitted()) {
					handleError(req, (HttpServletResponse) response);
				}
			}
		} finally {
			if ((limit != null) && lock) {
				limit.release();
			}
		}
	} else {
		chain.doFilter(request, response);
	}
}
 
开发者ID:ggrandes,项目名称:concurrentlimit-servlet-filter,代码行数:45,代码来源:ConcurrentLimitFilter.java

示例12: invoke

import javax.servlet.ServletResponse; //导入方法依赖的package包/类
/**
 * Invoke the next Valve in the sequence. When the invoke returns, check 
 * the response state, and output an error report is necessary.
 *
 * @param request The servlet request to be processed
 * @param response The servlet response to be created
 * @param context The valve context used to invoke the next valve
 *  in the current processing pipeline
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void invoke(Request request, Response response,
                   ValveContext context)
    throws IOException, ServletException {

    // Perform the request
    context.invokeNext(request, response);

    ServletRequest sreq = (ServletRequest) request;
    Throwable throwable = 
        (Throwable) sreq.getAttribute(Globals.EXCEPTION_ATTR);

    ServletResponse sresp = (ServletResponse) response;
    if (sresp.isCommitted()) {
        return;
    }

    if (throwable != null) {

        // The response is an error
        response.setError();

        // Reset the response (if possible)
        try {
            sresp.reset();
        } catch (IllegalStateException e) {
            ;
        }

        ServletResponse sresponse = (ServletResponse) response;
        if (sresponse instanceof HttpServletResponse)
            ((HttpServletResponse) sresponse).sendError
                (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    }

    response.setSuspended(false);

    try {
        report(request, response, throwable);
    } catch (Throwable tt) {
        tt.printStackTrace();
    }

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:57,代码来源:ErrorReportValve.java


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