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


Java ClientResponse类代码示例

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


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

示例1: mockWebClient

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
public static WebClient mockWebClient(final WebClient originalClient, final Mono<?> mono){
    WebClient client = spy(originalClient);

    WebClient.UriSpec uriSpec = mock(WebClient.UriSpec.class);
    doReturn(uriSpec).when(client).get();

    WebClient.RequestHeadersSpec<?> headerSpec = mock(WebClient.RequestHeadersSpec.class);
    doReturn(headerSpec).when(uriSpec).uri(anyString());
    doReturn(headerSpec).when(headerSpec).accept(any());

    ClientResponse clientResponse = mock(ClientResponse.class);
    doReturn(mono).when(clientResponse).bodyToMono(Mockito.any());
    doReturn(Mono.just(clientResponse)).when(headerSpec).exchange();

    return client;
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:17,代码来源:RestServiceHelper.java

示例2: filter

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的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: hostRouteWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void hostRouteWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/get")
			.header("Host", "www.example.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER))
								.isEqualTo(RoutePredicateHandlerMapping.class.getSimpleName());
						assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER))
								.isEqualTo("host_example_to_httpbin");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:21,代码来源:HostRoutePredicateFactoryTests.java

示例4: pathRouteWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void pathRouteWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/get")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER))
								.isEqualTo(RoutePredicateHandlerMapping.class.getSimpleName());
						assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER))
								.isEqualTo("default_path_to_httpbin");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:20,代码来源:PathRoutePredicateFactoryTests.java

示例5: hostRouteWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void hostRouteWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/get")
			.header("Host", "www.method.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER))
								.isEqualTo(RoutePredicateHandlerMapping.class.getSimpleName());
						assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER))
								.isEqualTo("method_test");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:21,代码来源:MethodRoutePredicateFactoryTests.java

示例6: compositeRouteWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void compositeRouteWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/headers?foo=bar&baz")
			.header("Host", "www.foo.org")
			.header("X-Request-Id", "123")
			.cookie("chocolate", "chip")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER))
								.isEqualTo(RoutePredicateHandlerMapping.class.getSimpleName());
						assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER))
								.isEqualTo("host_foo_path_headers_to_httpbin");
						assertThat(httpHeaders.getFirst("X-Response-Foo"))
								.isEqualTo("Bar");
					})
			.expectComplete()
			.verify();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:25,代码来源:GatewayIntegrationTests.java

