当前位置: 首页>>代码示例>>Java>>正文


Java BodyExtractors类代码示例

本文整理汇总了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()));
    });
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:19,代码来源:InstancesProxyController.java

示例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");
	}));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:16,代码来源:WebClientWriteResponseFilter.java

示例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));
    }
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:36,代码来源:InstancesProxyController.java

示例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));
    }
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:9,代码来源:InstanceFilterFunctions.java

示例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));
    }
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:9,代码来源:InstanceFilterFunctions.java

示例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());
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:6,代码来源:PostHandler.java

示例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());
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:6,代码来源:PostHandler.java

示例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)));
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:7,代码来源:DefaultResponseBodyProcessor.java

示例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)));
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:7,代码来源:DefaultResponseBodyProcessor.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:7,代码来源:ReactiveVaultTemplate.java


注:本文中的org.springframework.web.reactive.function.BodyExtractors类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。