Java Code Examples for org.springframework.web.util.UriBuilder

The following examples show how to use org.springframework.web.util.UriBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void supportsParameter() {
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerWebExchange.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpRequest.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpResponse.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(HttpMethod.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Locale.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(TimeZone.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ZoneId.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(UriComponentsBuilder.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(UriBuilder.class)));

	assertFalse(this.resolver.supportsParameter(this.testMethod.arg(WebSession.class)));
	assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
	try {
		this.resolver.supportsParameter(this.testMethod.arg(Mono.class, ServerWebExchange.class));
		fail();
	}
	catch (IllegalStateException ex) {
		assertTrue("Unexpected error message:\n" + ex.getMessage(),
				ex.getMessage().startsWith(
						"ServerWebExchangeMethodArgumentResolver does not support reactive type wrapper"));
	}
}
 
Example 2
@Test
public void supportsParameter() {
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerWebExchange.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpRequest.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ServerHttpResponse.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(HttpMethod.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(Locale.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(TimeZone.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(ZoneId.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(UriComponentsBuilder.class)));
	assertTrue(this.resolver.supportsParameter(this.testMethod.arg(UriBuilder.class)));

	assertFalse(this.resolver.supportsParameter(this.testMethod.arg(WebSession.class)));
	assertFalse(this.resolver.supportsParameter(this.testMethod.arg(String.class)));
	try {
		this.resolver.supportsParameter(this.testMethod.arg(Mono.class, ServerWebExchange.class));
		fail();
	}
	catch (IllegalStateException ex) {
		assertTrue("Unexpected error message:\n" + ex.getMessage(),
				ex.getMessage().startsWith(
						"ServerWebExchangeArgumentResolver doesn't support reactive type wrapper"));
	}
}
 
Example 3
@Override
public boolean supportsParameter(MethodParameter parameter) {
	return checkParameterTypeNoReactiveWrapper(parameter,
			type -> ServerWebExchange.class.isAssignableFrom(type) ||
					ServerHttpRequest.class.isAssignableFrom(type) ||
					ServerHttpResponse.class.isAssignableFrom(type) ||
					HttpMethod.class == type ||
					Locale.class == type ||
					TimeZone.class == type ||
					ZoneId.class == type ||
					UriBuilder.class == type || UriComponentsBuilder.class == type);
}
 
Example 4
@SuppressWarnings("unused")
public void handle(
		ServerWebExchange exchange,
		ServerHttpRequest request,
		ServerHttpResponse response,
		WebSession session,
		HttpMethod httpMethod,
		Locale locale,
		TimeZone timeZone,
		ZoneId zoneId,
		UriComponentsBuilder uriComponentsBuilder,
		UriBuilder uriBuilder,
		String s,
		Mono<ServerWebExchange> monoExchange) {
}
 
Example 5
@Override
public boolean supportsParameter(MethodParameter parameter) {
	return checkParameterTypeNoReactiveWrapper(parameter,
			type -> ServerWebExchange.class.isAssignableFrom(type) ||
					ServerHttpRequest.class.isAssignableFrom(type) ||
					ServerHttpResponse.class.isAssignableFrom(type) ||
					HttpMethod.class == type ||
					Locale.class == type ||
					TimeZone.class == type ||
					ZoneId.class == type ||
					UriBuilder.class == type || UriComponentsBuilder.class == type);
}
 
Example 6
@SuppressWarnings("unused")
public void handle(
		ServerWebExchange exchange,
		ServerHttpRequest request,
		ServerHttpResponse response,
		WebSession session,
		HttpMethod httpMethod,
		Locale locale,
		TimeZone timeZone,
		ZoneId zoneId,
		UriComponentsBuilder uriComponentsBuilder,
		UriBuilder uriBuilder,
		String s,
		Mono<ServerWebExchange> monoExchange) {
}
 
Example 7
Source Project: reactive-ms-example   Source File: BasicIntegrationTest.java    License: MIT License 5 votes vote down vote up
private String get(final Function<UriBuilder, URI> builder, final HttpStatus status) {
    return new String(client.get()
            .uri(builder)
            .accept(TEXT_HTML).exchange()
            .expectStatus().isEqualTo(status)
            .expectHeader().contentType(TEXT_HTML)
            .expectBody().returnResult().getResponseBody());
}
 
Example 8
Source Project: reactive-ms-example   Source File: BasicIntegrationTest.java    License: MIT License 5 votes vote down vote up
protected <T> T get(final Function<UriBuilder, URI> builder, final HttpStatus status, final Class<T> type) {
    return client.get()
            .uri(builder)
            .accept(APPLICATION_JSON_UTF8).exchange()
            .expectStatus().isEqualTo(status)
            .expectHeader().contentType(APPLICATION_JSON_UTF8)
            .expectBody(type)
            .returnResult().getResponseBody();
}
 
Example 9
Source Project: reactive-ms-example   Source File: BasicIntegrationTest.java    License: MIT License 5 votes vote down vote up
protected <T, K> T post(final Function<UriBuilder, URI> builder, final HttpStatus status, final K object, final Class<T> type) {
    return client.post()
            .uri(builder)
            .body(BodyInserters.fromObject(object))
            .accept(APPLICATION_JSON_UTF8).exchange()
            .expectStatus().isEqualTo(status)
            .expectHeader().contentType(APPLICATION_JSON_UTF8)
            .expectBody(type)
            .returnResult().getResponseBody();
}
 
Example 10
Source Project: spring-vault   Source File: VaultClients.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public UriBuilder uriString(String uriTemplate) {

	if (uriTemplate.startsWith("http:") || uriTemplate.startsWith("https:")) {
		return UriComponentsBuilder.fromUriString(uriTemplate);
	}

	VaultEndpoint endpoint = this.endpointProvider.getVaultEndpoint();

	String baseUri = toBaseUri(endpoint);
	UriComponents uriComponents = UriComponentsBuilder.fromUriString(prepareUriTemplate(baseUri, uriTemplate))
			.build();

	return UriComponentsBuilder.fromUriString(baseUri).uriComponents(uriComponents);
}
 
Example 11
Source Project: spring-analysis-note   Source File: DefaultWebClient.java    License: MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(String uriTemplate, Function<UriBuilder, URI> uriFunction) {
	attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
	return uri(uriFunction.apply(uriBuilderFactory.uriString(uriTemplate)));
}
 
Example 12
Source Project: spring-analysis-note   Source File: DefaultWebClient.java    License: MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
	return uri(uriFunction.apply(uriBuilderFactory.builder()));
}
 
Example 13
Source Project: spring-analysis-note   Source File: DefaultServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(uri());
}
 
Example 14
Source Project: spring-analysis-note   Source File: ServerRequestWrapper.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.delegate.uriBuilder();
}
 
