本文整理汇总了Java中org.springframework.web.reactive.function.BodyExtractors类的典型用法代码示例。如果您正苦于以下问题:Java BodyExtractors类的具体用法?Java BodyExtractors怎么用?Java BodyExtractors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BodyExtractors类属于org.springframework.web.reactive.function包,在下文中一共展示了BodyExtractors类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: endpointProxy
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
@RequestMapping(path = REQUEST_MAPPING_PATH, method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST,
RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS})
public Mono<Void> endpointProxy(@PathVariable("instanceId") String instanceId,
ServerHttpRequest request,
ServerHttpResponse response) {
String endpointLocalPath = getEndpointLocalPath(request.getPath().pathWithinApplication().value());
URI uri = UriComponentsBuilder.fromPath(endpointLocalPath)
.query(request.getURI().getRawQuery())
.build(true)
.toUri();
return super.forward(instanceId, uri, request.getMethod(), request.getHeaders(),
() -> BodyInserters.fromDataBuffers(request.getBody())).flatMap(clientResponse -> {
response.setStatusCode(clientResponse.statusCode());
response.getHeaders().addAll(filterHeaders(clientResponse.headers().asHttpHeaders()));
return response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers()));
});
}
示例2: filter
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// NOTICE: nothing in "pre" filter stage as CLIENT_RESPONSE_ATTR is not added
// until the WebHandler is run
return chain.filter(exchange).then(Mono.defer(() -> {
ClientResponse clientResponse = exchange.getAttribute(CLIENT_RESPONSE_ATTR);
if (clientResponse == null) {
return Mono.empty();
}
log.trace("WebClientWriteResponseFilter start");
ServerHttpResponse response = exchange.getResponse();
return response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers())).log("webClient response");
}));
}
示例3: endpointProxy
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
@ResponseBody
@RequestMapping(path = REQUEST_MAPPING_PATH, method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST,
RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS})
public Mono<Void> endpointProxy(@PathVariable("instanceId") String instanceId,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) {
ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
String pathWithinApplication = servletRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)
.toString();
String endpointLocalPath = getEndpointLocalPath(pathWithinApplication);
URI uri = UriComponentsBuilder.fromPath(endpointLocalPath)
.query(request.getURI().getRawQuery())
.build(true)
.toUri();
//We need to explicitly block until the headers are recieved.
// otherwise the FrameworkServlet will add wrong Allow header for OPTIONS request
ClientResponse clientResponse = super.forward(instanceId, uri, request.getMethod(), request.getHeaders(),
() -> BodyInserters.fromDataBuffers(
DataBufferUtils.readInputStream(request::getBody, this.bufferFactory, 16384))).block();
response.setStatusCode(clientResponse.statusCode());
response.getHeaders().addAll(filterHeaders(clientResponse.headers().asHttpHeaders()));
try {
return DataBufferUtils.write(clientResponse.body(BodyExtractors.toDataBuffers()), response.getBody())
.doOnNext(DataBufferUtils::release)
.then();
} catch (IOException ex) {
return Mono.error(new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, null, ex));
}
}
示例4: bodyToMono
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
@Override
public <T> Mono<T> bodyToMono(Class<? extends T> elementClass) {
if (Void.class.isAssignableFrom(elementClass)) {
return response.bodyToMono(elementClass);
} else {
return body(BodyExtractors.toMono(elementClass));
}
}
示例5: bodyToFlux
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
@Override
public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass) {
if (Void.class.isAssignableFrom(elementClass)) {
return response.bodyToFlux(elementClass);
} else {
return body(BodyExtractors.toFlux(elementClass));
}
}
示例6: create
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
public Mono<ServerResponse> create(ServerRequest req) {
return req.body(BodyExtractors.toMono(Post.class))
.flatMap(post -> this.posts.save(post))
.flatMap(p -> created(URI.create("/posts/" + p.getId())).build());
}
示例7: create
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
public Mono<ServerResponse> create(ServerRequest req) {
return req.body(BodyExtractors.toMono(Post.class))
.flatMap(post -> this.posts.save(post))
.flatMap(p -> ServerResponse.created(URI.create("/posts/" + p.getId())).build());
}
示例8: toMono
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
private <T> Mono<T> toMono(Mono<ClientResponse> monoResponse, Class<T> monoContentType) {
return monoResponse
.flatMap(response -> bodyToPublisher(response,
BodyExtractors.toMono(monoContentType),
ErrorBodyExtractors.toMono(httpErrorReaders)));
}
示例9: toFlux
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
private <T> Flux<T> toFlux(Mono<ClientResponse> monoResponse, Class<T> fluxContentType) {
return monoResponse
.flatMapMany(response -> bodyToPublisher(response,
BodyExtractors.toFlux(fluxContentType),
ErrorBodyExtractors.toFlux(httpErrorReaders)));
}
示例10: mapResponse
import org.springframework.web.reactive.function.BodyExtractors; //导入依赖的package包/类
private static <T> Function<ClientResponse, Mono<? extends T>> mapResponse(
ParameterizedTypeReference<T> typeReference, String path) {
return response -> isSuccess(response) ? response.body(BodyExtractors
.toMono(typeReference)) : mapOtherwise(response, path);
}