Java Code Examples for javax.servlet.http.HttpServletResponse#SC_SERVICE_UNAVAILABLE

The following examples show how to use javax.servlet.http.HttpServletResponse#SC_SERVICE_UNAVAILABLE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Response fromSocketException(SocketException e) {
    int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;

    Throwable cause = e.getCause() == null ? e : e.getCause();
    String errorMessage = toStandardHttpErrorMessage(status, cause);

    ErrorResponse errorResponse = ErrorResponse.newError(status, errorMessage)
            .clientRequest(httpServletRequest)
            .serverContext()
            .exceptionContext(cause)
            .build();
    return Response.status(status).entity(errorResponse).build();
}
 
Example 2
Source Project: pulsar   File: ProducerHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static int getErrorCode(Exception e) {
    if (e instanceof IllegalArgumentException) {
        return HttpServletResponse.SC_BAD_REQUEST;
    } else if (e instanceof ProducerBusyException) {
        return HttpServletResponse.SC_CONFLICT;
    } else if (e instanceof ProducerBlockedQuotaExceededError || e instanceof ProducerBlockedQuotaExceededException) {
        return HttpServletResponse.SC_SERVICE_UNAVAILABLE;
    } else {
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
}
 
Example 3
protected void outputError(RequestContext reqCtx, HttpServletResponse response) throws ServletException {
	try {
		if (!response.isCommitted()) {
			Integer httpErrorCode = (Integer) reqCtx.getExtraParam("errorCode");
			if (httpErrorCode == null) {
				httpErrorCode = new Integer(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
			}
			response.sendError(httpErrorCode.intValue());
		}
	} catch (IOException e) {
		_logger.error("outputError", e);
		throw new ServletException("Service not available");
	}
}
 
Example 4
Source Project: knox   File: GatewayServlet.java    License: Apache License 2.0 5 votes vote down vote up
private void auditLog(ServletRequest servletRequest, ServletResponse servletResponse) {
  final int status = ((HttpServletResponse) servletResponse).getStatus();
  final String requestUri, actionOutcome;
  if (HttpServletResponse.SC_SERVICE_UNAVAILABLE == status) {
    requestUri = ServletRequestUtils.getContextPathWithQuery(servletRequest);
    actionOutcome = ActionOutcome.UNAVAILABLE;
  } else {
    requestUri = (String) servletRequest.getAttribute(AbstractGatewayFilter.SOURCE_REQUEST_CONTEXT_URL_ATTRIBUTE_NAME);
    actionOutcome = ActionOutcome.SUCCESS;
  }
  auditor.audit(Action.ACCESS, requestUri, ResourceType.URI, actionOutcome, res.responseStatus(status));
}
 
Example 5
private static RestException fromStatusRuntimeException(StatusRuntimeException e) {
    int statusCode;
    switch (e.getStatus().getCode()) {
        case OK:
            statusCode = HttpServletResponse.SC_OK;
            break;
        case INVALID_ARGUMENT:
            statusCode = HttpServletResponse.SC_BAD_REQUEST;
            break;
        case DEADLINE_EXCEEDED:
            statusCode = HttpServletResponse.SC_REQUEST_TIMEOUT;
            break;
        case NOT_FOUND:
            statusCode = HttpServletResponse.SC_NOT_FOUND;
            break;
        case ALREADY_EXISTS:
            statusCode = HttpServletResponse.SC_CONFLICT;
            break;
        case PERMISSION_DENIED:
            statusCode = HttpServletResponse.SC_FORBIDDEN;
            break;
        case RESOURCE_EXHAUSTED:
            statusCode = TOO_MANY_REQUESTS;
            break;
        case FAILED_PRECONDITION:
            statusCode = HttpServletResponse.SC_CONFLICT;
            break;
        case UNIMPLEMENTED:
            statusCode = HttpServletResponse.SC_NOT_IMPLEMENTED;
            break;
        case UNAVAILABLE:
            statusCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
            break;
        case UNAUTHENTICATED:
            statusCode = HttpServletResponse.SC_UNAUTHORIZED;
            break;
        default:
            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    return RestException.newBuilder(statusCode, e.getMessage())
            .withCause(e)
            .build();
}
 
Example 6
Source Project: nomulus   File: HttpException.java    License: Apache License 2.0 4 votes vote down vote up
public ServiceUnavailableException(String message) {
  super(HttpServletResponse.SC_SERVICE_UNAVAILABLE, message, null);
}