Example 15
Source Project: spring-analysis-note   Source File: RequestPredicates.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.request.uriBuilder();
}
 
Example 16
Source Project: spring-analysis-note   Source File: MockServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example 17
Source Project: spring-analysis-note   Source File: DefaultServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return ServletUriComponentsBuilder.fromRequest(servletRequest());
}
 
Example 18
Source Project: spring-analysis-note   Source File: DefaultServerRequestBuilder.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example 19
Source Project: spring-analysis-note   Source File: RequestPredicates.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.request.uriBuilder();
}
 
Example 20
Source Project: spring-analysis-note   Source File: MockServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example 21
Source Project: spring-analysis-note   Source File: DefaultWebTestClient.java    License: MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
	this.bodySpec.uri(uriFunction);
	this.uriTemplate = null;
	return this;
}
 
Example 22
Source Project: java-technology-stack   Source File: DefaultWebClient.java    License: MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
	return uri(uriFunction.apply(uriBuilderFactory.builder()));
}
 
Example 23
Source Project: java-technology-stack   Source File: DefaultServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(uri());
}
 
Example 24
Source Project: java-technology-stack   Source File: ServerRequestWrapper.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.delegate.uriBuilder();
}
 
Example 25
Source Project: java-technology-stack   Source File: RequestPredicates.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.request.uriBuilder();
}
 
Example 26
Source Project: java-technology-stack   Source File: MockServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example 27
Source Project: java-technology-stack   Source File: MockServerRequest.java    License: MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example 28
Source Project: java-technology-stack   Source File: DefaultWebTestClient.java    License: MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
	this.bodySpec.uri(uriFunction);
	this.uriTemplate = null;
	return this;
}
 
Example 29
Source Project: sofa-lookout   Source File: StaticTargetPromScrapeJob.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void scrape(List<JobState> jobStates) {
    for (StaticScrapeConfig.StaticConfigItem item : getConfig().getStaticConfigItemList()) {
        for (String target : item.getTargets()) {
            JobState jobState = new JobState();
            jobStates.add(jobState);
            jobState.setLastScrapedTime(Instant.now());
            long start = System.currentTimeMillis();
            try {
                // String targetUrl = getConfig().getSchema() + "://" + target + getConfig().getMetricsPath();
                UriBuilder uriBuilder = UriComponentsBuilder.newInstance().scheme(getConfig().getSchema()).host(target).path(getConfig().getMetricsPath());

                //add params
                if (getConfig().getParams() != null) {
                    for (Map.Entry<String, List<String>> entry : getConfig().getParams().entrySet()) {
                        uriBuilder.queryParam(entry.getKey(), entry.getValue().toArray());

                    }
                }
                String targetUrl = ((UriComponentsBuilder) uriBuilder).build().toUriString();
                Request request = new Request.Builder().url(targetUrl).header("User-Agent", "lookout-gateway").build();
                jobState.setEndpoint(targetUrl);
                Call call = client.newCall(request);
                Response response = call.execute();
                Map<String, List<String>> headers = response.headers().toMultimap();
                headers.put("target", Lists.newArrayList(target));
                if (consumer != null)
                    consumer.accept(new ScrapeResult<>(response.body().bytes(), headers, getConfig()));
                jobState.setSuccessful(true);
            } catch (Throwable e) {
                jobState.setSuccessful(false);
                jobState.setError(e.getMessage());
                log.warn("scrape fail!" + e.getMessage());
            } finally {
                jobState.setDuration(Duration.ofMillis(System.currentTimeMillis() - start));
                //最近一次拉取的状态记录
                LogUtils.SCRAPE_DIGEST_LOGGER
                        .info("|{}|{}|{}|{}|", jobState.getEndpoint(), getJobName(), jobState.isSuccessful() ? "T" : "F", jobState
                                .getDuration().toMillis());
            }

        }

    }
}
 
Example 30
Source Project: reactive-ms-example   Source File: BasicIntegrationTest.java    License: MIT License 4 votes vote down vote up
protected String get(final Function<UriBuilder, URI> builder) {
    return get(builder, HttpStatus.OK);
}