示例7: defaultFiltersWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void defaultFiltersWorks() {
	assertThat(this.properties.getDefaultFilters()).isNotEmpty();

	Mono<ClientResponse> result = webClient.get()
			.uri("/headers")
			.header("Host", "www.addresponseheader.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst("X-Response-Default-Foo"))
								.isEqualTo("Default-Bar");
						assertThat(httpHeaders.get("X-Response-Default-Foo")).hasSize(1);
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:21,代码来源:GatewayIntegrationTests.java

示例8: loadBalancerFilterWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void loadBalancerFilterWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/get")
			.header("Host", "www.loadbalancerclient.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER))
								.isEqualTo("load_balancer_client_test");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:19,代码来源:GatewayIntegrationTests.java

示例9: removeResponseHeaderFilterWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void removeResponseHeaderFilterWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/headers")
			.header("Host", "www.removereresponseheader.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders).doesNotContainKey("X-Request-Foo");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:17,代码来源:RemoveResponseHeaderGatewayFilterFactoryTests.java

示例10: secureHeadersFilterWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void secureHeadersFilterWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/headers")
			.header("Host", "www.secureheaders.org")
			.exchange();

	SecureHeadersProperties defaults = new SecureHeadersProperties();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.OK);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(X_XSS_PROTECTION_HEADER)).isEqualTo(defaults.getXssProtectionHeader());
						assertThat(httpHeaders.getFirst(STRICT_TRANSPORT_SECURITY_HEADER)).isEqualTo(defaults.getStrictTransportSecurity());
						assertThat(httpHeaders.getFirst(X_FRAME_OPTIONS_HEADER)).isEqualTo(defaults.getFrameOptions());
						assertThat(httpHeaders.getFirst(X_CONTENT_TYPE_OPTIONS_HEADER)).isEqualTo(defaults.getContentTypeOptions());
						assertThat(httpHeaders.getFirst(REFERRER_POLICY_HEADER)).isEqualTo(defaults.getReferrerPolicy());
						assertThat(httpHeaders.getFirst(CONTENT_SECURITY_POLICY_HEADER)).isEqualTo(defaults.getContentSecurityPolicy());
						assertThat(httpHeaders.getFirst(X_DOWNLOAD_OPTIONS_HEADER)).isEqualTo(defaults.getDownloadOptions());
						assertThat(httpHeaders.getFirst(X_PERMITTED_CROSS_DOMAIN_POLICIES_HEADER)).isEqualTo(defaults.getPermittedCrossDomainPolicies());
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:27,代码来源:SecureHeadersGatewayFilterFactoryTests.java

示例11: redirectToFilterWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void redirectToFilterWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/")
			.header("Host", "www.redirectto.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						assertStatus(response, HttpStatus.FOUND);
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders.getFirst(HttpHeaders.LOCATION))
								.isEqualTo("http://example.org");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:19,代码来源:RedirectToGatewayFilterFactoryTests.java

示例12: setResponseHeaderFilterWorks

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
@Test
public void setResponseHeaderFilterWorks() {
	Mono<ClientResponse> result = webClient.get()
			.uri("/headers")
			.header("Host", "www.setreresponseheader.org")
			.exchange();

	StepVerifier.create(result)
			.consumeNextWith(
					response -> {
						HttpHeaders httpHeaders = response.headers().asHttpHeaders();
						assertThat(httpHeaders).containsKey("X-Request-Foo");
						assertThat(httpHeaders.get("X-Request-Foo")).containsExactly("Bar");
					})
			.expectComplete()
			.verify(DURATION);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:18,代码来源:SetResponseGatewayFilterFactoryTests.java

示例13: filter

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的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

示例14: createUser

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
public Mono<ClientResponse> createUser(String username, char[] password, List<String> tags) {
    if(username == null) {
        throw new IllegalArgumentException("username cannot be null");
    }
    if(password == null) {
        throw new IllegalArgumentException("password cannot be null or empty. If you need to create a user that "
            + "will only authenticate using an x509 certificate, use createUserWithPasswordHash with a blank hash.");
    }
    Map<String, Object> body = new HashMap<String, Object>();
    body.put("password", new String(password));
    body.put("tags", StringUtils.collectionToCommaDelimitedString(tags));

    return client
        .put()
        .uri("/users/{username}", username)
        .syncBody(body)
        .exchange();
}
 
开发者ID:rabbitmq,项目名称:hop,代码行数:19,代码来源:ReactiveClient.java

示例15: createUserWithPasswordHash

import org.springframework.web.reactive.function.client.ClientResponse; //导入依赖的package包/类
public Mono<ClientResponse> createUserWithPasswordHash(String username, char[] passwordHash, List<String> tags) {
    if(username == null) {
        throw new IllegalArgumentException("username cannot be null");
    }
    // passwordless authentication is a thing. See
    // https://github.com/rabbitmq/hop/issues/94 and https://www.rabbitmq.com/authentication.html. MK.
    if(passwordHash == null) {
        passwordHash = "".toCharArray();
    }
    Map<String, Object> body = new HashMap<String, Object>();
    body.put("password_hash", String.valueOf(passwordHash));
    body.put("tags", StringUtils.collectionToCommaDelimitedString(tags));

    return client
        .put()
        .uri("/users/{username}", username)
        .syncBody(body)
        .exchange();
}
 
开发者ID:rabbitmq,项目名称:hop,代码行数:20,代码来源:ReactiveClient.java


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