• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClientRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.web.reactive.function.client.ClientRequest的典型用法代码示例。如果您正苦于以下问题:Java ClientRequest类的具体用法?Java ClientRequest怎么用?Java ClientRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientRequest类属于org.springframework.web.reactive.function.client包,在下文中一共展示了ClientRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: ReactiveVaultTemplate

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
/**
 * Create a new {@link ReactiveVaultTemplate} with a {@link VaultEndpointProvider},
 * {@link ClientHttpConnector} and {@link VaultTokenSupplier}.
 *
 * @param endpointProvider must not be {@literal null}.
 * @param connector must not be {@literal null}.
 * @param vaultTokenSupplier must not be {@literal null}.
 */
public ReactiveVaultTemplate(VaultEndpointProvider endpointProvider,
		ClientHttpConnector connector, VaultTokenSupplier vaultTokenSupplier) {

	Assert.notNull(endpointProvider, "VaultEndpointProvider must not be null");
	Assert.notNull(connector, "ClientHttpConnector must not be null");
	Assert.notNull(vaultTokenSupplier, "AuthenticationSupplier must not be null");

	ExchangeFilterFunction filter = ofRequestProcessor(request -> vaultTokenSupplier
			.getVaultToken().map(token -> {

				return ClientRequest.from(request).headers(headers -> {
					headers.set(VaultHttpHeaders.VAULT_TOKEN, token.getToken());
				}).build();
			}));

	this.statelessClient = ReactiveVaultClients.createWebClient(endpointProvider,
			connector);
	this.sessionClient = ReactiveVaultClients
			.createWebClient(endpointProvider, connector).mutate().filter(filter)
			.build();
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:30,代码来源:ReactiveVaultTemplate.java


示例2: requestForQuotationWithHystrixWebClient

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
private Mono<Quotation> requestForQuotationWithHystrixWebClient(String bankURL, Double loanAmount) {

        ClientRequest<Void> request = ClientRequest.GET(bankURL.concat(REQUEST_QUOTATION_PATH), loanAmount)
                .accept(MediaType.APPLICATION_JSON)
                .build();

        return hystrixWebClient.exchangeCommandBuilder()
                .withCommandName(bankURL)
                .withErrorThresholdPercentage(50)
                .withRequestVolumeThreshold(5)
                .withSleepWindowInMilliseconds(5000)
                .withExecutionTimeoutInMilliseconds(1500)
                .exchange(request)
                .then(response -> response.bodyToMono(Quotation.class))
                .otherwiseReturn(OFFER_IN_CASE_OF_ERROR);
    }
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:17,代码来源:SpringReactorReactiveLoanRequestService.java


示例3: execute_withHeaders

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Test
public void execute_withHeaders() {
    Request request = new MockRequest("http://example.ca", HttpMethod.GET);
    request.headers().add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
    request.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE);
    
    requestExecutor.execute(request);
    ClientRequest clientRequest = verifyExchange();
    assertThat(clientRequest.url())
            .isEqualTo(URI.create("http://example.ca"));
    assertThat(clientRequest.method())
            .isEqualTo(HttpMethod.GET);
    assertThat(clientRequest.headers().getFirst(HttpHeaders.ACCEPT))
            .isEqualTo(MediaType.APPLICATION_JSON_VALUE);
    assertThat(clientRequest.headers().getFirst(HttpHeaders.CONTENT_TYPE))
            .isEqualTo(MediaType.APPLICATION_XML_VALUE);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:18,代码来源:DefaultRequestExecutorTest.java


示例4: createNewSpan

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
/**
 * Enriches the request with proper headers and publishes
 * the client sent event
 */
private Span createNewSpan(ClientRequest request, Span optionalParent) {
	URI uri = request.url();
	String spanName = getName(uri);
	Span newSpan;
	if (optionalParent == null) {
		newSpan = tracer().createSpan(spanName);
	} else {
		newSpan = tracer().createSpan(spanName, optionalParent);
	}
	addRequestTags(request);
	newSpan.logEvent(Span.CLIENT_SEND);
	if (log.isDebugEnabled()) {
		log.debug("Starting new client span [" + newSpan + "]");
	}
	return newSpan;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:21,代码来源:TraceWebClientBeanPostProcessor.java


示例5: filter

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
	URI originalUrl = request.url();
	String serviceId = originalUrl.getHost();
	Assert.state(serviceId != null, "Request URI does not contain a valid hostname: " + originalUrl);
	//TODO: reactive lb client

	ServiceInstance instance = this.loadBalancerClient.choose(serviceId);
	URI uri = this.loadBalancerClient.reconstructURI(instance, originalUrl);
	ClientRequest newRequest = ClientRequest.method(request.method(), uri)
			.headers(headers -> headers.addAll(request.headers()))
			.cookies(cookies -> cookies.addAll(request.cookies()))
			.attributes(attributes -> attributes.putAll(request.attributes()))
			.body(request.body())
			.build();
	return next.exchange(newRequest);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:18,代码来源:LoadBalancerExchangeFilterFunction.java


示例6: rewriteEndpointUrl

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
public static ExchangeFilterFunction rewriteEndpointUrl() {
    return withInstance((instance, request, next) -> {
        if (request.url().isAbsolute()) {
            return next.exchange(request);
        }

        UriComponents oldUrl = UriComponentsBuilder.fromUri(request.url()).build();
        if (oldUrl.getPathSegments().isEmpty()) {
            return Mono.error(new InstanceWebClientException("No endpoint specified"));
        }

        String endpointId = oldUrl.getPathSegments().get(0);
        Optional<Endpoint> endpoint = instance.getEndpoints().get(endpointId);

        if (!endpoint.isPresent()) {
            return Mono.error(new InstanceWebClientException("Endpoint '" + endpointId + "' not found"));
        }

        URI newUrl = rewriteUrl(oldUrl, endpoint.get().getUrl());
        ClientRequest newRequest = ClientRequest.from(request)
                                                .attribute(ATTRIBUTE_ENDPOINT, endpoint.get().getId())
                                                .url(newUrl)
                                                .build();
        return next.exchange(newRequest);
    });
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:27,代码来源:InstanceFilterFunctions.java


示例7: requestForQuotation

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Override
protected Mono<Quotation> requestForQuotation(String bankURL, Double loanAmount) {
    ClientRequest<Void> request = ClientRequest.GET(bankURL.concat(REQUEST_QUOTATION_PATH), loanAmount)
            .accept(MediaType.APPLICATION_JSON)
            .build();

    return hystrixWebClient.exchangeCommandBuilder()
            .withCommandName(bankURL)
            .withErrorThresholdPercentage(50)
            .withRequestVolumeThreshold(5)
            .withSleepWindowInMilliseconds(5000)
            .withExecutionTimeoutInMilliseconds(Long.valueOf(REQUEST_TIMEOUT.toMillis()).intValue())
            .exchange(request)
            .then(response -> response.bodyToMono(Quotation.class));
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:16,代码来源:ReactorLoanBrokerAgent.java


示例8: requestForQuotationWithoutCB

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
private Mono<Quotation> requestForQuotationWithoutCB(String bankURL, Double loanAmount) {

        ClientRequest<Void> request = ClientRequest.GET(bankURL.concat(REQUEST_QUOTATION_PATH), loanAmount)
                .accept(MediaType.APPLICATION_JSON)
                .build();

        Mono<Quotation> offer = webClient.exchange(request)
                .timeout(REQUEST_TIMEOUT) // Response should come back within REQUEST_TIMEOUT
                .then(response -> response.bodyToMono(Quotation.class))
                .otherwiseReturn(OFFER_IN_CASE_OF_ERROR); // Fallback strategy

        return offer;
    }
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:14,代码来源:SpringReactorReactiveLoanRequestService.java


示例9: construct

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Override
protected Observable<Quotation> construct() {

    ClientRequest<Void> request = ClientRequest.GET(getBankURL().concat(REQUEST_QUOTATION_PATH), getLoanAmount())
            .accept(MediaType.APPLICATION_JSON)
            .build();

    Mono<Quotation> offer = webClient
            .exchange(request)
            .timeout(REQUEST_TIMEOUT) // Response should come back within REQUEST_TIMEOUT
            .then(response -> response.bodyToMono(Quotation.class))
            .otherwiseReturn(throwable -> !(throwable instanceof TimeoutException), OFFER_IN_CASE_OF_ERROR); // Fallback strategy

    return toSingle(offer.toFuture()).toObservable();
}
 
开发者ID:noorulhaq,项目名称:reactive.loanbroker.system,代码行数:16,代码来源:SpringReactorReactiveLoanRequestService.java


示例10: logClientRequest

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
private static Mono<ClientResponse> logClientRequest(ClientRequest clientRequest, ExchangeFunction exchangeFunction, Logger logger, LogLevel logLevel) {
    boolean logHeaders = LogLevel.HEADERS.equals(logLevel);
    boolean logBasic = logHeaders || LogLevel.BASIC.equals(logLevel);

    long startNs = logBasic? System.nanoTime() : 0;
    if (logBasic) {
        logger.log(()-> "--> " + clientRequest.method() + ' ' + clientRequest.url());
        logger.log(()-> "Content-Type: " + clientRequest.headers().getContentType());
        if (logHeaders) {
            logger.log("Headers:");
            clientRequest.headers().forEach((name, values) -> {
                if (!HttpHeaders.CONTENT_TYPE.equals(name))
                    logger.log(()-> " * " + name + ": " + values);
            });
        }
        logger.log(() -> "--> END " + clientRequest.method());
    }
    return exchangeFunction
            .exchange(clientRequest)
            .doOnEach(clientResponseSignal -> {
                ClientResponse response;
                if (logBasic && (response = clientResponseSignal.get()) != null) {
                    long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
                    logger.log("<-- " + response.statusCode() + ' ' + clientRequest.method() + ' ' + clientRequest.url() + " (" + tookMs + "ms)");
                    if (logHeaders) {
                        logger.log("Headers:");
                        response.headers().asHttpHeaders().forEach((name, values) -> logger.log(()-> " - " + name + ": " + values));
                    }
                    logger.log(() -> "<-- END HTTP " + clientRequest.method());
                }
            });
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:33,代码来源:ExchangeFilterFunctions.java


示例11: execute

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Test
public void execute() {
    Request request = new MockRequest("http://example.ca", HttpMethod.GET);
    request.headers().add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
    
    requestExecutor.execute(request);
    ClientRequest clientRequest = verifyExchange();
    assertThat(clientRequest.url())
            .isEqualTo(URI.create("http://example.ca"));
    assertThat(clientRequest.method())
            .isEqualTo(HttpMethod.GET);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:13,代码来源:DefaultRequestExecutorTest.java


示例12: tweetBot

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
@Bean
public CommandLineRunner tweetBot(TwitterOAuth twitterOAuth, ReactiveTweetRepository tweetRepo) {

    return args -> {
        MultiValueMap<String, String> body = new LinkedMultiValueMap<>();

        String tracks = "#cltjug,#FathersDay";
        if (args.length > 0) {
            log.info("Using arguments as tracks");
            tracks = String.join(",", args);
        }

        log.info("Filtering tracks [{}]", tracks);
        body.add("track", tracks);

        WebClient webClient = WebClient.create()
                .filter((currentRequest, next) ->
                        next.exchange(ClientRequest.from(currentRequest)
                                .header(HttpHeaders.AUTHORIZATION, twitterOAuth.oAuth1Header(
                                        currentRequest.url(), currentRequest.method(), body.toSingleValueMap()))
                                .build()));

        Flux<Tweet> tweets = webClient
                .post()
                .uri(TwitterApiEndpoint.TWITTER_STREAM_API_STATUS_FILTER_URL)
                .contentType(MediaType.APPLICATION_FORM_URLENCODED)
                .body(BodyInserters.fromFormData(body))
                .exchange()
                .flatMapMany(clientResponse -> clientResponse.bodyToFlux(Tweet.class));

        tweetRepo.saveAll(tweets).subscribe(System.out::println);

    };
}
 
开发者ID:orlandovald,项目名称:webflux-twitter-demo,代码行数:35,代码来源:WebfluxTwitterDemoApplication.java


示例13: addRequestTags

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
/**
 * Adds HTTP tags to the client side span
 */
private void addRequestTags(ClientRequest request) {
	keysInjector().addRequestTags(request.url().toString(),
			request.url().getHost(),
			request.url().getPath(),
			request.method().name(),
			request.headers());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:11,代码来源:TraceWebClientBeanPostProcessor.java


示例14: setInstance

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
public static ExchangeFilterFunction setInstance(Mono<Instance> instance) {
    return (request, next) -> instance.map(
            i -> ClientRequest.from(request).attribute(ATTRIBUTE_INSTANCE, i).build())
                                      .switchIfEmpty(request.url().isAbsolute() ?
                                              Mono.just(request) :
                                              Mono.error(new InstanceWebClientException("Instance not found")))
                                      .flatMap(next::exchange);
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:9,代码来源:InstanceFilterFunctions.java


示例15: addHeaders

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
public static ExchangeFilterFunction addHeaders(HttpHeadersProvider httpHeadersProvider) {
    return withInstance((instance, request, next) -> {
        ClientRequest newRequest = ClientRequest.from(request)
                                                .headers(headers -> headers.addAll(
                                                        httpHeadersProvider.getHeaders(instance)))
                                                .build();
        return next.exchange(newRequest);
    });
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:10,代码来源:InstanceFilterFunctions.java


示例16: convertLegacyEndpoint

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
public static ExchangeFilterFunction convertLegacyEndpoint(LegacyEndpointConverter converter) {
    return (ClientRequest request, ExchangeFunction next) -> {
        Mono<ClientResponse> clientResponse = next.exchange(request);
        if (request.attribute(ATTRIBUTE_ENDPOINT).map(converter::canConvert).orElse(false)) {
            return clientResponse.flatMap(response -> {
                if (response.headers().contentType().map(ACTUATOR_V1_MEDIATYPE::isCompatibleWith).orElse(false)) {
                    return convertClientResponse(converter::convert, ACTUATOR_V2_MEDIATYPE).apply(response);
                }
                return Mono.just(response);
            });
        }
        return clientResponse;
    };
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:15,代码来源:InstanceFilterFunctions.java


示例17: oAuthToken

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
private ExchangeFilterFunction oAuthToken(String token) {
    return (clientRequest, exchangeFunction) ->
            exchangeFunction
                    .exchange(ClientRequest.from(clientRequest).header("Authorization", "Bearer " + token).build());
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:6,代码来源:GitterClient.java


示例18: verifyExchange

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
private ClientRequest verifyExchange() {
    ClientRequest request = this.captor.getValue();
    verify(this.exchangeFunction).exchange(request);
    verifyNoMoreInteractions(this.exchangeFunction);
    return request;
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:7,代码来源:DefaultRequestExecutorTest.java


示例19: ClientRequestTextMap

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
ClientRequestTextMap(ClientRequest readDelegate,
		ClientRequest.Builder writeDelegate) {
	this.readDelegate = readDelegate;
	this.writeDelegate = writeDelegate;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:6,代码来源:TraceWebClientBeanPostProcessor.java


示例20: process

import org.springframework.web.reactive.function.client.ClientRequest; //导入依赖的package包/类
ClientRequest process(ClientRequest request); 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:2,代码来源:RequestProcessor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PsiTreeChangeEvent类代码示例发布时间:2022-05-22
下一篇:
Java LogHandlerAppFinishedEvent类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap