当前位置: 首页>>代码示例>>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;未经允许,请勿转载。