org.springframework.web.util.UriBuilder Java Examples

The following examples show how to use org.springframework.web.util.UriBuilder. 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
Source File: ServerWebExchangeArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #2
Source File: ServerWebExchangeMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #3
Source File: VaultClients.java    From spring-vault with 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 #4
Source File: ServerWebExchangeArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #5
Source File: ServerWebExchangeArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #6
Source File: ServerWebExchangeMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 File: ServerWebExchangeMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 #8
Source File: BasicIntegrationTest.java    From reactive-ms-example with 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 #9
Source File: BasicIntegrationTest.java    From reactive-ms-example with 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 #10
Source File: BasicIntegrationTest.java    From reactive-ms-example with 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 #11
Source File: BasicIntegrationTest.java    From reactive-ms-example with MIT License 4 votes vote down vote up
protected String get(final Function<UriBuilder, URI> builder) {
    return get(builder, HttpStatus.OK);
}
 
Example #12
Source File: BasicIntegrationTest.java    From reactive-ms-example with MIT License 4 votes vote down vote up
protected <T> T get(final Function<UriBuilder, URI> builder, final Class<T> type) {
    return get(builder, HttpStatus.OK, type);
}
 
Example #13
Source File: StaticTargetPromScrapeJob.java    From sofa-lookout with 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 #14
Source File: DefaultWebTestClient.java    From java-technology-stack with 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 #15
Source File: MockServerRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example #16
Source File: BasicIntegrationTest.java    From reactive-ms-example with MIT License 4 votes vote down vote up
protected <T, K> T post(final Function<UriBuilder, URI> builder, final K object, final Class<T> type) {
    return post(builder, HttpStatus.OK, object, type);
}
 
Example #17
Source File: MockServerRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example #18
Source File: DefaultWebClient.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
	return uri(uriFunction.apply(uriBuilderFactory.builder()));
}
 
Example #19
Source File: RequestPredicates.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.request.uriBuilder();
}
 
Example #20
Source File: ServerRequestWrapper.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.delegate.uriBuilder();
}
 
Example #21
Source File: DefaultWebClient.java    From spring-analysis-note with 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 #22
Source File: DefaultWebClient.java    From java-technology-stack with 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 File: DefaultServerRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(uri());
}
 
Example #24
Source File: DefaultWebTestClient.java    From spring-analysis-note with 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 #25
Source File: MockServerRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example #26
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return this.request.uriBuilder();
}
 
Example #27
Source File: DefaultServerRequestBuilder.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}
 
Example #28
Source File: DefaultServerRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(uri());
}
 
Example #29
Source File: DefaultServerRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return ServletUriComponentsBuilder.fromRequest(servletRequest());
}
 
Example #30
Source File: MockServerRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public UriBuilder uriBuilder() {
	return UriComponentsBuilder.fromUri(this.uri);
}