當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatus.value方法代碼示例

本文整理匯總了Java中org.springframework.http.HttpStatus.value方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.value方法的具體用法?Java HttpStatus.value怎麽用?Java HttpStatus.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processHttpServerError

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
@ExceptionHandler(HttpServerErrorException.class)
@ResponseBody
public ResponseEntity<ErrorVM> processHttpServerError(HttpServerErrorException ex) {
    BodyBuilder builder;
    ErrorVM fieldErrorVM;
    HttpStatus responseStatus = ex.getStatusCode();
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        fieldErrorVM = new ErrorVM(ERROR_PREFIX + responseStatus.value(), translate(ERROR_PREFIX
                                                                                        + responseStatus.value()));
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        fieldErrorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR,
                                   translate(ErrorConstants.ERR_INTERNAL_SERVER_ERROR));
    }
    return builder.body(fieldErrorVM);
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:18,代碼來源:ExceptionTranslator.java

示例2: handleMessageException

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
/**
 * Handles MessageException exception.
 *
 * @param exception the MessageException instance
 * @param request   the WebRequest caused exception
 * @return the ResponseEntity object instance
 */
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
    HttpStatus status;

    switch (exception.getErrorType()) {
        case NOT_FOUND:
            status = HttpStatus.NOT_FOUND;
            break;
        case DATA_INVALID:
        case PARAMETERS_INVALID:
            status = HttpStatus.BAD_REQUEST;
            break;
        case ALREADY_EXISTS:
            status = HttpStatus.CONFLICT;
            break;
        case AUTH_FAILED:
            status = HttpStatus.UNAUTHORIZED;
            break;
        case OPERATION_TIMED_OUT:
        case INTERNAL_ERROR:
        default:
            status = HttpStatus.INTERNAL_SERVER_ERROR;
            break;
    }

    MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(),
            status.value(), status.getReasonPhrase(),
            exception.getMessage(), exception.getClass().getSimpleName());
    return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:38,代碼來源:TopologyExceptionHandler.java

