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


Java HttpServletResponse.isCommitted方法代码示例

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


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

示例1: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
		AccessDeniedException accessDeniedException) throws IOException, ServletException {
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	
	String userName = (auth == null) ? "anonymous" : auth.getName();
	LOGGER.warn("User: {} attempted unauthorized access to URL: {} . message: {}", userName,
			request.getRequestURL() + accessDeniedException.getMessage());
	
	if (!response.isCommitted()) {
		if (errorPage != null) {
			// Set the 403 status code.
			response.setStatus(HttpServletResponse.SC_FORBIDDEN);

			// forward to error page.
			RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage);
			dispatcher.forward(request, response);
		}
		else {
			response.sendError(HttpServletResponse.SC_FORBIDDEN,
					accessDeniedException.getMessage());
		}
	}
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:25,代码来源:AccessDeniedHandlerCustomImpl.java

示例2: handleThingsboardException

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public void handleThingsboardException(Exception exception, HttpServletResponse response) {
    log.debug("Processing exception {}", exception.getMessage(), exception);
    if (!response.isCommitted()) {
        try {
            response.setContentType(MediaType.APPLICATION_JSON_VALUE);
            if (exception instanceof SecurityException) {
                response.setStatus(HttpStatus.FORBIDDEN.value());
                mapper.writeValue(response.getWriter(),
                        new HttpRequestProcessingError("You don't have permission to perform this operation!"));
            } else {
                response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                mapper.writeValue(response.getWriter(), new HttpRequestProcessingError(exception.getMessage()));
            }
        } catch (IOException e) {
            log.error("Can't handle exception", e);
        }
    }
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:20,代码来源:HttpController.java

示例3: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void handle(HttpServletRequest request,
				   HttpServletResponse response,
				   AccessDeniedException accessDeniedException) throws IOException, ServletException {
	logger.error(accessDeniedException, accessDeniedException);
	if (!response.isCommitted()) {
		String accept = request.getHeader("Accept");
		if (accept != null && accept.contains("application/json")) {
			logger.warn("The ajax request access is denied.");
			response.setStatus(HttpServletResponse.SC_FORBIDDEN);
			response.flushBuffer();
		}
		else {
			super.handle(request, response, accessDeniedException);
		}
	}
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:18,代码来源:AccessDeniedHandlerMvcImpl.java

示例4: updateResponse

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private void updateResponse(String requestURI, ContentCachingResponseWrapper responseWrapper) throws IOException {
	try {
		HttpServletResponse rawResponse = (HttpServletResponse) responseWrapper.getResponse();
		byte[] body = responseWrapper.getContentAsByteArray();
		ServletOutputStream outputStream = rawResponse.getOutputStream();
		if (rawResponse.isCommitted()) {
			if (body.length > 0) {
				StreamUtils.copy(body, outputStream);
			}
		} else {
			if (body.length > 0) {
				rawResponse.setContentLength(body.length);
				StreamUtils.copy(body, rawResponse.getOutputStream());
			}
		}
		finishResponse(outputStream, body);
	} catch (Exception ex) {
		logger.error("请求地址为" + requestURI + "的连接返回报文失败,原因是{}", ex.getMessage());
	}
}
 
开发者ID:wengwh,项目名称:plumdo-stock,代码行数:21,代码来源:RequestLogFilter.java

示例5: authenticate

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * @throws IOException If an I/O error occurs
 * @throws IllegalStateException If the response has been committed
 * @throws ServletException If the caller is responsible for handling the
 *         error and the container has NOT set the HTTP response code etc.
 */
@Override
public boolean authenticate(HttpServletResponse response)
throws IOException, ServletException {
    if (response.isCommitted()) {
        throw new IllegalStateException(
                sm.getString("coyoteRequest.authenticate.ise"));
    }

    return context.getAuthenticator().authenticate(this, response);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:Request.java

示例6: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void handle(Exception exception, HttpServletResponse response) {
  log.debug("Processing exception {}", exception.getMessage(), exception);
  if (!response.isCommitted()) {
    try {
      response.setContentType(MediaType.APPLICATION_JSON_VALUE);

      if (exception instanceof IoTPException) {
        handleThingsboardException((IoTPException) exception, response);
      } else if (exception instanceof AccessDeniedException) {
        handleAccessDeniedException(response);
      } else if (exception instanceof AuthenticationException) {
        handleAuthenticationException((AuthenticationException) exception, response);
      } else {
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        mapper.writeValue(response.getWriter(), IoTPErrorResponse.of(exception.getMessage(),
            IoTPErrorCode.GENERAL, HttpStatus.INTERNAL_SERVER_ERROR));
      }
    } catch (IOException e) {
      log.error("Can't handle exception", e);
    }
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:23,代码来源:IoTPErrorResponseHandler.java

示例7: doForward

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Do a forward using request dispatcher.
 * Uri is a valid uri. If response has already been commited, do an include
 * instead.
 * @param uri Uri or Definition name to forward.
 * @param request Current page request.
 * @param response Current page response.
 */
protected void doForward(
	String uri,
	HttpServletRequest request,
	HttpServletResponse response)
	throws IOException, ServletException {
           
	if (response.isCommitted()) {
		this.doInclude(uri, request, response);
           
	} else {
		super.doForward(uri, request, response);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:TilesRequestProcessor.java

示例8: sendErrorResponse

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
void sendErrorResponse(HttpServletResponse resp, ApiException e) throws IOException {
	if (!resp.isCommitted()) {
		resp.setContentType("application/json");
		resp.sendError(400, "json");
		PrintWriter pw = resp.getWriter();
		pw.print("{\"error\":");
		pw.print(objectMapper.writeValueAsString(e.error));
		pw.print("{\"error\":");
		pw.print(objectMapper.writeValueAsString(e.data));
		pw.print("{\"message\":");
		pw.print(objectMapper.writeValueAsString(e.getMessage()));
		pw.print("}");
		pw.flush();
	}
}
 
开发者ID:michaelliao,项目名称:cryptoexchange,代码行数:16,代码来源:RestFilter.java

示例9: onProxyResponseFailure

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
protected void onProxyResponseFailure(final HttpServletRequest clientRequest, final HttpServletResponse proxyResponse,
		final Response serverResponse, final Throwable failure) {
	_log.warn(failure.toString());

	if (proxyResponse.isCommitted()) {
		// Parent behavior
		super.onProxyResponseFailure(clientRequest, proxyResponse, serverResponse, failure);
	} else {
		proxyResponse.resetBuffer();
		if (failure instanceof TimeoutException) {
			proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
		} else {

			// Unavailable business server as JSON response
			proxyResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
			proxyResponse.setContentType("application/json");
			try {
				proxyResponse.getOutputStream().write("{\"code\":\"business-down\"}".getBytes(StandardCharsets.UTF_8));
			} catch (final IOException ioe) {
				_log.warn("Broken proxy stream", ioe);
			}
		}
		proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
		final AsyncContext asyncContext = clientRequest.getAsyncContext();
		asyncContext.complete();
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:29,代码来源:BackendProxyServlet.java

示例10: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException {
	

    String targetUrl = targetUrl(authentication);
    if (response.isCommitted()) {
        System.out.println("Can't redirect");
        return;
    }
    redirectStrategy.sendRedirect(request, response, targetUrl);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:13,代码来源:CustomSuccessHandler.java

示例11: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private void handle(HttpServletRequest request, HttpServletResponse response,
                    Authentication authentication) throws IOException {

    String targetURL = determineTargetURL(authentication);
    if (response.isCommitted()) {
        logger.debug("Response has already been committed. Unable to redirect to " + targetURL);
        return;
    }

    redirectStrategy.sendRedirect(request, response, targetURL);
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:12,代码来源:ProfChoperAuthSuccessHandler.java

示例12: doFilter

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public boolean doFilter(HttpServletRequest request, HttpServletResponse httpResponse,
        FilterChain chain) throws IOException, ServletException {
    if (disabled) {
        // skip the execution if disabled
        return true;
    }
    if (httpResponse.isCommitted()) {
        throw new ServletException("Response already committed");
    }

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

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

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

    // cross-site scripting filter protection
    if (config.isXssProtectionEnabled()) {
        httpResponse.setHeader(XSS_PROTECTION_HEADER_NAME, XSS_PROTECTION_HEADER_VALUE);
    }
    return true; // invoke chain
}
 
开发者ID:goodees,项目名称:goodees,代码行数:34,代码来源:SecurityHeadersFilter.java

示例13: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
	if (response.isCommitted()) {
		return;
	}

	redirectStrategy.sendRedirect(request, response, "/home");
}
 
开发者ID:edylle,项目名称:hockey-game,代码行数:8,代码来源:CustomAuthenticationSuccessHandler.java

示例14: doFilter

import javax.servlet.http.HttpServletResponse; //导入方法依赖的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

示例15: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * @see com.tle.web.sections.errors.SectionsExceptionHandler#handle(java.lang.Throwable,
 *      com.tle.web.sections.SectionInfo,
 *      com.tle.web.sections.SectionsController,
 *      com.tle.web.sections.events.SectionEvent)
 */
@SuppressWarnings("nls")
@Override
public void handle(Throwable exception, SectionInfo info, SectionsController controller, SectionEvent<?> event)
{
	LOGGER.error("Error during selection session request", exception);
	super.handle(exception, info, controller, null);
	HttpServletResponse response = info.getResponse();
	if( !response.isCommitted() )
	{
		response.reset();
		response.setStatus(500);
		response.setHeader("Content-Type", "text/html");
		try
		{
			String errMsg = "An error occurred on the server when invoking the request: " + exception.getMessage();
			response.getWriter().print(errMsg);
			// Some sort of formatted error message ...?
			// response.getWriter().append("An error : " +
			// exception.getMessage());
			// Some sort of redirect ...?
			// response.sendRedirect(....);
			// Sufficient for Moodle19, but Moodle22 & 23 don't present the
			// server error page ...?
			// response.sendError(500, exception.getMessage());
			// An issue remains with getting an error message to be
			// presented to the iframe for the moodle file-picker session.
			// Flushing and closing doesn't seem to make any difference ...
			response.getWriter().flush();
			response.getWriter().close();
		}
		catch( IOException e )
		{
			throw new SectionsRuntimeException(e);
		}
	}
	info.setRendered();
}
 
开发者ID:equella,项目名称:Equella,代码行数:44,代码来源:RootSelectionExceptionHandler.java


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