本文整理匯總了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());
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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());
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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
}
示例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");
}
示例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());
}
示例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();
}