示例3: handleExceptionInternal

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception exception, Object body, HttpHeaders headers,
                                                         HttpStatus status, WebRequest request) {
    MessageError error = new MessageError(request.getHeader(CORRELATION_ID), System.currentTimeMillis(),
            status.value(), status.getReasonPhrase(),
            exception.getMessage(), exception.getClass().getSimpleName());
    return super.handleExceptionInternal(exception, error, headers, status, request);
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:12,代碼來源:TopologyExceptionHandler.java

示例4: errorPage

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
@RequestMapping(produces = "text/html")
public String errorPage(HttpServletRequest request, Model model) {
    String message, error;
    HttpStatus status = getStatus(request);
    RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    Map<String, Object> attributeMap = this.errorAttributes.getErrorAttributes(requestAttributes, false);

    if (attributeMap != null) {
        message = (String) attributeMap.get("message");
        error = (String) attributeMap.get("error");
        model.addAttribute("header", error);
        model.addAttribute("message", message);
    }

    if (status.is4xxClientError()){
        if(status.value() == 404) {
            model.addAttribute("header", "Sorry but we couldn't find this page");
            model.addAttribute("message", "This page you are looking for does not exist.");
        } else if (status.value() == 403) {
            model.addAttribute("header", "Access denied");
            model.addAttribute("message", "Full authentication is required to access this resource.");
        }
    } else if (status.value() == 500){
        model.addAttribute("header", "Internal Server Error");
        model.addAttribute("message",
                "If the problem persists feel free to create an issue in Github.");
    }
    model.addAttribute("number", status.value());
    return "errorPage";
}
 
開發者ID:dizitart,項目名稱:nitrite-database,代碼行數:31,代碼來源:DataGateErrorController.java

示例5: HttpStatusCodeException

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
/**
 * Construct a new instance of {@code HttpStatusCodeException} based on an
 * {@link HttpStatus}, status text, and response body content.
 * @param statusCode the status code
 * @param statusText the status text
 * @param responseHeaders the response headers, may be {@code null}
 * @param responseBody the response body content, may be {@code null}
 * @param responseCharset the response body charset, may be {@code null}
 * @since 3.1.2
 */
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
		HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {

	super(statusCode.value() + " " + statusText);
	this.statusCode = statusCode;
	this.statusText = statusText;
	this.responseHeaders = responseHeaders;
	this.responseBody = responseBody != null ? responseBody : new byte[0];
	this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:HttpStatusCodeException.java

示例6: handleResponseException

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
@ExceptionHandler(SearchResponseException.class)
@ResponseBody
ResponseEntity<?> handleResponseException(SearchResponseException ex) {
    int statusCode = ex.getResponseException().getResponse().getStatusLine().getStatusCode();
    HttpStatus status = HttpStatus.valueOf(statusCode);
    return new ResponseEntity<>(new EndpointError(status.value(), ex.getErrorMessage()), status);
}
 
開發者ID:chaokunyang,項目名稱:jkes,代碼行數:8,代碼來源:EndpointAdvice.java

示例7: create

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
public static ResultMap create(String message, HttpStatus status) {
    return new ResultMap(status.value(), message, status.getReasonPhrase());
}
 
開發者ID:Zigin,項目名稱:MonitorPlatform,代碼行數:4,代碼來源:ResultMap.java

示例8: ErrorMessage

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
public ErrorMessage(String error, HttpStatus status, String details) {
	this(error, status.value(), details);
}
 
開發者ID:yushijinhun,項目名稱:akir,代碼行數:4,代碼來源:ErrorMessage.java

示例9: handleGenericException

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
private ExceptionDTO handleGenericException(Throwable e, HttpStatus status) {
    return new ExceptionDTO(status.value(), status.getReasonPhrase(), e.getMessage());
}
 
開發者ID:farchanjo,項目名稱:webcron,代碼行數:4,代碼來源:ExceptionResource.java

示例10: handleAnotherException

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
@ExceptionHandler(AnotherException.class)
@ResponseBody
ResponseEntity<?> handleAnotherException(HttpServletRequest request, Throwable ex) {
  HttpStatus status = getStatus(request);
  return new ResponseEntity<>(new AnotherExceptionErrorMessage(status.value(), ex.getMessage()), status);
}
 
開發者ID:chanjarster,項目名稱:spring-mvc-error-handling-example,代碼行數:7,代碼來源:BarControllerAdvice.java

示例11: RestErrorResponse

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
protected RestErrorResponse(HttpStatus status, String detailMessage) {
  statusCode = status.value();
  reasonPhrase = status.getReasonPhrase();
  this.detailMessage = detailMessage;
}
 
開發者ID:springuni,項目名稱:springuni-particles,代碼行數:6,代碼來源:RestErrorResponse.java

示例12: JsonResult

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
public JsonResult(HttpStatus code, String message, Object data) {
    this.code = code.value();
    this.message = message;
    this.data = data;
}
 
開發者ID:Nbsaw,項目名稱:miaohu,代碼行數:6,代碼來源:JsonResult.java

示例13: createLog

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
private String createLog(HttpServletRequest request, HttpStatus status, String code, String message) {
    return request.getMethod() + " " + request.getRequestURI() + " " + status.value() + " | " + code + " | " + message;
}
 
開發者ID:mkopylec,項目名稱:project-manager,代碼行數:4,代碼來源:ErrorHandler.java

示例14: of

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
public static ErrorResponse of(HttpStatus httpStatus, String message) {
    return new ErrorResponse(httpStatus.getReasonPhrase(), message, httpStatus.value());
}
 
開發者ID:shout-star,項目名稱:uroborosql-springboot-demo,代碼行數:4,代碼來源:ErrorResponse.java

示例15: ApiError

import org.springframework.http.HttpStatus; //導入方法依賴的package包/類
public ApiError(HttpStatus httpStatus, String message, String description) {
    statusCode = httpStatus.value();
    meaning = httpStatus.getReasonPhrase();
    this.message = message;
    this.description = description;
}
 
開發者ID:dhaval-mehta,項目名稱:url-to-google-drive,代碼行數:7,代碼來源:ApiError.java


注:本文中的org.springframework.http.HttpStatus.value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。