當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。