本文整理汇总了Java中org.zalando.problem.Problem.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Problem.getStatus方法的具体用法?Java Problem.getStatus怎么用?Java Problem.getStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zalando.problem.Problem
的用法示例。
在下文中一共展示了Problem.getStatus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.zalando.problem.Problem; //导入方法依赖的package包/类
/**
* Post-process Problem payload to add the message key for front-end if needed
*/
@Override
public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity, NativeWebRequest request) {
if (entity == null || entity.getBody() == null) {
return entity;
}
Problem problem = entity.getBody();
if (!(problem instanceof ConstraintViolationProblem || problem instanceof DefaultProblem)) {
return entity;
}
ProblemBuilder builder = Problem.builder()
.withType(Problem.DEFAULT_TYPE.equals(problem.getType()) ? ErrorConstants.DEFAULT_TYPE : problem.getType())
.withStatus(problem.getStatus())
.withTitle(problem.getTitle())
.with("path", request.getNativeRequest(HttpServletRequest.class).getRequestURI());
if (problem instanceof ConstraintViolationProblem) {
builder
.with("violations", ((ConstraintViolationProblem) problem).getViolations())
.with("message", ErrorConstants.ERR_VALIDATION);
return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
} else {
builder
.withCause(((DefaultProblem) problem).getCause())
.withDetail(problem.getDetail())
.withInstance(problem.getInstance());
problem.getParameters().forEach(builder::with);
if (!problem.getParameters().containsKey("message") && problem.getStatus() != null) {
builder.with("message", "error.http." + problem.getStatus().getStatusCode());
}
return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
}
}
示例2: write
import org.zalando.problem.Problem; //导入方法依赖的package包/类
private static void write(HttpServerResponse response, Problem problem) {
int statusCode = problem.getStatus() != null ? problem.getStatus().getStatusCode() : Status.OK.getStatusCode();
response.setChunked(true).putHeader("Content-Type", "application/problem+json");
try {
response
.setStatusCode(statusCode)
.write(Json.encode(problem));
} catch (EncodeException e) {
LOG.error("Error while writing problem to JSON", e);
response
.setStatusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode())
.write(INTERNAL_SERVER_ERROR);
} finally {
response.end();
}
}
示例3: isServerProblem
import org.zalando.problem.Problem; //导入方法依赖的package包/类
private static boolean isServerProblem(Problem problem) {
return problem.getStatus() == null ||
(problem.getStatus().getStatusCode() >= 500 && problem.getStatus().getStatusCode() < 600);
}