本文整理了Java中io.micronaut.http.HttpResponse.status()
方法的一些代码示例,展示了HttpResponse.status()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.status()
方法的具体详情如下:
包路径:io.micronaut.http.HttpResponse
类名称:HttpResponse
方法名:status
暂无
代码示例来源:origin: micronaut-projects/micronaut-core
private MutableHttpResponse<Object> forStatus(AnnotationMetadata annotationMetadata) {
HttpStatus status = HttpStatus.OK;
if (annotationMetadata.hasAnnotation(Status.class)) {
status = annotationMetadata.getValue(Status.class, HttpStatus.class).orElse(status);
}
return HttpResponse.status(status);
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/status")
public HttpMessage status() {
return HttpResponse.status(HttpStatus.MOVED_PERMANENTLY);
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public Object handle(HttpRequest request, JsonProcessingException exception) {
// TODO: Send JSON back with detailed error
MutableHttpResponse<Object> response = HttpResponse.status(HttpStatus.BAD_REQUEST, "Invalid JSON");
JsonError body = new JsonError("Invalid JSON: " + exception.getMessage());
body.link(Link.SELF, Link.of(request.getUri()));
response.body(body);
return response;
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
HttpMethod methodToMatch = preflight ? headers.getFirst(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.class).orElse(requestMethod) : requestMethod;
if (allowedMethods.stream().noneMatch(method -> method.equals(methodToMatch))) {
return Optional.of(HttpResponse.status(HttpStatus.FORBIDDEN));
.allMatch(header -> allowedHeaders.stream()
.anyMatch(allowedHeader -> allowedHeader.equals(header.toString().trim())))) {
return Optional.of(HttpResponse.status(HttpStatus.FORBIDDEN));
代码示例来源:origin: micronaut-projects/micronaut-core
private MutableHttpResponse<?> messageToResponse(RouteMatch<?> finalRoute, Object message) {
MutableHttpResponse<?> response;
if (message instanceof HttpResponse) {
response = ConversionService.SHARED.convert(message, NettyMutableHttpResponse.class)
.orElseThrow(() -> new InternalServerException("Emitted response is not mutable"));
} else {
if (message instanceof HttpStatus) {
response = HttpResponse.status((HttpStatus) message);
} else {
response = forStatus(finalRoute.getAnnotationMetadata()).body(message);
}
}
return response;
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get("/{isbn}")
public HttpResponse find(String isbn) {
if (isbn.equals("1680502395")) {
Map<String, Object> m = new HashMap<>();
m.put("status", 401);
m.put("error", "Unauthorized");
m.put("message", "No message available");
m.put("path", "/books/"+isbn);
return HttpResponse.status(HttpStatus.UNAUTHORIZED).body(m);
}
return HttpResponse.ok(new Book("1491950358", "Building Microservices"));
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Get(produces = MediaType.TEXT_PLAIN)
public HttpResponse index() {
return HttpResponse.status(HttpStatus.CREATED).body("success");
}
//end::httpResponseStatus[]
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, HttpStatusException exception) {
Object body = exception.getBody()
.orElseGet(() -> {
JsonError error = new JsonError(exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return error;
});
return HttpResponse
.status(exception.getStatus())
.body(body);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public HttpResponse handle(HttpRequest request, ContentLengthExceededException exception) {
JsonError error = new JsonError(exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse
.status(HttpStatus.REQUEST_ENTITY_TOO_LARGE)
.body(error);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
request,
nettyHttpRequest,
HttpResponse.status(status),
status.getReason()
);
request,
nettyHttpRequest,
HttpResponse.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE),
"Content Type [" + contentType + "] not allowed. Allowed types: " + existingRouteConsumes);
return;
request,
nettyHttpRequest,
HttpResponse.status(HttpStatus.BAD_REQUEST),
"Not a WebSocket request");
} else {
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
Assert.that(request.getAttributes().contains("first"));
Assert.that(!request.getAttributes().contains("second"));
if(request.getParameters().get("username") == null) {
return Publishers.just(HttpResponse.status(HttpStatus.FORBIDDEN));
}
else {
request.getAttributes().put("authenticated", true);
return Publishers.map(
chain.proceed(request),
mutableHttpResponse -> mutableHttpResponse.header("X-Test", "Foo " + request.getAttributes().get("SomeServiceValue", String.class, "none"))
);
}
}
}
代码示例来源:origin: io.micronaut/management
/**
* Returns 401 if the route is a match for an endpoint with sensitive true.
*
* @param request The {@link HttpRequest} instance
* @param chain The {@link ServerFilterChain} instance
* @return A {@link Publisher} for the Http response
*/
@Override
protected Publisher<MutableHttpResponse<?>> doFilterOnce(HttpRequest<?> request, ServerFilterChain chain) {
Optional<RouteMatch> routeMatch = RouteMatchUtils.findRouteMatchAtRequest(request);
if (routeMatch.isPresent() && routeMatch.get() instanceof MethodBasedRouteMatch) {
ExecutableMethod method = ((MethodBasedRouteMatch) routeMatch.get()).getExecutableMethod();
if (endpointMethods.containsKey(method)) {
if (endpointMethods.get(method)) {
return Publishers.just(HttpResponse.status(HttpStatus.UNAUTHORIZED));
}
}
}
return chain.proceed(request);
}
}
代码示例来源:origin: io.micronaut/micronaut-management
/**
* Returns 401 if the route is a match for an endpoint with sensitive true.
*
* @param request The {@link HttpRequest} instance
* @param chain The {@link ServerFilterChain} instance
* @return A {@link Publisher} for the Http response
*/
@Override
protected Publisher<MutableHttpResponse<?>> doFilterOnce(HttpRequest<?> request, ServerFilterChain chain) {
Optional<RouteMatch> routeMatch = RouteMatchUtils.findRouteMatchAtRequest(request);
if (routeMatch.isPresent() && routeMatch.get() instanceof MethodBasedRouteMatch) {
ExecutableMethod method = ((MethodBasedRouteMatch) routeMatch.get()).getExecutableMethod();
if (endpointMethods.containsKey(method)) {
if (endpointMethods.get(method)) {
return Publishers.just(HttpResponse.status(HttpStatus.UNAUTHORIZED));
}
}
}
return chain.proceed(request);
}
}
代码示例来源:origin: io.micronaut/http-server
@Override
public Object handle(HttpRequest request, JsonProcessingException exception) {
// TODO: Send JSON back with detailed error
MutableHttpResponse<Object> response = HttpResponse.status(HttpStatus.BAD_REQUEST, "Invalid JSON");
JsonError body = new JsonError("Invalid JSON: " + exception.getMessage());
body.link(Link.SELF, Link.of(request.getUri()));
response.body(body);
return response;
}
}
代码示例来源:origin: io.micronaut/http-server
HttpMethod methodToMatch = preflight ? headers.getFirst(ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.class).orElse(requestMethod) : requestMethod;
if (allowedMethods.stream().noneMatch(method -> method.equals(methodToMatch))) {
return Optional.of(HttpResponse.status(HttpStatus.FORBIDDEN));
.allMatch(header -> allowedHeaders.stream()
.anyMatch(allowedHeader -> allowedHeader.equals(header.toString().trim())))) {
return Optional.of(HttpResponse.status(HttpStatus.FORBIDDEN));
代码示例来源:origin: io.micronaut/http-server
@Override
public HttpResponse handle(HttpRequest request, ContentLengthExceededException exception) {
JsonError error = new JsonError(exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse
.status(HttpStatus.REQUEST_ENTITY_TOO_LARGE)
.body(error);
}
}
代码示例来源:origin: io.micronaut/http-server
@Override
public HttpResponse handle(HttpRequest request, HttpStatusException exception) {
Object body = exception.getBody()
.orElseGet(() -> {
JsonError error = new JsonError(exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return error;
});
return HttpResponse
.status(exception.getStatus())
.body(body);
}
}
内容来源于网络,如有侵权,请联系作者删除!