From 0385894d342fc43dc26a3cbf08d439b7cd6d9ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E5=AD=90=20Yang?= Date: Thu, 9 Jan 2025 22:01:14 +0800 Subject: [PATCH] :art: UriComponentsBuilder API --- .../method/MvcUriComponentsBuilderTests.java | 28 +- .../web/util/ForwardedHeaderUtilsTests.java | 4 +- .../reactive/MockClientHttpRequest.java | 4 +- .../reactive/MockServerHttpRequest.java | 8 +- .../client/match/MockRestRequestMatchers.java | 6 +- .../mock/request/MockHttpRequestBuilder.java | 8 +- .../mock/result/MockMvcResultMatchers.java | 8 +- .../reactive/MockServerHttpRequestTests.java | 2 +- .../response/DefaultResponseCreatorTests.java | 4 +- .../request/MockHttpRequestBuilderTests.java | 4 +- .../web/mock/samples/spr/EncodedUriTests.java | 4 +- .../web/AbstractRedirectModelManager.java | 4 +- .../main/java/infra/web/RequestContext.java | 4 +- .../java/infra/web/RequestContextUtils.java | 2 +- ...UriComponentsBuilderParameterStrategy.java | 6 +- .../web/client/DefaultRestClientBuilder.java | 4 +- .../client/config/RootUriBuilderFactory.java | 6 +- .../reactive/DefaultWebClientBuilder.java | 4 +- .../function/DefaultServerRequest.java | 4 +- .../function/DefaultServerRequestBuilder.java | 4 +- .../method/MvcUriComponentsBuilder.java | 10 +- .../service/invoker/HttpRequestValues.java | 8 +- .../web/util/AbstractUriTemplateHandler.java | 2 +- .../web/util/DefaultUriBuilderFactory.java | 14 +- .../web/util/DefaultUriTemplateHandler.java | 2 +- .../infra/web/util/ForwardedHeaderUtils.java | 4 +- .../web/util/HierarchicalUriComponents.java | 4 +- .../infra/web/util/OpaqueUriComponents.java | 4 +- .../main/java/infra/web/util/UriBuilder.java | 16 +- .../java/infra/web/util/UriComponents.java | 11 +- .../infra/web/util/UriComponentsBuilder.java | 60 +++-- .../main/java/infra/web/util/UriTemplate.java | 8 +- .../main/java/infra/web/util/WebUtils.java | 4 +- .../java/infra/http/RequestEntityTests.java | 8 +- .../invoker/HttpRequestValuesTests.java | 2 +- .../RequestParamArgumentResolverTests.java | 2 +- .../web/util/UriComponentsBuilderTests.java | 242 +++++++++--------- .../infra/web/util/UriComponentsTests.java | 90 +++---- .../http/MockClientHttpRequest.java | 4 +- .../reactive/MockClientHttpRequest.java | 4 +- .../reactive/MockServerHttpRequest.java | 8 +- .../client/ConnectionManagerSupport.java | 6 +- .../web/socket/client/WebSocketClient.java | 6 +- 43 files changed, 324 insertions(+), 313 deletions(-) diff --git a/integration-tests/src/test/java/infra/web/handler/method/MvcUriComponentsBuilderTests.java b/integration-tests/src/test/java/infra/web/handler/method/MvcUriComponentsBuilderTests.java index 56c6d0d7d1..4776243909 100755 --- a/integration-tests/src/test/java/infra/web/handler/method/MvcUriComponentsBuilderTests.java +++ b/integration-tests/src/test/java/infra/web/handler/method/MvcUriComponentsBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -120,7 +120,7 @@ public void fromControllerNotMapped() { @Test public void fromControllerWithCustomBaseURIViaStaticCall() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); UriComponents uriComponents = fromController(builder, PersonControllerImpl.class).build(); assertThat(uriComponents.toString()).isEqualTo("https://example.org:9090/base/people"); @@ -129,7 +129,7 @@ public void fromControllerWithCustomBaseURIViaStaticCall() { @Test public void fromControllerWithCustomBaseURIViaInstance() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents uriComponents = mvcBuilder.withController(PersonControllerImpl.class).build(); @@ -202,7 +202,7 @@ public void fromMethodNameInUnmappedControllerMethod() { @Test public void fromMethodNameWithCustomBaseURIViaStaticCall() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); UriComponents uriComponents = fromMethodName(builder, ControllerWithMethods.class, "methodWithPathVariable", "1").build(); @@ -212,7 +212,7 @@ public void fromMethodNameWithCustomBaseURIViaStaticCall() { @Test public void fromMethodNameWithCustomBaseURIViaInstance() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents uriComponents = mvcBuilder.withMethodName(ControllerWithMethods.class, "methodWithPathVariable", "1").build(); @@ -328,7 +328,7 @@ public void fromMethodCallWithPathVariableAndMultiValueRequestParams() { @Test public void fromMethodCallWithCustomBaseURIViaStaticCall() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build(); assertThat(uriComponents.toString()).isEqualTo("https://example.org:9090/base/something/else"); @@ -337,7 +337,7 @@ public void fromMethodCallWithCustomBaseURIViaStaticCall() { @Test public void fromMethodCallWithCustomBaseURIViaInstance() { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents result = mvcBuilder.withMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); @@ -350,7 +350,7 @@ public void fromMethodCallWithModelAndViewReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithModelAndView.class).getBooking(21L)).buildAndExpand(42); - assertThat(uriComponents.encode().toUri().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); + assertThat(uriComponents.encode().toURI().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); } @Test @@ -358,7 +358,7 @@ public void fromMethodCallWithObjectReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithObject.class).getBooking(21L)).buildAndExpand(42); - assertThat(uriComponents.encode().toUri().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); + assertThat(uriComponents.encode().toURI().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); } @Test @@ -366,7 +366,7 @@ public void fromMethodCallWithStringReturnType() { assertThatIllegalStateException().isThrownBy(() -> { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithString.class).getBooking(21L)).buildAndExpand(42); - uriComponents.encode().toUri().toString(); + uriComponents.encode().toURI().toString(); }); } @@ -375,7 +375,7 @@ public void fromMethodNameWithStringReturnType() { UriComponents uriComponents = fromMethodName( BookingControllerWithString.class, "getBooking", 21L).buildAndExpand(42); - assertThat(uriComponents.encode().toUri().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); + assertThat(uriComponents.encode().toURI().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); } @Test // gh-30210 @@ -384,7 +384,7 @@ public void fromMethodCallWithCharSequenceReturnType() { on(BookingControllerWithCharSequence.class).getBooking(21L)) .buildAndExpand(42); - assertThat(uriComponents.encode().toUri().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); + assertThat(uriComponents.encode().toURI().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); } @Test // gh-30210 @@ -392,7 +392,7 @@ public void fromMethodCallWithJdbc30115ReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithJdbcSavepoint.class).getBooking(21L)).buildAndExpand(42); - assertThat(uriComponents.encode().toUri().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); + assertThat(uriComponents.encode().toURI().toString()).isEqualTo("http://localhost/hotels/42/bookings/21"); } @Test @@ -411,7 +411,7 @@ public void fromMappingNamePlain() { public void fromMappingNameWithCustomBaseURI() { initWebApplicationContext(WebConfig.class); - UriComponentsBuilder baseUrl = UriComponentsBuilder.fromUriString("https://example.org:9999/base"); + UriComponentsBuilder baseUrl = UriComponentsBuilder.forURIString("https://example.org:9999/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(baseUrl); String url = mvcBuilder.withMappingName("PAC#getAddressesForCountry").arg(0, "DE").buildAndExpand(123); assertThat(url).isEqualTo("https://example.org:9999/base/people/123/addresses/DE"); diff --git a/integration-tests/src/test/java/infra/web/util/ForwardedHeaderUtilsTests.java b/integration-tests/src/test/java/infra/web/util/ForwardedHeaderUtilsTests.java index 1340cef9de..d04a5c60ec 100755 --- a/integration-tests/src/test/java/infra/web/util/ForwardedHeaderUtilsTests.java +++ b/integration-tests/src/test/java/infra/web/util/ForwardedHeaderUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -361,7 +361,7 @@ public HttpMethod getMethod() { @Override public URI getURI() { - return UriComponentsBuilder.fromUriString("/").build().toUri(); + return UriComponentsBuilder.forURIString("/").build().toURI(); } @Override diff --git a/today-test/src/main/java/infra/mock/http/client/reactive/MockClientHttpRequest.java b/today-test/src/main/java/infra/mock/http/client/reactive/MockClientHttpRequest.java index 3cfbfe5aaf..c20ac6e52f 100644 --- a/today-test/src/main/java/infra/mock/http/client/reactive/MockClientHttpRequest.java +++ b/today-test/src/main/java/infra/mock/http/client/reactive/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,7 +60,7 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest { private Function, Mono> writeHandler; public MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars) { - this(httpMethod, UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(vars).encode().toUri()); + this(httpMethod, UriComponentsBuilder.forURIString(urlTemplate).buildAndExpand(vars).encode().toURI()); } public MockClientHttpRequest(HttpMethod httpMethod, URI url) { diff --git a/today-test/src/main/java/infra/mock/http/server/reactive/MockServerHttpRequest.java b/today-test/src/main/java/infra/mock/http/server/reactive/MockServerHttpRequest.java index a26c30a5d3..8cb6e804df 100644 --- a/today-test/src/main/java/infra/mock/http/server/reactive/MockServerHttpRequest.java +++ b/today-test/src/main/java/infra/mock/http/server/reactive/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -249,7 +249,7 @@ public static BodyBuilder method(String httpMethod, String uri, Object... vars) } private static URI toUri(String uri, Object[] vars) { - return UriComponentsBuilder.fromUriString(uri).buildAndExpand(vars).encode().toUri(); + return UriComponentsBuilder.forURIString(uri).buildAndExpand(vars).encode().toURI(); } /** @@ -453,7 +453,7 @@ private static class DefaultBodyBuilder implements BodyBuilder { @Nullable private String contextPath; - private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); + private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.create(); private final HttpHeaders headers = HttpHeaders.forWritable(); @@ -623,7 +623,7 @@ private URI getUrlToUse() { MultiValueMap params = this.queryParamsBuilder.buildAndExpand().encode().getQueryParams(); if (!params.isEmpty()) { - return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri(); + return UriComponentsBuilder.forURI(this.url).queryParams(params).build(true).toURI(); } return this.url; } diff --git a/today-test/src/main/java/infra/test/web/client/match/MockRestRequestMatchers.java b/today-test/src/main/java/infra/test/web/client/match/MockRestRequestMatchers.java index b4d55de414..b6862fe198 100644 --- a/today-test/src/main/java/infra/test/web/client/match/MockRestRequestMatchers.java +++ b/today-test/src/main/java/infra/test/web/client/match/MockRestRequestMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -103,7 +103,7 @@ public static RequestMatcher requestTo(String expectedUri) { */ public static RequestMatcher requestToUriTemplate(String expectedUri, Object... uriVars) { Assert.notNull(expectedUri, "'uri' is required"); - URI uri = UriComponentsBuilder.fromUriString(expectedUri).buildAndExpand(uriVars).encode().toUri(); + URI uri = UriComponentsBuilder.forURIString(expectedUri).buildAndExpand(uriVars).encode().toURI(); return requestTo(uri); } @@ -146,7 +146,7 @@ public static RequestMatcher queryParam(String name, String... expectedValues) { } private static MultiValueMap getQueryParams(ClientHttpRequest request) { - return UriComponentsBuilder.fromUri(request.getURI()).build().getQueryParams(); + return UriComponentsBuilder.forURI(request.getURI()).build().getQueryParams(); } private static void assertValueCount( diff --git a/today-test/src/main/java/infra/test/web/mock/request/MockHttpRequestBuilder.java b/today-test/src/main/java/infra/test/web/mock/request/MockHttpRequestBuilder.java index 9beec1cde1..c1b02e4848 100644 --- a/today-test/src/main/java/infra/test/web/mock/request/MockHttpRequestBuilder.java +++ b/today-test/src/main/java/infra/test/web/mock/request/MockHttpRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -146,7 +146,7 @@ private static URI initUri(String url, Object[] vars) { Assert.isTrue(url.isEmpty() || url.startsWith("/") || url.startsWith("http://") || url.startsWith("https://"), () -> "'url' should start with a path or be a complete HTTP URL: " + url); String uriString = (url.isEmpty() ? "/" : url); - return UriComponentsBuilder.fromUriString(uriString).buildAndExpand(vars).encode().toUri(); + return UriComponentsBuilder.forURIString(uriString).buildAndExpand(vars).encode().toURI(); } /** @@ -706,13 +706,13 @@ public final HttpMockRequestImpl buildRequest(MockContext mockContext) { String query = this.url.getRawQuery(); if (!this.queryParams.isEmpty()) { - String str = UriComponentsBuilder.newInstance().queryParams(this.queryParams).build().encode().getQuery(); + String str = UriComponentsBuilder.create().queryParams(this.queryParams).build().encode().getQuery(); query = StringUtils.isNotEmpty(query) ? (query + "&" + str) : str; } if (query != null) { request.setQueryString(query); } - addRequestParams(request, UriComponentsBuilder.fromUri(this.url).build().getQueryParams()); + addRequestParams(request, UriComponentsBuilder.forURI(this.url).build().getQueryParams()); this.parameters.forEach((name, values) -> { for (String value : values) { diff --git a/today-test/src/main/java/infra/test/web/mock/result/MockMvcResultMatchers.java b/today-test/src/main/java/infra/test/web/mock/result/MockMvcResultMatchers.java index 99056f7e1b..2cc0cc8974 100644 --- a/today-test/src/main/java/infra/test/web/mock/result/MockMvcResultMatchers.java +++ b/today-test/src/main/java/infra/test/web/mock/result/MockMvcResultMatchers.java @@ -98,10 +98,10 @@ public static ResultMatcher forwardedUrl(@Nullable String expectedUrl) { * * @param urlTemplate a URL template; the expanded URL will be encoded * @param uriVars zero or more URI variables to populate the template - * @see UriComponentsBuilder#fromUriString(String) + * @see UriComponentsBuilder#forURIString(String) */ public static ResultMatcher forwardedUrlTemplate(String urlTemplate, Object... uriVars) { - String uri = UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); + String uri = UriComponentsBuilder.forURIString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); return forwardedUrl(uri); } @@ -139,10 +139,10 @@ public static ResultMatcher redirectedUrl(String expectedUrl) { * * @param urlTemplate a URL template; the expanded URL will be encoded * @param uriVars zero or more URI variables to populate the template - * @see UriComponentsBuilder#fromUriString(String) + * @see UriComponentsBuilder#forURIString(String) */ public static ResultMatcher redirectedUrlTemplate(String urlTemplate, Object... uriVars) { - String uri = UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); + String uri = UriComponentsBuilder.forURIString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); return redirectedUrl(uri); } diff --git a/today-test/src/test/java/infra/mock/http/server/reactive/MockServerHttpRequestTests.java b/today-test/src/test/java/infra/mock/http/server/reactive/MockServerHttpRequestTests.java index 3874e32716..074b604faf 100644 --- a/today-test/src/test/java/infra/mock/http/server/reactive/MockServerHttpRequestTests.java +++ b/today-test/src/test/java/infra/mock/http/server/reactive/MockServerHttpRequestTests.java @@ -78,7 +78,7 @@ void httpMethodNotNullOrEmpty(ThrowingCallable callable) { static Stream> httpMethodNotNullOrEmpty() { String uriTemplate = "/foo bar?a=b"; return Stream.of( - named("null HttpMethod, URI", () -> MockServerHttpRequest.method(null, UriComponentsBuilder.fromUriString(uriTemplate).build("")).build()), + named("null HttpMethod, URI", () -> MockServerHttpRequest.method(null, UriComponentsBuilder.forURIString(uriTemplate).build("")).build()), named("null HttpMethod, uriTemplate", () -> MockServerHttpRequest.method((HttpMethod) null, uriTemplate).build()), named("null String, uriTemplate", () -> MockServerHttpRequest.method((String) null, uriTemplate).build()), named("empty String, uriTemplate", () -> MockServerHttpRequest.method("", uriTemplate).build()), diff --git a/today-test/src/test/java/infra/test/web/client/response/DefaultResponseCreatorTests.java b/today-test/src/test/java/infra/test/web/client/response/DefaultResponseCreatorTests.java index f904abfd84..7d35a37f02 100644 --- a/today-test/src/test/java/infra/test/web/client/response/DefaultResponseCreatorTests.java +++ b/today-test/src/test/java/infra/test/web/client/response/DefaultResponseCreatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -219,7 +219,7 @@ void setCookies() throws IOException { } private static ClientHttpResponse createResponse(DefaultResponseCreator creator) throws IOException { - URI uri = UriComponentsBuilder.fromUriString("/foo/bar").build().toUri(); + URI uri = UriComponentsBuilder.forURIString("/foo/bar").build().toURI(); return creator.createResponse(new MockClientHttpRequest(HttpMethod.POST, uri)); } diff --git a/today-test/src/test/java/infra/test/web/mock/request/MockHttpRequestBuilderTests.java b/today-test/src/test/java/infra/test/web/mock/request/MockHttpRequestBuilderTests.java index 41a7e1c773..dbc0164907 100644 --- a/today-test/src/test/java/infra/test/web/mock/request/MockHttpRequestBuilderTests.java +++ b/today-test/src/test/java/infra/test/web/mock/request/MockHttpRequestBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -541,7 +541,7 @@ void mergeInvokesDefaultRequestPostProcessorFirst() { void arbitraryMethod() { String httpMethod = "REPort"; - URI url = UriComponentsBuilder.fromPath("/foo/{bar}").buildAndExpand(42).toUri(); + URI url = UriComponentsBuilder.forPath("/foo/{bar}").buildAndExpand(42).toURI(); this.builder = new MockHttpRequestBuilder(httpMethod, url); HttpMockRequestImpl request = this.builder.buildRequest(this.mockContext); diff --git a/today-test/src/test/java/infra/test/web/mock/samples/spr/EncodedUriTests.java b/today-test/src/test/java/infra/test/web/mock/samples/spr/EncodedUriTests.java index 3866fe1eb9..0f8123b4af 100644 --- a/today-test/src/test/java/infra/test/web/mock/samples/spr/EncodedUriTests.java +++ b/today-test/src/test/java/infra/test/web/mock/samples/spr/EncodedUriTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,7 +75,7 @@ public void setup() { @Test public void test() throws Exception { String id = "a/b"; - URI url = UriComponentsBuilder.fromUriString("/circuit").pathSegment(id).build().encode().toUri(); + URI url = UriComponentsBuilder.forURIString("/circuit").pathSegment(id).build().encode().toURI(); ResultActions result = mockMvc.perform(get(url)); result.andExpect(status().isOk()) .andExpect(model().attribute("receivedId", is(id))); diff --git a/today-web/src/main/java/infra/web/AbstractRedirectModelManager.java b/today-web/src/main/java/infra/web/AbstractRedirectModelManager.java index f495a569c2..531d5347eb 100755 --- a/today-web/src/main/java/infra/web/AbstractRedirectModelManager.java +++ b/today-web/src/main/java/infra/web/AbstractRedirectModelManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -165,7 +165,7 @@ protected boolean isRedirectModelForRequest(RedirectModel model, RequestContext private MultiValueMap getOriginatingRequestParams(RequestContext request) { String query = request.getQueryString(); - return UriComponentsBuilder.fromPath("/").query(query).build().getQueryParams(); + return UriComponentsBuilder.forPath("/").query(query).build().getQueryParams(); } @Override diff --git a/today-web/src/main/java/infra/web/RequestContext.java b/today-web/src/main/java/infra/web/RequestContext.java index 689620a245..95e6f3a6bc 100755 --- a/today-web/src/main/java/infra/web/RequestContext.java +++ b/today-web/src/main/java/infra/web/RequestContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -946,7 +946,7 @@ public boolean isCorsRequest() { corsRequestFlag = false; } else { - UriComponents originUrl = UriComponentsBuilder.fromOriginHeader(origin).build(); + UriComponents originUrl = UriComponentsBuilder.forOriginHeader(origin).build(); String scheme = getScheme(); String host = getServerName(); int port = getServerPort(); diff --git a/today-web/src/main/java/infra/web/RequestContextUtils.java b/today-web/src/main/java/infra/web/RequestContextUtils.java index 62a46dea92..c22623bf4f 100755 --- a/today-web/src/main/java/infra/web/RequestContextUtils.java +++ b/today-web/src/main/java/infra/web/RequestContextUtils.java @@ -297,7 +297,7 @@ public static void saveRedirectModel( manager = getRedirectModelManager(request); } if (manager != null) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString(location).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString(location).build(); redirectModel.setTargetRequestPath(uriComponents.getPath()); redirectModel.addTargetRequestParams(uriComponents.getQueryParams()); diff --git a/today-web/src/main/java/infra/web/bind/resolver/UriComponentsBuilderParameterStrategy.java b/today-web/src/main/java/infra/web/bind/resolver/UriComponentsBuilderParameterStrategy.java index 9f277a4d47..22fefbcb05 100755 --- a/today-web/src/main/java/infra/web/bind/resolver/UriComponentsBuilderParameterStrategy.java +++ b/today-web/src/main/java/infra/web/bind/resolver/UriComponentsBuilderParameterStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ * Resolvers argument values of type {@link UriComponentsBuilder}. * *

The returned instance is initialized via - * {@link UriComponentsBuilder#fromHttpRequest(HttpRequest)} + * {@link UriComponentsBuilder#forHttpRequest(HttpRequest)} * * @author Rossen Stoyanchev * @author Harry Yang @@ -43,7 +43,7 @@ public boolean supportsParameter(ResolvableMethodParameter resolvable) { @Nullable @Override public Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable { - return UriComponentsBuilder.fromHttpRequest(context); + return UriComponentsBuilder.forHttpRequest(context); } } diff --git a/today-web/src/main/java/infra/web/client/DefaultRestClientBuilder.java b/today-web/src/main/java/infra/web/client/DefaultRestClientBuilder.java index 1388ccdd00..1c404ada65 100755 --- a/today-web/src/main/java/infra/web/client/DefaultRestClientBuilder.java +++ b/today-web/src/main/java/infra/web/client/DefaultRestClientBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -475,7 +475,7 @@ private UriBuilderFactory initUriBuilderFactory() { } DefaultUriBuilderFactory factory = this.baseURI != null - ? new DefaultUriBuilderFactory(UriComponentsBuilder.fromUri(baseURI)) + ? new DefaultUriBuilderFactory(UriComponentsBuilder.forURI(baseURI)) : new DefaultUriBuilderFactory(); factory.setDefaultUriVariables(this.defaultUriVariables); return factory; diff --git a/today-web/src/main/java/infra/web/client/config/RootUriBuilderFactory.java b/today-web/src/main/java/infra/web/client/config/RootUriBuilderFactory.java index fcc704ca4b..048b922f11 100644 --- a/today-web/src/main/java/infra/web/client/config/RootUriBuilderFactory.java +++ b/today-web/src/main/java/infra/web/client/config/RootUriBuilderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,12 +43,12 @@ public class RootUriBuilderFactory extends RootUriTemplateHandler implements Uri @Override public UriBuilder uriString(String uriTemplate) { - return UriComponentsBuilder.fromUriString(apply(uriTemplate)); + return UriComponentsBuilder.forURIString(apply(uriTemplate)); } @Override public UriBuilder builder() { - return UriComponentsBuilder.newInstance(); + return UriComponentsBuilder.create(); } /** diff --git a/today-web/src/main/java/infra/web/client/reactive/DefaultWebClientBuilder.java b/today-web/src/main/java/infra/web/client/reactive/DefaultWebClientBuilder.java index 9f353667e6..28fa3bc631 100755 --- a/today-web/src/main/java/infra/web/client/reactive/DefaultWebClientBuilder.java +++ b/today-web/src/main/java/infra/web/client/reactive/DefaultWebClientBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -364,7 +364,7 @@ private UriBuilderFactory initUriBuilderFactory() { } DefaultUriBuilderFactory factory = baseURI != null - ? new DefaultUriBuilderFactory(UriComponentsBuilder.fromUri(baseURI)) + ? new DefaultUriBuilderFactory(UriComponentsBuilder.forURI(baseURI)) : new DefaultUriBuilderFactory(); factory.setDefaultUriVariables(this.defaultUriVariables); return factory; diff --git a/today-web/src/main/java/infra/web/handler/function/DefaultServerRequest.java b/today-web/src/main/java/infra/web/handler/function/DefaultServerRequest.java index 51ee5b55ca..117520ddf8 100755 --- a/today-web/src/main/java/infra/web/handler/function/DefaultServerRequest.java +++ b/today-web/src/main/java/infra/web/handler/function/DefaultServerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -113,7 +113,7 @@ public URI uri() { @Override public UriBuilder uriBuilder() { - return UriComponentsBuilder.fromHttpRequest(requestContext); + return UriComponentsBuilder.forHttpRequest(requestContext); } @Override diff --git a/today-web/src/main/java/infra/web/handler/function/DefaultServerRequestBuilder.java b/today-web/src/main/java/infra/web/handler/function/DefaultServerRequestBuilder.java index f54b8eb5f2..e0f573e46d 100755 --- a/today-web/src/main/java/infra/web/handler/function/DefaultServerRequestBuilder.java +++ b/today-web/src/main/java/infra/web/handler/function/DefaultServerRequestBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -253,7 +253,7 @@ public URI uri() { @Override public UriBuilder uriBuilder() { - return UriComponentsBuilder.fromUri(this.uri); + return UriComponentsBuilder.forURI(this.uri); } @Override diff --git a/today-web/src/main/java/infra/web/handler/method/MvcUriComponentsBuilder.java b/today-web/src/main/java/infra/web/handler/method/MvcUriComponentsBuilder.java index 52be89154c..280091c921 100755 --- a/today-web/src/main/java/infra/web/handler/method/MvcUriComponentsBuilder.java +++ b/today-web/src/main/java/infra/web/handler/method/MvcUriComponentsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +67,7 @@ *

    *
  • Static {@code fromXxx(...)} methods to prepare links using information * from the current request as determined by a call to - * {@link infra.web.util.UriComponentsBuilder#fromCurrentRequest()}. + * {@link infra.web.util.UriComponentsBuilder#forCurrentRequest()}. *
  • Static {@code fromXxx(UriComponentsBuilder,...)} methods can be given * a baseUrl when operating outside the context of a request. *
  • Instance-based {@code withXxx(...)} methods where an instance of @@ -540,7 +540,7 @@ private static UriComponentsBuilder fromMethodInternal( private static UriComponentsBuilder getBaseUrlToUse(@Nullable UriComponentsBuilder baseUrl) { return baseUrl == null ? - UriComponentsBuilder.fromHttpRequest(RequestContextHolder.getRequired()) : + UriComponentsBuilder.forHttpRequest(RequestContextHolder.getRequired()) : baseUrl.cloneBuilder(); } @@ -839,7 +839,7 @@ public MethodArgumentBuilder(Class controllerType, Method method) { public MethodArgumentBuilder(@Nullable UriComponentsBuilder baseUrl, Class controllerType, Method method) { Assert.notNull(controllerType, "'controllerType' is required"); Assert.notNull(method, "'method' is required"); - this.baseUrl = baseUrl != null ? baseUrl : UriComponentsBuilder.fromPath(getPath()); + this.baseUrl = baseUrl != null ? baseUrl : UriComponentsBuilder.forPath(getPath()); this.controllerType = controllerType; this.method = method; this.argumentValues = new Object[method.getParameterCount()]; @@ -847,7 +847,7 @@ public MethodArgumentBuilder(@Nullable UriComponentsBuilder baseUrl, Class co @Deprecated private static String getPath() { - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpRequest(RequestContextHolder.get()); + UriComponentsBuilder builder = UriComponentsBuilder.forHttpRequest(RequestContextHolder.get()); String path = builder.build().getPath(); return path != null ? path : ""; } diff --git a/today-web/src/main/java/infra/web/service/invoker/HttpRequestValues.java b/today-web/src/main/java/infra/web/service/invoker/HttpRequestValues.java index 16b84f902d..ecf62c9de9 100755 --- a/today-web/src/main/java/infra/web/service/invoker/HttpRequestValues.java +++ b/today-web/src/main/java/infra/web/service/invoker/HttpRequestValues.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -436,10 +436,10 @@ public HttpRequestValues build() { } else if (uri != null) { // insert into prepared URI - uri = UriComponentsBuilder.fromUri(uri) + uri = UriComponentsBuilder.forURI(uri) .queryParams(UriUtils.encodeQueryParams(this.requestParams)) .build(true) - .toUri(); + .toURI(); } else { // append to URI template @@ -483,7 +483,7 @@ private boolean hasFormDataContentType() { } private String appendQueryParams(String uriTemplate, Map uriVars, MultiValueMap requestParams) { - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uriTemplate); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.forURIString(uriTemplate); int i = 0; for (Map.Entry> entry : requestParams.entrySet()) { String nameVar = "queryParam" + i; diff --git a/today-web/src/main/java/infra/web/util/AbstractUriTemplateHandler.java b/today-web/src/main/java/infra/web/util/AbstractUriTemplateHandler.java index fa47a975bf..d8fa0235cf 100755 --- a/today-web/src/main/java/infra/web/util/AbstractUriTemplateHandler.java +++ b/today-web/src/main/java/infra/web/util/AbstractUriTemplateHandler.java @@ -56,7 +56,7 @@ public abstract class AbstractUriTemplateHandler implements UriTemplateHandler { */ public void setBaseUrl(@Nullable String baseUrl) { if (baseUrl != null) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString(baseUrl).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString(baseUrl).build(); Assert.hasText(uriComponents.getScheme(), "'baseUrl' must have a scheme"); Assert.hasText(uriComponents.getHost(), "'baseUrl' must have a host"); Assert.isNull(uriComponents.getQuery(), "'baseUrl' cannot have a query"); diff --git a/today-web/src/main/java/infra/web/util/DefaultUriBuilderFactory.java b/today-web/src/main/java/infra/web/util/DefaultUriBuilderFactory.java index 8d798186bc..7eb4708d4f 100755 --- a/today-web/src/main/java/infra/web/util/DefaultUriBuilderFactory.java +++ b/today-web/src/main/java/infra/web/util/DefaultUriBuilderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,7 +68,7 @@ public DefaultUriBuilderFactory() { /** * Constructor with a base URI. *

    The given URI template is parsed via - * {@link UriComponentsBuilder#fromUriString} and then applied as a base URI + * {@link UriComponentsBuilder#forURIString} and then applied as a base URI * to every UriBuilder via {@link UriComponentsBuilder#uriComponents} unless * the UriBuilder itself was created with a URI template that already has a * target address. @@ -76,7 +76,7 @@ public DefaultUriBuilderFactory() { * @param baseUriTemplate the URI template to use a base URL */ public DefaultUriBuilderFactory(String baseUriTemplate) { - this.baseUri = UriComponentsBuilder.fromUriString(baseUriTemplate); + this.baseUri = UriComponentsBuilder.forURIString(baseUriTemplate); } /** @@ -103,7 +103,7 @@ public final boolean hasBaseUri() { * * @param parserType the parser type * @see UriComponentsBuilder.ParserType - * @see UriComponentsBuilder#fromUriString(String, UriComponentsBuilder.ParserType) + * @see UriComponentsBuilder#forURIString(String, UriComponentsBuilder.ParserType) * @since 5.0 */ public void setParserType(UriComponentsBuilder.ParserType parserType) { @@ -293,7 +293,7 @@ public DefaultUriBuilder(String uriTemplate) { private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) { UriComponentsBuilder result; if (StringUtils.isEmpty(uriTemplate)) { - result = (baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance()); + result = (baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.create()); } else if (baseUri != null) { UriComponentsBuilder builder = parseUri(uriTemplate); @@ -312,8 +312,8 @@ else if (baseUri != null) { private UriComponentsBuilder parseUri(String uriTemplate) { return (getParserType() != null ? - UriComponentsBuilder.fromUriString(uriTemplate, getParserType()) : - UriComponentsBuilder.fromUriString(uriTemplate)); + UriComponentsBuilder.forURIString(uriTemplate, getParserType()) : + UriComponentsBuilder.forURIString(uriTemplate)); } private void parsePathIfNecessary(UriComponentsBuilder result) { diff --git a/today-web/src/main/java/infra/web/util/DefaultUriTemplateHandler.java b/today-web/src/main/java/infra/web/util/DefaultUriTemplateHandler.java index 5acc4505e9..53e8098c72 100755 --- a/today-web/src/main/java/infra/web/util/DefaultUriTemplateHandler.java +++ b/today-web/src/main/java/infra/web/util/DefaultUriTemplateHandler.java @@ -110,7 +110,7 @@ protected URI expandInternal(String uriTemplate, Object... uriVariables) { * on whether {@link #setParsePath parsePath} is enabled. */ protected UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString(uriTemplate); if (shouldParsePath() && !isStrictEncoding()) { List pathSegments = builder.build().getPathSegments(); builder.replacePath(null); diff --git a/today-web/src/main/java/infra/web/util/ForwardedHeaderUtils.java b/today-web/src/main/java/infra/web/util/ForwardedHeaderUtils.java index dc34ee8f7d..50abfa4d6d 100755 --- a/today-web/src/main/java/infra/web/util/ForwardedHeaderUtils.java +++ b/today-web/src/main/java/infra/web/util/ForwardedHeaderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ public abstract class ForwardedHeaderUtils { * additional updates from forwarded headers */ public static UriComponentsBuilder adaptFromForwardedHeaders(URI uri, HttpHeaders headers) { - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUri(uri); + UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.forURI(uri); try { String forwardedHeader = headers.getFirst("Forwarded"); if (StringUtils.hasText(forwardedHeader)) { diff --git a/today-web/src/main/java/infra/web/util/HierarchicalUriComponents.java b/today-web/src/main/java/infra/web/util/HierarchicalUriComponents.java index 7b19a756af..622b90f068 100755 --- a/today-web/src/main/java/infra/web/util/HierarchicalUriComponents.java +++ b/today-web/src/main/java/infra/web/util/HierarchicalUriComponents.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -515,7 +515,7 @@ public String toUriString() { } @Override - public URI toUri() { + public URI toURI() { try { if (this.encodeState.isEncoded()) { return new URI(toUriString()); diff --git a/today-web/src/main/java/infra/web/util/OpaqueUriComponents.java b/today-web/src/main/java/infra/web/util/OpaqueUriComponents.java index d7fc0d6b7a..f7d6a87962 100755 --- a/today-web/src/main/java/infra/web/util/OpaqueUriComponents.java +++ b/today-web/src/main/java/infra/web/util/OpaqueUriComponents.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -130,7 +130,7 @@ public String toUriString() { } @Override - public URI toUri() { + public URI toURI() { try { return new URI(getScheme(), this.ssp, getFragment()); } diff --git a/today-web/src/main/java/infra/web/util/UriBuilder.java b/today-web/src/main/java/infra/web/util/UriBuilder.java index 35ea4269ca..72696ae187 100755 --- a/today-web/src/main/java/infra/web/util/UriBuilder.java +++ b/today-web/src/main/java/infra/web/util/UriBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +37,7 @@ * component configured once and used to create many URLs. * * @author Rossen Stoyanchev + * @author 海子 Yang * @see UriBuilderFactory * @see UriComponentsBuilder * @since 4.0 @@ -295,4 +296,17 @@ public interface UriBuilder { * values to preserve URI template placeholders. */ String toUriString(); + + // Static Factory Methods + + /** + * Create a new, empty builder. + * + * @return the new {@code UriComponentsBuilder} + * @since 5.0 + */ + static UriComponentsBuilder forUriComponents() { + return UriComponentsBuilder.create(); + } + } diff --git a/today-web/src/main/java/infra/web/util/UriComponents.java b/today-web/src/main/java/infra/web/util/UriComponents.java index 0602b42c65..b9417296b8 100755 --- a/today-web/src/main/java/infra/web/util/UriComponents.java +++ b/today-web/src/main/java/infra/web/util/UriComponents.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2023 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -12,7 +12,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see [http://www.gnu.org/licenses/] + * along with this program. If not, see [https://www.gnu.org/licenses/] */ package infra.web.util; @@ -43,6 +43,7 @@ * @author Arjen Poutsma * @author Juergen Hoeller * @author Rossen Stoyanchev + * @author 海子 Yang * @see UriComponentsBuilder * @since 4.0 */ @@ -223,7 +224,7 @@ public final UriComponents expand(UriTemplateVariables uriVariables) { * multi-argument {@link URI} constructor which quotes illegal characters * that cannot appear in their respective URI component. */ - public abstract URI toUri(); + public abstract URI toURI(); /** * A simple pass-through to {@link #toUriString()}. @@ -246,9 +247,7 @@ static String expandUriComponent(@Nullable String source, UriTemplateVariables u } @Nullable - static String expandUriComponent( - @Nullable String source, UriTemplateVariables uriVariables, @Nullable UnaryOperator encoder) { - + static String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables, @Nullable UnaryOperator encoder) { if (source == null) { return null; } diff --git a/today-web/src/main/java/infra/web/util/UriComponentsBuilder.java b/today-web/src/main/java/infra/web/util/UriComponentsBuilder.java index ffff8cb428..03a28854a6 100755 --- a/today-web/src/main/java/infra/web/util/UriComponentsBuilder.java +++ b/today-web/src/main/java/infra/web/util/UriComponentsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,7 +49,7 @@ *

    Typical usage involves: *

      *
    1. Create a {@code UriComponentsBuilder} with one of the static factory methods - * (such as {@link #fromPath(String)} or {@link #fromUri(URI)})
    2. + * (such as {@link #forPath(String)} or {@link #forURI(URI)}) *
    3. Set the various URI components through the respective methods ({@link #scheme(String)}, * {@link #userInfo(String)}, {@link #host(String)}, {@link #port(int)}, {@link #path(String)}, * {@link #pathSegment(String...)}, {@link #queryParam(String, Object...)}, and @@ -65,9 +65,9 @@ * @author Sebastien Deleuze * @author Sam Brannen * @author Harry Yang - * @see #newInstance() - * @see #fromPath(String) - * @see #fromUri(URI) + * @see #create() + * @see #forPath(String) + * @see #forURI(URI) * @since 4.0 */ public class UriComponentsBuilder implements UriBuilder, Cloneable { @@ -107,9 +107,9 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { /** * Default constructor. Protected to prevent direct instantiation. * - * @see #newInstance() - * @see #fromPath(String) - * @see #fromUri(URI) + * @see #create() + * @see #forPath(String) + * @see #forURI(URI) */ protected UriComponentsBuilder() { this.pathBuilder = new CompositePathComponentBuilder(); @@ -141,7 +141,7 @@ protected UriComponentsBuilder(UriComponentsBuilder other) { * * @return the new {@code UriComponentsBuilder} */ - public static UriComponentsBuilder newInstance() { + public static UriComponentsBuilder create() { return new UriComponentsBuilder(); } @@ -151,10 +151,8 @@ public static UriComponentsBuilder newInstance() { * @param path the path to initialize with * @return the new {@code UriComponentsBuilder} */ - public static UriComponentsBuilder fromPath(String path) { - UriComponentsBuilder builder = new UriComponentsBuilder(); - builder.path(path); - return builder; + public static UriComponentsBuilder forPath(String path) { + return new UriComponentsBuilder().path(path); } /** @@ -169,22 +167,20 @@ public static UriComponentsBuilder fromPath(String path) { * @param uri the URI to initialize with * @return the new {@code UriComponentsBuilder} */ - public static UriComponentsBuilder fromUri(URI uri) { - UriComponentsBuilder builder = new UriComponentsBuilder(); - builder.uri(uri); - return builder; + public static UriComponentsBuilder forURI(URI uri) { + return new UriComponentsBuilder().uri(uri); } /** - * Variant of {@link #fromUriString(String, ParserType)} that defaults to + * Variant of {@link #forURIString(String, ParserType)} that defaults to * the {@link ParserType#RFC} parsing. */ - public static UriComponentsBuilder fromUriString(String uri) throws InvalidUrlException { + public static UriComponentsBuilder forURIString(String uri) throws InvalidUrlException { Assert.notNull(uri, "URI is required"); if (uri.isEmpty()) { return new UriComponentsBuilder(); } - return fromUriString(uri, ParserType.RFC); + return forURIString(uri, ParserType.RFC); } /** @@ -204,7 +200,7 @@ public static UriComponentsBuilder fromUriString(String uri) throws InvalidUrlEx * @return the new {@code UriComponentsBuilder} * @throws InvalidUrlException if {@code uri} cannot be parsed */ - public static UriComponentsBuilder fromUriString(String uri, ParserType parserType) throws InvalidUrlException { + public static UriComponentsBuilder forURIString(String uri, ParserType parserType) throws InvalidUrlException { Assert.notNull(uri, "URI is required"); if (uri.isEmpty()) { return new UriComponentsBuilder(); @@ -232,12 +228,12 @@ var record = WhatWgUrlParser.parse(uri, WhatWgUrlParser.EMPTY_RECORD, null, null * @param request the source request * @return the URI components of the URI */ - public static UriComponentsBuilder fromHttpRequest(HttpRequest request) { + public static UriComponentsBuilder forHttpRequest(HttpRequest request) { return ForwardedHeaderUtils.adaptFromForwardedHeaders(request.getURI(), request.getHeaders()); } - public static UriComponentsBuilder fromCurrentRequest() { - return fromHttpRequest(RequestContextHolder.get()); + public static UriComponentsBuilder forCurrentRequest() { + return forHttpRequest(RequestContextHolder.get()); } /** @@ -245,8 +241,8 @@ public static UriComponentsBuilder fromCurrentRequest() { * * @see RFC 6454 */ - public static UriComponentsBuilder fromOriginHeader(String origin) { - return fromUriString(origin); + public static UriComponentsBuilder forOriginHeader(String origin) { + return forURIString(origin); } // Encode methods @@ -300,7 +296,7 @@ public UriComponents build() { /** * Variant of {@link #build()} to create a {@link UriComponents} instance * when components are already fully encoded. This is useful for example if - * the builder was created via {@link UriComponentsBuilder#fromUri(URI)}. + * the builder was created via {@link UriComponentsBuilder#forURI(URI)}. * * @param encoded whether the components in this builder are already encoded * @return the URI components @@ -356,12 +352,12 @@ public UriComponents buildAndExpand(Object... uriVariableValues) { @Override public URI build(Object... uriVariables) { - return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri(); + return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toURI(); } @Override public URI build(Map uriVariables) { - return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri(); + return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toURI(); } /** @@ -758,7 +754,7 @@ public UriComponentsBuilder cloneBuilder() { } /** - * Enum to provide a choice of URI parsers to use in {@link #fromUriString(String, ParserType)}. + * Enum to provide a choice of URI parsers to use in {@link #forURIString(String, ParserType)}. * * @since 5.0 */ @@ -938,6 +934,8 @@ public PathSegmentComponentBuilder cloneBuilder() { } } - private enum EncodingHint {ENCODE_TEMPLATE, FULLY_ENCODED, NONE} + private enum EncodingHint { + ENCODE_TEMPLATE, FULLY_ENCODED, NONE + } } diff --git a/today-web/src/main/java/infra/web/util/UriTemplate.java b/today-web/src/main/java/infra/web/util/UriTemplate.java index 7c0a09915b..7aa538d297 100755 --- a/today-web/src/main/java/infra/web/util/UriTemplate.java +++ b/today-web/src/main/java/infra/web/util/UriTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,7 +70,7 @@ public class UriTemplate implements Serializable { public UriTemplate(String uriTemplate) { Assert.notNull(uriTemplate, "'uriTemplate' is required"); this.uriTemplate = uriTemplate; - this.uriComponents = UriComponentsBuilder.fromUriString(uriTemplate).build(); + this.uriComponents = UriComponentsBuilder.forURIString(uriTemplate).build(); TemplateInfo info = TemplateInfo.parse(uriTemplate); this.variableNames = Collections.unmodifiableList(info.getVariableNames()); @@ -107,7 +107,7 @@ public List getVariableNames() { public URI expand(Map uriVariables) { UriComponents expandedComponents = this.uriComponents.expand(uriVariables); UriComponents encodedComponents = expandedComponents.encode(); - return encodedComponents.toUri(); + return encodedComponents.toURI(); } /** @@ -128,7 +128,7 @@ public URI expand(Map uriVariables) { public URI expand(Object... uriVariableValues) { UriComponents expandedComponents = this.uriComponents.expand(uriVariableValues); UriComponents encodedComponents = expandedComponents.encode(); - return encodedComponents.toUri(); + return encodedComponents.toURI(); } /** diff --git a/today-web/src/main/java/infra/web/util/WebUtils.java b/today-web/src/main/java/infra/web/util/WebUtils.java index 71b592bc63..35ea44909e 100755 --- a/today-web/src/main/java/infra/web/util/WebUtils.java +++ b/today-web/src/main/java/infra/web/util/WebUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -282,7 +282,7 @@ public static boolean isSameOrigin(RequestContext request) { String host = request.getServerName(); int port = request.getServerPort(); - UriComponents originUrl = UriComponentsBuilder.fromOriginHeader(origin).build(); + UriComponents originUrl = UriComponentsBuilder.forOriginHeader(origin).build(); return Objects.equals(scheme, originUrl.getScheme()) && Objects.equals(host, originUrl.getHost()) && getPort(scheme, port) == getPort(originUrl.getScheme(), originUrl.getPort()); diff --git a/today-web/src/test/java/infra/http/RequestEntityTests.java b/today-web/src/test/java/infra/http/RequestEntityTests.java index 88fbef800b..0069c80db2 100755 --- a/today-web/src/test/java/infra/http/RequestEntityTests.java +++ b/today-web/src/test/java/infra/http/RequestEntityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -62,7 +62,7 @@ void normal() throws URISyntaxException { @Test void uriVariablesExpansion() throws URISyntaxException { - URI uri = UriComponentsBuilder.fromUriString("https://example.com/{foo}").buildAndExpand("bar").toUri(); + URI uri = UriComponentsBuilder.forURIString("https://example.com/{foo}").buildAndExpand("bar").toURI(); RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build(); String url = "https://www.{host}.com/{path}"; @@ -70,7 +70,7 @@ void uriVariablesExpansion() throws URISyntaxException { String path = "foo/bar"; URI expected = new URI("https://www.example.com/foo/bar"); - uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(host, path).toUri(); + uri = UriComponentsBuilder.forURIString(url).buildAndExpand(host, path).toURI(); RequestEntity entity = RequestEntity.get(uri).build(); assertThat(entity.getURI()).isEqualTo(expected); @@ -78,7 +78,7 @@ void uriVariablesExpansion() throws URISyntaxException { uriVariables.put("host", host); uriVariables.put("path", path); - uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).toUri(); + uri = UriComponentsBuilder.forURIString(url).buildAndExpand(uriVariables).toURI(); entity = RequestEntity.get(uri).build(); assertThat(entity.getURI()).isEqualTo(expected); } diff --git a/today-web/src/test/java/infra/web/service/invoker/HttpRequestValuesTests.java b/today-web/src/test/java/infra/web/service/invoker/HttpRequestValuesTests.java index cc35047772..4d4a81f381 100755 --- a/today-web/src/test/java/infra/web/service/invoker/HttpRequestValuesTests.java +++ b/today-web/src/test/java/infra/web/service/invoker/HttpRequestValuesTests.java @@ -92,7 +92,7 @@ void queryParamsWithUriTemplate() { .containsEntry("queryParam1[0]", "2nd value A") .containsEntry("queryParam1[1]", "2nd value B"); - URI uri = UriComponentsBuilder.fromUriString(uriTemplate) + URI uri = UriComponentsBuilder.forURIString(uriTemplate) .encode() .build(requestValues.getUriVariables()); diff --git a/today-web/src/test/java/infra/web/service/invoker/RequestParamArgumentResolverTests.java b/today-web/src/test/java/infra/web/service/invoker/RequestParamArgumentResolverTests.java index 1280e0bd3b..56c842af34 100755 --- a/today-web/src/test/java/infra/web/service/invoker/RequestParamArgumentResolverTests.java +++ b/today-web/src/test/java/infra/web/service/invoker/RequestParamArgumentResolverTests.java @@ -76,7 +76,7 @@ void requestParamWithDisabledFormattingCollectionValue() { HttpRequestValues values = this.client.getRequestValues(); String uriTemplate = values.getUriTemplate(); Map uriVariables = values.getUriVariables(); - UriComponents uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode(); + UriComponents uri = UriComponentsBuilder.forURIString(uriTemplate).buildAndExpand(uriVariables).encode(); assertThat(uri.getQuery()).isEqualTo("param1=value%201¶m2=1,2,3"); } diff --git a/today-web/src/test/java/infra/web/util/UriComponentsBuilderTests.java b/today-web/src/test/java/infra/web/util/UriComponentsBuilderTests.java index 35134ef9fb..89532c256e 100755 --- a/today-web/src/test/java/infra/web/util/UriComponentsBuilderTests.java +++ b/today-web/src/test/java/infra/web/util/UriComponentsBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,26 +56,26 @@ class UriComponentsBuilderTests { void examplesInReferenceManual(ParserType parserType) { final String expected = "/hotel%20list/New%20York?q=foo%2Bbar"; - URI uri = UriComponentsBuilder.fromPath("/hotel list/{city}") + URI uri = UriComponentsBuilder.forPath("/hotel list/{city}") .queryParam("q", "{q}") .encode() .buildAndExpand("New York", "foo+bar") - .toUri(); + .toURI(); assertThat(uri).asString().isEqualTo(expected); - uri = UriComponentsBuilder.fromPath("/hotel list/{city}") + uri = UriComponentsBuilder.forPath("/hotel list/{city}") .queryParam("q", "{q}") .build("New York", "foo+bar"); assertThat(uri).asString().isEqualTo(expected); - uri = UriComponentsBuilder.fromUriString("/hotel list/{city}?q={q}", parserType) + uri = UriComponentsBuilder.forURIString("/hotel list/{city}?q={q}", parserType) .build("New York", "foo+bar"); assertThat(uri).asString().isEqualTo(expected); } @Test void plain() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); + UriComponentsBuilder builder = UriComponentsBuilder.create(); UriComponents result = builder.scheme("https").host("example.com") .path("foo").queryParam("bar").fragment("baz").build(); @@ -86,12 +86,12 @@ void plain() { assertThat(result.getFragment()).isEqualTo("baz"); URI expected = URI.create("https://example.com/foo?bar#baz"); - assertThat(result.toUri()).as("Invalid result URI").isEqualTo(expected); + assertThat(result.toURI()).as("Invalid result URI").isEqualTo(expected); } @Test void multipleFromSameBuilder() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance() + UriComponentsBuilder builder = UriComponentsBuilder.create() .scheme("https").host("example.com").pathSegment("foo"); UriComponents result1 = builder.build(); builder = builder.pathSegment("foo2").queryParam("bar").fragment("baz"); @@ -101,7 +101,7 @@ void multipleFromSameBuilder() { assertThat(result1.getHost()).isEqualTo("example.com"); assertThat(result1.getPath()).isEqualTo("/foo"); URI expected = URI.create("https://example.com/foo"); - assertThat(result1.toUri()).as("Invalid result URI").isEqualTo(expected); + assertThat(result1.toURI()).as("Invalid result URI").isEqualTo(expected); assertThat(result2.getScheme()).isEqualTo("https"); assertThat(result2.getHost()).isEqualTo("example.com"); @@ -109,12 +109,12 @@ void multipleFromSameBuilder() { assertThat(result2.getQuery()).isEqualTo("bar"); assertThat(result2.getFragment()).isEqualTo("baz"); expected = URI.create("https://example.com/foo/foo2?bar#baz"); - assertThat(result2.toUri()).as("Invalid result URI").isEqualTo(expected); + assertThat(result2.toURI()).as("Invalid result URI").isEqualTo(expected); } @Test void fromPath() { - UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build(); + UriComponents result = UriComponentsBuilder.forPath("foo").queryParam("bar").fragment("baz").build(); assertThat(result.getPath()).isEqualTo("foo"); assertThat(result.getQuery()).isEqualTo("bar"); @@ -122,45 +122,45 @@ void fromPath() { assertThat(result.toUriString()).as("Invalid result URI String").isEqualTo("foo?bar#baz"); URI expected = URI.create("foo?bar#baz"); - assertThat(result.toUri()).as("Invalid result URI").isEqualTo(expected); + assertThat(result.toURI()).as("Invalid result URI").isEqualTo(expected); - result = UriComponentsBuilder.fromPath("/foo").build(); + result = UriComponentsBuilder.forPath("/foo").build(); assertThat(result.getPath()).isEqualTo("/foo"); expected = URI.create("/foo"); - assertThat(result.toUri()).as("Invalid result URI").isEqualTo(expected); + assertThat(result.toURI()).as("Invalid result URI").isEqualTo(expected); } @Test void fromHierarchicalUri() { URI uri = URI.create("https://example.com/foo?bar#baz"); - UriComponents result = UriComponentsBuilder.fromUri(uri).build(); + UriComponents result = UriComponentsBuilder.forURI(uri).build(); assertThat(result.getScheme()).isEqualTo("https"); assertThat(result.getHost()).isEqualTo("example.com"); assertThat(result.getPath()).isEqualTo("/foo"); assertThat(result.getQuery()).isEqualTo("bar"); assertThat(result.getFragment()).isEqualTo("baz"); - assertThat(result.toUri()).as("Invalid result URI").isEqualTo(uri); + assertThat(result.toURI()).as("Invalid result URI").isEqualTo(uri); } @Test void fromOpaqueUri() { URI uri = URI.create("mailto:foo@bar.com#baz"); - UriComponents result = UriComponentsBuilder.fromUri(uri).build(); + UriComponents result = UriComponentsBuilder.forURI(uri).build(); assertThat(result.getScheme()).isEqualTo("mailto"); assertThat(result.getSchemeSpecificPart()).isEqualTo("foo@bar.com"); assertThat(result.getFragment()).isEqualTo("baz"); - assertThat(result.toUri()).as("Invalid result URI").isEqualTo(uri); + assertThat(result.toURI()).as("Invalid result URI").isEqualTo(uri); } @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriEncodedQuery(ParserType parserType) { + void forUriEncodedQuery(ParserType parserType) { URI uri = URI.create("https://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D"); - String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0); - String fromUriString = UriComponentsBuilder.fromUriString(uri.toString(), parserType) + String fromUri = UriComponentsBuilder.forURI(uri).build().getQueryParams().get("param").get(0); + String fromUriString = UriComponentsBuilder.forURIString(uri.toString(), parserType) .build().getQueryParams().get("param").get(0); assertThat(fromUriString).isEqualTo(fromUri); @@ -168,8 +168,8 @@ void fromUriEncodedQuery(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriString(ParserType parserType) { - UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt", parserType).build(); + void forUriString(ParserType parserType) { + UriComponents result = UriComponentsBuilder.forURIString("https://www.ietf.org/rfc/rfc3986.txt", parserType).build(); assertThat(result.getScheme()).isEqualTo("https"); assertThat(result.getUserInfo()).isNull(); assertThat(result.getHost()).isEqualTo("www.ietf.org"); @@ -181,7 +181,7 @@ void fromUriString(ParserType parserType) { String url = "https://arjen:foobar@java.sun.com:80" + "/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)"; - result = UriComponentsBuilder.fromUriString(url, parserType).build(); + result = UriComponentsBuilder.forURIString(url, parserType).build(); assertThat(result.getScheme()).isEqualTo("https"); assertThat(result.getUserInfo()).isEqualTo("arjen:foobar"); assertThat(result.getHost()).isEqualTo("java.sun.com"); @@ -193,7 +193,7 @@ void fromUriString(ParserType parserType) { assertThat(result.getQueryParams()).isEqualTo(expectedQueryParams); assertThat(result.getFragment()).isEqualTo("and(java.util.BitSet)"); - result = UriComponentsBuilder.fromUriString("mailto:java-net@java.sun.com#baz", parserType).build(); + result = UriComponentsBuilder.forURIString("mailto:java-net@java.sun.com#baz", parserType).build(); assertThat(result.getScheme()).isEqualTo("mailto"); assertThat(result.getUserInfo()).isNull(); assertThat(result.getHost()).isNull(); @@ -203,7 +203,7 @@ void fromUriString(ParserType parserType) { assertThat(result.getQuery()).isNull(); assertThat(result.getFragment()).isEqualTo("baz"); - result = UriComponentsBuilder.fromUriString("mailto:user@example.com?subject=foo", parserType).build(); + result = UriComponentsBuilder.forURIString("mailto:user@example.com?subject=foo", parserType).build(); assertThat(result.getScheme()).isEqualTo("mailto"); assertThat(result.getUserInfo()).isNull(); assertThat(result.getHost()).isNull(); @@ -213,7 +213,7 @@ void fromUriString(ParserType parserType) { assertThat(result.getQuery()).isNull(); assertThat(result.getFragment()).isNull(); - result = UriComponentsBuilder.fromUriString("docs/guide/collections/designfaq.html#28", parserType).build(); + result = UriComponentsBuilder.forURIString("docs/guide/collections/designfaq.html#28", parserType).build(); assertThat(result.getScheme()).isNull(); assertThat(result.getUserInfo()).isNull(); assertThat(result.getHost()).isNull(); @@ -225,9 +225,9 @@ void fromUriString(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriStringQueryParamWithReservedCharInValue(ParserType parserType) { + void forUriStringQueryParamWithReservedCharInValue(ParserType parserType) { String uri = "https://www.google.com/ig/calculator?q=1USD=?EUR"; - UriComponents result = UriComponentsBuilder.fromUriString(uri, parserType).build(); + UriComponents result = UriComponentsBuilder.forURIString(uri, parserType).build(); assertThat(result.getQuery()).isEqualTo("q=1USD=?EUR"); assertThat(result.getQueryParams().getFirst("q")).isEqualTo("1USD=?EUR"); @@ -235,32 +235,32 @@ void fromUriStringQueryParamWithReservedCharInValue(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriStringQueryParamEncodedAndContainingPlus(ParserType parserType) { + void forUriStringQueryParamEncodedAndContainingPlus(ParserType parserType) { String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98"; - URI uri = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(true).toUri(); + URI uri = UriComponentsBuilder.forURIString(httpUrl, parserType).build(true).toURI(); assertThat(uri.toString()).isEqualTo(httpUrl); } @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriStringIPv6Host(ParserType parserType) { + void forUriStringIPv6Host(ParserType parserType) { UriComponents result = UriComponentsBuilder - .fromUriString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource", parserType).build().encode(); + .forURIString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource", parserType).build().encode(); assertThat(result.getHost()).isEqualToIgnoringCase("[1abc:2abc:3abc::5ABC:6abc]"); } @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriStringInvalidIPv6Host(ParserType parserType) { + void forUriStringInvalidIPv6Host(ParserType parserType) { assertThatIllegalArgumentException().isThrownBy(() -> - UriComponentsBuilder.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType)); + UriComponentsBuilder.forURIString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType)); } @ParameterizedTest @EnumSource(value = ParserType.class) - void fromUriStringNoPathWithReservedCharInQuery(ParserType parserType) { - UriComponents result = UriComponentsBuilder.fromUriString("https://example.com?foo=bar@baz", parserType).build(); + void forUriStringNoPathWithReservedCharInQuery(ParserType parserType) { + UriComponents result = UriComponentsBuilder.forURIString("https://example.com?foo=bar@baz", parserType).build(); assertThat(result.getUserInfo()).isNull(); assertThat(result.getHost()).isEqualTo("example.com"); assertThat(result.getQueryParams()).containsKey("foo"); @@ -271,7 +271,7 @@ void fromUriStringNoPathWithReservedCharInQuery(ParserType parserType) { @EnumSource(value = ParserType.class) void fromHttpUrlQueryParamEncodedAndContainingPlus(ParserType parserType) { String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98"; - URI uri = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(true).toUri(); + URI uri = UriComponentsBuilder.forURIString(httpUrl, parserType).build(true).toURI(); assertThat(uri.toString()).isEqualTo(httpUrl); } @@ -279,9 +279,9 @@ void fromHttpUrlQueryParamEncodedAndContainingPlus(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) void fromHttpUrlCaseInsensitiveScheme(ParserType parserType) { - assertThat(UriComponentsBuilder.fromUriString("HTTP://www.google.com", parserType).build().getScheme()) + assertThat(UriComponentsBuilder.forURIString("HTTP://www.google.com", parserType).build().getScheme()) .isEqualTo("http"); - assertThat(UriComponentsBuilder.fromUriString("HTTPS://www.google.com", parserType).build().getScheme()) + assertThat(UriComponentsBuilder.forURIString("HTTPS://www.google.com", parserType).build().getScheme()) .isEqualTo("https"); } @@ -289,14 +289,14 @@ void fromHttpUrlCaseInsensitiveScheme(ParserType parserType) { @EnumSource(value = ParserType.class) void fromHttpUrlInvalidIPv6Host(ParserType parserType) { assertThatIllegalArgumentException().isThrownBy(() -> - UriComponentsBuilder.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType)); + UriComponentsBuilder.forURIString("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource", parserType)); } @ParameterizedTest @EnumSource(value = ParserType.class) void fromHttpUrlWithoutFragment(ParserType parserType) { String httpUrl = "http://localhost:8080/test/print"; - UriComponents uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("http"); assertThat(uriComponents.getUserInfo()).isNull(); assertThat(uriComponents.getHost()).isEqualTo("localhost"); @@ -305,10 +305,10 @@ void fromHttpUrlWithoutFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEqualTo(Arrays.asList("test", "print")); assertThat(uriComponents.getQuery()).isNull(); assertThat(uriComponents.getFragment()).isNull(); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); httpUrl = "http://user:test@localhost:8080/test/print?foo=bar"; - uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("http"); assertThat(uriComponents.getUserInfo()).isEqualTo("user:test"); assertThat(uriComponents.getHost()).isEqualTo("localhost"); @@ -317,10 +317,10 @@ void fromHttpUrlWithoutFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEqualTo(Arrays.asList("test", "print")); assertThat(uriComponents.getQuery()).isEqualTo("foo=bar"); assertThat(uriComponents.getFragment()).isNull(); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); httpUrl = "http://localhost:8080/test/print?foo=bar"; - uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("http"); assertThat(uriComponents.getUserInfo()).isNull(); assertThat(uriComponents.getHost()).isEqualTo("localhost"); @@ -329,14 +329,14 @@ void fromHttpUrlWithoutFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEqualTo(Arrays.asList("test", "print")); assertThat(uriComponents.getQuery()).isEqualTo("foo=bar"); assertThat(uriComponents.getFragment()).isNull(); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); } @ParameterizedTest @EnumSource(value = ParserType.class) void fromHttpUrlWithFragment(ParserType parserType) { String httpUrl = "https://example.com/#baz"; - UriComponents uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("https"); assertThat(uriComponents.getUserInfo()).isNull(); assertThat(uriComponents.getHost()).isEqualTo("example.com"); @@ -345,10 +345,10 @@ void fromHttpUrlWithFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEmpty(); assertThat(uriComponents.getQuery()).isNull(); assertThat(uriComponents.getFragment()).isEqualTo("baz"); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); httpUrl = "http://localhost:8080/test/print#baz"; - uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("http"); assertThat(uriComponents.getUserInfo()).isNull(); assertThat(uriComponents.getHost()).isEqualTo("localhost"); @@ -357,10 +357,10 @@ void fromHttpUrlWithFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEqualTo(Arrays.asList("test", "print")); assertThat(uriComponents.getQuery()).isNull(); assertThat(uriComponents.getFragment()).isEqualTo("baz"); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); httpUrl = "http://localhost:8080/test/print?foo=bar#baz"; - uriComponents = UriComponentsBuilder.fromUriString(httpUrl, parserType).build(); + uriComponents = UriComponentsBuilder.forURIString(httpUrl, parserType).build(); assertThat(uriComponents.getScheme()).isEqualTo("http"); assertThat(uriComponents.getUserInfo()).isNull(); assertThat(uriComponents.getHost()).isEqualTo("localhost"); @@ -369,20 +369,20 @@ void fromHttpUrlWithFragment(ParserType parserType) { assertThat(uriComponents.getPathSegments()).isEqualTo(Arrays.asList("test", "print")); assertThat(uriComponents.getQuery()).isEqualTo("foo=bar"); assertThat(uriComponents.getFragment()).isEqualTo("baz"); - assertThat(uriComponents.toUri().toString()).isEqualTo(httpUrl); + assertThat(uriComponents.toURI().toString()).isEqualTo(httpUrl); } @Test // - void fromHttpRequestWithTrailingSlash() { - UriComponents before = UriComponentsBuilder.fromPath("/foo/").build(); - UriComponents after = UriComponentsBuilder.newInstance().uriComponents(before).build(); + void forHttpRequestWithTrailingSlash() { + UriComponents before = UriComponentsBuilder.forPath("/foo/").build(); + UriComponents after = UriComponentsBuilder.create().uriComponents(before).build(); assertThat(after.getPath()).isEqualTo("/foo/"); } @Test void path() { - UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar"); + UriComponentsBuilder builder = UriComponentsBuilder.forPath("/foo/bar"); UriComponents result = builder.build(); assertThat(result.getPath()).isEqualTo("/foo/bar"); @@ -391,7 +391,7 @@ void path() { @Test void pathSegments() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); + UriComponentsBuilder builder = UriComponentsBuilder.create(); UriComponents result = builder.pathSegment("foo").pathSegment("bar").build(); assertThat(result.getPath()).isEqualTo("/foo/bar"); @@ -400,7 +400,7 @@ void pathSegments() { @Test void pathThenPath() { - UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").path("ba/z"); + UriComponentsBuilder builder = UriComponentsBuilder.forPath("/foo/bar").path("ba/z"); UriComponents result = builder.build().encode(); assertThat(result.getPath()).isEqualTo("/foo/barba/z"); @@ -409,7 +409,7 @@ void pathThenPath() { @Test void pathThenPathSegments() { - UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z"); + UriComponentsBuilder builder = UriComponentsBuilder.forPath("/foo/bar").pathSegment("ba/z"); UriComponents result = builder.build().encode(); assertThat(result.getPath()).isEqualTo("/foo/bar/ba%2Fz"); @@ -418,7 +418,7 @@ void pathThenPathSegments() { @Test void pathSegmentsThenPathSegments() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").pathSegment("bar"); + UriComponentsBuilder builder = UriComponentsBuilder.create().pathSegment("foo").pathSegment("bar"); UriComponents result = builder.build(); assertThat(result.getPath()).isEqualTo("/foo/bar"); @@ -427,7 +427,7 @@ void pathSegmentsThenPathSegments() { @Test void pathSegmentsThenPath() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").path("/"); + UriComponentsBuilder builder = UriComponentsBuilder.create().pathSegment("foo").path("/"); UriComponents result = builder.build(); assertThat(result.getPath()).isEqualTo("/foo/"); @@ -436,7 +436,7 @@ void pathSegmentsThenPath() { @Test void pathSegmentsSomeEmpty() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("", "foo", "", "bar"); + UriComponentsBuilder builder = UriComponentsBuilder.create().pathSegment("", "foo", "", "bar"); UriComponents result = builder.build(); assertThat(result.getPath()).isEqualTo("/foo/bar"); @@ -446,20 +446,20 @@ void pathSegmentsSomeEmpty() { @Test // void pathWithDuplicateSlashes() { - UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build(); + UriComponents uriComponents = UriComponentsBuilder.forPath("/foo/////////bar").build(); assertThat(uriComponents.getPath()).isEqualTo("/foo/bar"); } @ParameterizedTest @EnumSource(value = ParserType.class) void replacePath(ParserType parserType) { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc2396.txt", parserType); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://www.ietf.org/rfc/rfc2396.txt", parserType); builder.replacePath("/rfc/rfc3986.txt"); UriComponents result = builder.build(); assertThat(result.toUriString()).isEqualTo("https://www.ietf.org/rfc/rfc3986.txt"); - builder = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc2396.txt", parserType); + builder = UriComponentsBuilder.forURIString("https://www.ietf.org/rfc/rfc2396.txt", parserType); builder.replacePath(null); result = builder.build(); @@ -469,13 +469,13 @@ void replacePath(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) void replaceQuery(ParserType parserType) { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar&baz=qux", parserType); + UriComponentsBuilder builder = UriComponentsBuilder.forURIString("https://example.com/foo?foo=bar&baz=qux", parserType); builder.replaceQuery("baz=42"); UriComponents result = builder.build(); assertThat(result.toUriString()).isEqualTo("https://example.com/foo?baz=42"); - builder = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar&baz=qux", parserType); + builder = UriComponentsBuilder.forURIString("https://example.com/foo?foo=bar&baz=qux", parserType); builder.replaceQuery(null); result = builder.build(); @@ -484,7 +484,7 @@ void replaceQuery(ParserType parserType) { @Test void queryParam() { - UriComponents result = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42).build(); + UriComponents result = UriComponentsBuilder.create().queryParam("baz", "qux", 42).build(); assertThat(result.getQuery()).isEqualTo("baz=qux&baz=42"); MultiValueMap expectedQueryParams = new LinkedMultiValueMap<>(2); @@ -496,7 +496,7 @@ void queryParam() { @Test void queryParamWithList() { List values = Arrays.asList("qux", "42"); - UriComponents result = UriComponentsBuilder.newInstance().queryParam("baz", values).build(); + UriComponents result = UriComponentsBuilder.create().queryParam("baz", values).build(); assertThat(result.getQuery()).isEqualTo("baz=qux&baz=42"); assertThat(result.getQueryParams()).containsOnlyKeys("baz").containsEntry("baz", values); @@ -504,7 +504,7 @@ void queryParamWithList() { @Test void queryParamWithOptionalValue() { - UriComponents result = UriComponentsBuilder.newInstance() + UriComponents result = UriComponentsBuilder.create() .queryParam("foo", Optional.empty()) .queryParam("baz", Optional.of("qux"), 42) .build(); @@ -517,7 +517,7 @@ void queryParamWithOptionalValue() { @Test void queryParamIfPresent() { - UriComponents result = UriComponentsBuilder.newInstance() + UriComponents result = UriComponentsBuilder.create() .queryParamIfPresent("baz", Optional.of("qux")) .queryParamIfPresent("foo", Optional.empty()) .build(); @@ -531,7 +531,7 @@ void queryParamIfPresent() { @Test void queryParamIfPresentCollection() { List values = Arrays.asList("foo", "bar"); - UriComponents result = UriComponentsBuilder.newInstance() + UriComponents result = UriComponentsBuilder.create() .queryParamIfPresent("baz", Optional.of(values)) .build(); @@ -541,7 +541,7 @@ void queryParamIfPresentCollection() { @Test void emptyQueryParam() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); + UriComponentsBuilder builder = UriComponentsBuilder.create(); UriComponents result = builder.queryParam("baz").build(); assertThat(result.getQuery()).isEqualTo("baz"); @@ -552,7 +552,7 @@ void emptyQueryParam() { @Test void emptyQueryParams() { - UriComponents result = UriComponentsBuilder.newInstance() + UriComponents result = UriComponentsBuilder.create() .queryParam("baz", Collections.emptyList()) .queryParam("foo", (Collection) null) .build(); @@ -566,13 +566,13 @@ void emptyQueryParams() { @Test void replaceQueryParam() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42); + UriComponentsBuilder builder = UriComponentsBuilder.create().queryParam("baz", "qux", 42); builder.replaceQueryParam("baz", "xuq", 24); UriComponents result = builder.build(); assertThat(result.getQuery()).isEqualTo("baz=xuq&baz=24"); - builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42); + builder = UriComponentsBuilder.create().queryParam("baz", "qux", 42); builder.replaceQueryParam("baz"); result = builder.build(); @@ -581,13 +581,13 @@ void replaceQueryParam() { @Test void replaceQueryParams() { - UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", Arrays.asList("qux", 42)); + UriComponentsBuilder builder = UriComponentsBuilder.create().queryParam("baz", Arrays.asList("qux", 42)); builder.replaceQueryParam("baz", Arrays.asList("xuq", 24)); UriComponents result = builder.build(); assertThat(result.getQuery()).isEqualTo("baz=xuq&baz=24"); - builder = UriComponentsBuilder.newInstance().queryParam("baz", Arrays.asList("qux", 42)); + builder = UriComponentsBuilder.create().queryParam("baz", Arrays.asList("qux", 42)); builder.replaceQueryParam("baz", Collections.emptyList()); result = builder.build(); @@ -596,13 +596,13 @@ void replaceQueryParams() { @Test void buildAndExpandHierarchical() { - UriComponents result = UriComponentsBuilder.fromPath("/{foo}").buildAndExpand("fooValue"); + UriComponents result = UriComponentsBuilder.forPath("/{foo}").buildAndExpand("fooValue"); assertThat(result.toUriString()).isEqualTo("/fooValue"); Map values = new HashMap<>(); values.put("foo", "fooValue"); values.put("bar", "barValue"); - result = UriComponentsBuilder.fromPath("/{foo}/{bar}").buildAndExpand(values); + result = UriComponentsBuilder.forPath("/{foo}/{bar}").buildAndExpand(values); assertThat(result.toUriString()).isEqualTo("/fooValue/barValue"); } @@ -610,25 +610,25 @@ void buildAndExpandHierarchical() { @EnumSource(value = ParserType.class) void parseBuildAndExpandHierarchical(ParserType parserType) { URI uri = UriComponentsBuilder - .fromUriString("{scheme}://{host}:{port}/{segment}?{query}#{fragment}", parserType) + .forURIString("{scheme}://{host}:{port}/{segment}?{query}#{fragment}", parserType) .buildAndExpand(Map.of( "scheme", "ws", "host", "example.org", "port", "7777", "segment", "path", "query", "q=1", "fragment", "foo")) - .toUri(); + .toURI(); assertThat(uri.toString()).isEqualTo("ws://example.org:7777/path?q=1#foo"); } @ParameterizedTest @EnumSource(value = ParserType.class) void buildAndExpandOpaque(ParserType parserType) { - UriComponents result = UriComponentsBuilder.fromUriString("mailto:{user}@{domain}", parserType) + UriComponents result = UriComponentsBuilder.forURIString("mailto:{user}@{domain}", parserType) .buildAndExpand("foo", "example.com"); assertThat(result.toUriString()).isEqualTo("mailto:foo@example.com"); Map values = new HashMap<>(); values.put("user", "foo"); values.put("domain", "example.com"); - UriComponentsBuilder.fromUriString("mailto:{user}@{domain}", parserType).buildAndExpand(values); + UriComponentsBuilder.forURIString("mailto:{user}@{domain}", parserType).buildAndExpand(values); assertThat(result.toUriString()).isEqualTo("mailto:foo@example.com"); } @@ -637,9 +637,9 @@ void buildAndExpandOpaque(ParserType parserType) { void schemeVariableMixedCase(ParserType parserType) { BiConsumer tester = (scheme, value) -> { - URI uri = UriComponentsBuilder.fromUriString(scheme + "://example.org", parserType) + URI uri = UriComponentsBuilder.forURIString(scheme + "://example.org", parserType) .buildAndExpand(Map.of("TheScheme", value)) - .toUri(); + .toURI(); assertThat(uri.toString()).isEqualTo("wss://example.org"); }; @@ -651,7 +651,7 @@ void schemeVariableMixedCase(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) void queryParamWithValueWithEquals(ParserType parserType) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=baz", parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString("https://example.com/foo?bar=baz", parserType).build(); assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar=baz"); assertThat(uriComponents.getQueryParams().get("bar")).containsExactly("baz"); } @@ -659,7 +659,7 @@ void queryParamWithValueWithEquals(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) void queryParamWithoutValueWithEquals(ParserType parserType) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=", parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString("https://example.com/foo?bar=", parserType).build(); assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar="); assertThat(uriComponents.getQueryParams().get("bar")).element(0).asString().isEmpty(); } @@ -667,7 +667,7 @@ void queryParamWithoutValueWithEquals(ParserType parserType) { @ParameterizedTest @EnumSource(value = ParserType.class) void queryParamWithoutValueWithoutEquals(ParserType parserType) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar", parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString("https://example.com/foo?bar", parserType).build(); assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar"); assertThat(uriComponents.getQueryParams().get("bar")).element(0).isNull(); @@ -676,7 +676,7 @@ void queryParamWithoutValueWithoutEquals(ParserType parserType) { @Test void opaqueUriDoesNotResetOnNullInput() { URI uri = URI.create("urn:ietf:wg:oauth:2.0:oob"); - UriComponents result = UriComponentsBuilder.fromUri(uri) + UriComponents result = UriComponentsBuilder.forURI(uri) .host(null) .port(-1) .port(null) @@ -685,24 +685,24 @@ void opaqueUriDoesNotResetOnNullInput() { .query(null) .build(); - assertThat(result.toUri()).isEqualTo(uri); + assertThat(result.toURI()).isEqualTo(uri); } @ParameterizedTest @EnumSource(value = ParserType.class) void relativeUrls(ParserType parserType) { String baseUrl = "https://example.com"; - assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar", parserType).build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl + "/foo/../bar", parserType).build().toString()) .isEqualTo(baseUrl + (parserType == ParserType.WHAT_WG ? "/bar" : "/foo/../bar")); - assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar", parserType).build().toUriString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl + "/foo/../bar", parserType).build().toUriString()) .isEqualTo(baseUrl + (parserType == ParserType.WHAT_WG ? "/bar" : "/foo/../bar")); - assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar", parserType).build().toUri().getPath()) + assertThat(UriComponentsBuilder.forURIString(baseUrl + "/foo/../bar", parserType).build().toURI().getPath()) .isEqualTo((parserType == ParserType.WHAT_WG ? "/bar" : "/foo/../bar")); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).path("foo/../bar").build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).path("foo/../bar").build().toString()) .isEqualTo(baseUrl + "/foo/../bar"); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).path("foo/../bar").build().toUriString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).path("foo/../bar").build().toUriString()) .isEqualTo(baseUrl + "/foo/../bar"); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).path("foo/../bar").build().toUri().getPath()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).path("foo/../bar").build().toURI().getPath()) .isEqualTo("/foo/../bar"); } @@ -710,20 +710,20 @@ void relativeUrls(ParserType parserType) { @EnumSource(value = ParserType.class) void emptySegments(ParserType parserType) { String baseUrl = "https://example.com/abc/"; - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).path("/x/y/z").build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).path("/x/y/z").build().toString()) .isEqualTo("https://example.com/abc/x/y/z"); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).pathSegment("x", "y", "z").build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).pathSegment("x", "y", "z").build().toString()) .isEqualTo("https://example.com/abc/x/y/z"); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).path("/x/").path("/y/z").build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).path("/x/").path("/y/z").build().toString()) .isEqualTo("https://example.com/abc/x/y/z"); - assertThat(UriComponentsBuilder.fromUriString(baseUrl, parserType).pathSegment("x").path("y").build().toString()) + assertThat(UriComponentsBuilder.forURIString(baseUrl, parserType).pathSegment("x").path("y").build().toString()) .isEqualTo("https://example.com/abc/x/y"); } @ParameterizedTest @EnumSource(value = ParserType.class) void parsesEmptyFragment(ParserType parserType) { - UriComponents components = UriComponentsBuilder.fromUriString("/example#", parserType).build(); + UriComponents components = UriComponentsBuilder.forURIString("/example#", parserType).build(); assertThat(components.getFragment()).isNull(); assertThat(components.toString()).isEqualTo("/example"); } @@ -731,13 +731,13 @@ void parsesEmptyFragment(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) void parsesEmptyUri(ParserType parserType) { - UriComponents components = UriComponentsBuilder.fromUriString("", parserType).build(); + UriComponents components = UriComponentsBuilder.forURIString("", parserType).build(); assertThat(components.toString()).isEmpty(); } @Test void testCloneAndMerge() { - UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance(); + UriComponentsBuilder builder1 = UriComponentsBuilder.create(); builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1", "x").fragment("f1").encode(); UriComponentsBuilder builder2 = builder1.cloneBuilder(); @@ -766,7 +766,7 @@ void testDeepClone() { vars.put("ps1", "foo"); vars.put("ps2", "bar"); - UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance(); + UriComponentsBuilder builder1 = UriComponentsBuilder.create(); builder1.scheme("http").host("e1.com").userInfo("user:pwd").path("/p1").pathSegment("{ps1}") .pathSegment("{ps2}").queryParam("q1").fragment("f1").uriVariables(vars).encode(); @@ -796,7 +796,7 @@ void testDeepClone() { void encodeTemplateWithInvalidPlaceholderSyntax(ParserType parserType) { BiConsumer tester = (in, out) -> - assertThat(UriComponentsBuilder.fromUriString(in, parserType).encode().toUriString()).isEqualTo(out); + assertThat(UriComponentsBuilder.forURIString(in, parserType).encode().toUriString()).isEqualTo(out); // empty tester.accept("{}", "%7B%7D"); @@ -824,8 +824,8 @@ void encodeTemplateWithInvalidPlaceholderSyntax(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) void uriComponentsNotEqualAfterNormalization(ParserType parserType) { - UriComponents uri1 = UriComponentsBuilder.fromUriString("http://test.com", parserType).build().normalize(); - UriComponents uri2 = UriComponentsBuilder.fromUriString("http://test.com/", parserType).build(); + UriComponents uri1 = UriComponentsBuilder.forURIString("http://test.com", parserType).build().normalize(); + UriComponents uri2 = UriComponentsBuilder.forURIString("http://test.com/", parserType).build(); assertThat(uri1.getPathSegments()).isEmpty(); assertThat(uri2.getPathSegments()).isEmpty(); @@ -835,8 +835,8 @@ void uriComponentsNotEqualAfterNormalization(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) void uriComponentsWithMergedQueryParams(ParserType parserType) { - String uri = UriComponentsBuilder.fromUriString("http://localhost:8081", parserType) - .uriComponents(UriComponentsBuilder.fromUriString("/{path}?sort={sort}", parserType).build()) + String uri = UriComponentsBuilder.forURIString("http://localhost:8081", parserType) + .uriComponents(UriComponentsBuilder.forURIString("/{path}?sort={sort}", parserType).build()) .queryParam("sort", "another_value").build().toString(); assertThat(uri).isEqualTo("http://localhost:8081/{path}?sort={sort}&sort=another_value"); @@ -844,29 +844,29 @@ void uriComponentsWithMergedQueryParams(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) - void toUriStringWithCurlyBraces(ParserType parserType) { - assertThat(UriComponentsBuilder.fromUriString("/path?q={asa}asa", parserType).toUriString()) + void toURIStringWithCurlyBraces(ParserType parserType) { + assertThat(UriComponentsBuilder.forURIString("/path?q={asa}asa", parserType).toUriString()) .isEqualTo("/path?q=%7Basa%7Dasa"); } @Test void verifyDoubleSlashReplacedWithSingleOne() { - String path = UriComponentsBuilder.fromPath("/home/").path("/path").build().getPath(); + String path = UriComponentsBuilder.forPath("/home/").path("/path").build().getPath(); assertThat(path).isEqualTo("/home/path"); } @ParameterizedTest @EnumSource(value = ParserType.class) void validPort(ParserType parserType) { - UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567/path", parserType).build(); + UriComponents uriComponents = UriComponentsBuilder.forURIString("http://localhost:52567/path", parserType).build(); assertThat(uriComponents.getPort()).isEqualTo(52567); assertThat(uriComponents.getPath()).isEqualTo("/path"); - uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567?trace=false", parserType).build(); + uriComponents = UriComponentsBuilder.forURIString("http://localhost:52567?trace=false", parserType).build(); assertThat(uriComponents.getPort()).isEqualTo(52567); assertThat(uriComponents.getQuery()).isEqualTo("trace=false"); - uriComponents = UriComponentsBuilder.fromUriString("http://localhost:52567#fragment", parserType).build(); + uriComponents = UriComponentsBuilder.forURIString("http://localhost:52567#fragment", parserType).build(); assertThat(uriComponents.getPort()).isEqualTo(52567); assertThat(uriComponents.getFragment()).isEqualTo("fragment"); } @@ -876,18 +876,18 @@ void validPort(ParserType parserType) { void verifyInvalidPort(ParserType parserType) { String url = "http://localhost:XXX/path"; assertThatIllegalArgumentException() - .isThrownBy(() -> UriComponentsBuilder.fromUriString(url, parserType).build().toUri()); + .isThrownBy(() -> UriComponentsBuilder.forURIString(url, parserType).build().toURI()); assertThatIllegalArgumentException() - .isThrownBy(() -> UriComponentsBuilder.fromUriString(url, parserType).build().toUri()); + .isThrownBy(() -> UriComponentsBuilder.forURIString(url, parserType).build().toURI()); } @ParameterizedTest @EnumSource(value = ParserType.class) void expandPortAndPathWithoutSeparator(ParserType parserType) { URI uri = UriComponentsBuilder - .fromUriString("ws://localhost:{port}/{path}", parserType) + .forURIString("ws://localhost:{port}/{path}", parserType) .buildAndExpand(7777, "test") - .toUri(); + .toURI(); assertThat(uri.toString()).isEqualTo("ws://localhost:7777/test"); } diff --git a/today-web/src/test/java/infra/web/util/UriComponentsTests.java b/today-web/src/test/java/infra/web/util/UriComponentsTests.java index ce717e5082..6570d49071 100755 --- a/today-web/src/test/java/infra/web/util/UriComponentsTests.java +++ b/today-web/src/test/java/infra/web/util/UriComponentsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ import infra.web.util.UriComponentsBuilder.ParserType; -import static infra.web.util.UriComponentsBuilder.fromUriString; +import static infra.web.util.UriComponentsBuilder.forURIString; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -49,7 +49,7 @@ class UriComponentsTests { @Test void expandAndEncode() { UriComponents uri = UriComponentsBuilder - .fromPath("/hotel list/{city} specials").queryParam("q", "{value}").build() + .forPath("/hotel list/{city} specials").queryParam("q", "{value}").build() .expand("Z\u00fcrich", "a+b").encode(); assertThat(uri.toString()).isEqualTo("/hotel%20list/Z%C3%BCrich%20specials?q=a+b"); @@ -58,7 +58,7 @@ void expandAndEncode() { @Test void encodeAndExpand() { UriComponents uri = UriComponentsBuilder - .fromPath("/hotel list/{city} specials").queryParam("q", "{value}").encode().build() + .forPath("/hotel list/{city} specials").queryParam("q", "{value}").encode().build() .expand("Z\u00fcrich", "a+b"); assertThat(uri.toString()).isEqualTo("/hotel%20list/Z%C3%BCrich%20specials?q=a%2Bb"); @@ -67,7 +67,7 @@ void encodeAndExpand() { @Test void encodeAndExpandPartially() { UriComponents uri = UriComponentsBuilder - .fromPath("/hotel list/{city} specials").queryParam("q", "{value}").encode() + .forPath("/hotel list/{city} specials").queryParam("q", "{value}").encode() .uriVariables(Collections.singletonMap("city", "Z\u00fcrich")).build(); assertThat(uri.expand("a+b").toString()).isEqualTo("/hotel%20list/Z%C3%BCrich%20specials?q=a%2Bb"); @@ -76,52 +76,52 @@ void encodeAndExpandPartially() { @Test // void encodeAndExpandWithDollarSign() { - UriComponents uri = UriComponentsBuilder.fromPath("/path").queryParam("q", "{value}").encode().build(); + UriComponents uri = UriComponentsBuilder.forPath("/path").queryParam("q", "{value}").encode().build(); assertThat(uri.expand("JavaClass$1.class").toString()).isEqualTo("/path?q=JavaClass%241.class"); } @ParameterizedTest @EnumSource(value = ParserType.class) - void toUriEncoded(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("https://example.com/hotel list/Z\u00fcrich", parserType).build(); - assertThat(uri.encode().toUri()).isEqualTo(URI.create("https://example.com/hotel%20list/Z%C3%BCrich")); + void toURIEncoded(ParserType parserType) { + UriComponents uri = UriComponentsBuilder.forURIString("https://example.com/hotel list/Z\u00fcrich", parserType).build(); + assertThat(uri.encode().toURI()).isEqualTo(URI.create("https://example.com/hotel%20list/Z%C3%BCrich")); } @ParameterizedTest @EnumSource(value = ParserType.class) - void toUriNotEncoded(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("https://example.com/hotel list/Z\u00fcrich", parserType).build(); - assertThat(uri.toUri()).isEqualTo(URI.create("https://example.com/hotel%20list/Z\u00fcrich")); + void toURINotEncoded(ParserType parserType) { + UriComponents uri = UriComponentsBuilder.forURIString("https://example.com/hotel list/Z\u00fcrich", parserType).build(); + assertThat(uri.toURI()).isEqualTo(URI.create("https://example.com/hotel%20list/Z\u00fcrich")); } @ParameterizedTest @EnumSource(value = ParserType.class) - void toUriAlreadyEncoded(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("https://example.com/hotel%20list/Z%C3%BCrich", parserType).build(true); - assertThat(uri.encode().toUri()).isEqualTo(URI.create("https://example.com/hotel%20list/Z%C3%BCrich")); + void toURIAlreadyEncoded(ParserType parserType) { + UriComponents uri = UriComponentsBuilder.forURIString("https://example.com/hotel%20list/Z%C3%BCrich", parserType).build(true); + assertThat(uri.encode().toURI()).isEqualTo(URI.create("https://example.com/hotel%20list/Z%C3%BCrich")); } @ParameterizedTest @EnumSource(value = ParserType.class) - void toUriWithIpv6HostAlreadyEncoded(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString( + void toURIWithIpv6HostAlreadyEncoded(ParserType parserType) { + UriComponents uri = UriComponentsBuilder.forURIString( "http://[1abc:2abc:3abc::5ABC:6abc]:8080/hotel%20list/Z%C3%BCrich", parserType).build(true); - assertThat(uri.encode().toUri()).isEqualTo( + assertThat(uri.encode().toURI()).isEqualTo( URI.create("http://[1abc:2abc:3abc::5ABC:6abc]:8080/hotel%20list/Z%C3%BCrich")); } @ParameterizedTest @EnumSource(value = ParserType.class) - void toUriStringWithPortVariable(ParserType parserType) { + void toURIStringWithPortVariable(ParserType parserType) { String url = "http://localhost:{port}/first"; - assertThat(UriComponentsBuilder.fromUriString(url, parserType).build().toUriString()).isEqualTo(url); + assertThat(UriComponentsBuilder.forURIString(url, parserType).build().toUriString()).isEqualTo(url); } @ParameterizedTest @EnumSource(value = ParserType.class) void expand(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("https://example.com", parserType).path("/{foo} {bar}").build(); + UriComponents uri = UriComponentsBuilder.forURIString("https://example.com", parserType).path("/{foo} {bar}").build(); uri = uri.expand("1 2", "3 4"); assertThat(uri.getPath()).isEqualTo("/1 2 3 4"); @@ -132,7 +132,7 @@ void expand(ParserType parserType) { @EnumSource(value = ParserType.class) void expandWithRegexVar(ParserType parserType) { String template = "/myurl/{name:[a-z]{1,5}}/show"; - UriComponents uri = UriComponentsBuilder.fromUriString(template, parserType).build(); + UriComponents uri = UriComponentsBuilder.forURIString(template, parserType).build(); uri = uri.expand(Collections.singletonMap("name", "test")); assertThat(uri.getPath()).isEqualTo("/myurl/test/show"); @@ -141,7 +141,7 @@ void expandWithRegexVar(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) void uirTemplateExpandWithMismatchedCurlyBraces(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("/myurl/?q={{{{", parserType).encode().build(); + UriComponents uri = UriComponentsBuilder.forURIString("/myurl/?q={{{{", parserType).encode().build(); assertThat(uri.toUriString()).isEqualTo("/myurl/?q=%7B%7B%7B%7B"); } @@ -149,7 +149,7 @@ void uirTemplateExpandWithMismatchedCurlyBraces(ParserType parserType) { @EnumSource(value = ParserType.class) void expandWithFragmentOrder(ParserType parserType) { UriComponents uri = UriComponentsBuilder - .fromUriString("https://{host}/{path}#{fragment}", parserType).build() + .forURIString("https://{host}/{path}#{fragment}", parserType).build() .expand("example.com", "foo", "bar"); assertThat(uri.toUriString()).isEqualTo("https://example.com/foo#bar"); @@ -158,10 +158,10 @@ void expandWithFragmentOrder(ParserType parserType) { @ParameterizedTest // @EnumSource(value = ParserType.class) void port(ParserType parserType) { - UriComponents uri1 = fromUriString("https://example.com:8080/bar", parserType).build(); - UriComponents uri2 = fromUriString("https://example.com/bar", parserType).port(8080).build(); - UriComponents uri3 = fromUriString("https://example.com/bar", parserType).port("{port}").build().expand(8080); - UriComponents uri4 = fromUriString("https://example.com/bar", parserType).port("808{digit}").build().expand(0); + UriComponents uri1 = forURIString("https://example.com:8080/bar", parserType).build(); + UriComponents uri2 = forURIString("https://example.com/bar", parserType).port(8080).build(); + UriComponents uri3 = forURIString("https://example.com/bar", parserType).port("{port}").build().expand(8080); + UriComponents uri4 = forURIString("https://example.com/bar", parserType).port("808{digit}").build().expand(0); assertThat(uri1.getPort()).isEqualTo(8080); assertThat(uri1.toUriString()).isEqualTo("https://example.com:8080/bar"); @@ -177,8 +177,8 @@ void port(ParserType parserType) { @EnumSource(value = ParserType.class) void invalidPort(ParserType parserType) { assertThatExceptionOfType(InvalidUrlException.class) - .isThrownBy(() -> fromUriString("https://example.com:XXX/bar", parserType)); - assertExceptionsForInvalidPort(fromUriString("https://example.com/bar", parserType).port("XXX").build()); + .isThrownBy(() -> forURIString("https://example.com:XXX/bar", parserType)); + assertExceptionsForInvalidPort(forURIString("https://example.com/bar", parserType).port("XXX").build()); } private void assertExceptionsForInvalidPort(UriComponents uriComponents) { @@ -186,39 +186,39 @@ private void assertExceptionsForInvalidPort(UriComponents uriComponents) { .isThrownBy(uriComponents::getPort) .withMessage("The port must be an integer: XXX"); assertThatIllegalStateException() - .isThrownBy(uriComponents::toUri) + .isThrownBy(uriComponents::toURI) .withMessage("The port must be an integer: XXX"); } @Test void expandEncoded() { assertThatIllegalStateException().isThrownBy(() -> - UriComponentsBuilder.fromPath("/{foo}").build().encode().expand("bar")); + UriComponentsBuilder.forPath("/{foo}").build().encode().expand("bar")); } @Test void invalidCharacters() { assertThatIllegalArgumentException().isThrownBy(() -> - UriComponentsBuilder.fromPath("/{foo}").build(true)); + UriComponentsBuilder.forPath("/{foo}").build(true)); } @Test void invalidEncodedSequence() { assertThatIllegalArgumentException().isThrownBy(() -> - UriComponentsBuilder.fromPath("/fo%2o").build(true)); + UriComponentsBuilder.forPath("/fo%2o").build(true)); } @ParameterizedTest @EnumSource(value = ParserType.class) void normalize(ParserType parserType) { - UriComponents uri = UriComponentsBuilder.fromUriString("https://example.com/foo/../bar", parserType).build(); + UriComponents uri = UriComponentsBuilder.forURIString("https://example.com/foo/../bar", parserType).build(); assertThat(uri.normalize().toString()).isEqualTo("https://example.com/bar"); } @ParameterizedTest @EnumSource(value = ParserType.class) void serializable(ParserType parserType) throws Exception { - UriComponents uri = UriComponentsBuilder.fromUriString( + UriComponents uri = UriComponentsBuilder.forURIString( "https://example.com", parserType).path("/{foo}").query("bar={baz}").build(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -231,9 +231,9 @@ void serializable(ParserType parserType) throws Exception { } @Test - void copyToUriComponentsBuilder() { - UriComponents source = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z").build(); - UriComponentsBuilder targetBuilder = UriComponentsBuilder.newInstance(); + void copyToURIComponentsBuilder() { + UriComponents source = UriComponentsBuilder.forPath("/foo/bar").pathSegment("ba/z").build(); + UriComponentsBuilder targetBuilder = UriBuilder.forUriComponents(); source.copyToUriComponentsBuilder(targetBuilder); UriComponents result = targetBuilder.build().encode(); @@ -245,9 +245,9 @@ void copyToUriComponentsBuilder() { @EnumSource(value = ParserType.class) void equalsHierarchicalUriComponents(ParserType parserType) { String url = "https://example.com"; - UriComponents uric1 = UriComponentsBuilder.fromUriString(url, parserType).path("/{foo}").query("bar={baz}").build(); - UriComponents uric2 = UriComponentsBuilder.fromUriString(url, parserType).path("/{foo}").query("bar={baz}").build(); - UriComponents uric3 = UriComponentsBuilder.fromUriString(url, parserType).path("/{foo}").query("bin={baz}").build(); + UriComponents uric1 = UriComponentsBuilder.forURIString(url, parserType).path("/{foo}").query("bar={baz}").build(); + UriComponents uric2 = UriComponentsBuilder.forURIString(url, parserType).path("/{foo}").query("bar={baz}").build(); + UriComponents uric3 = UriComponentsBuilder.forURIString(url, parserType).path("/{foo}").query("bin={baz}").build(); assertThat(uric1).isInstanceOf(HierarchicalUriComponents.class); assertThat(uric1).isEqualTo(uric1); @@ -259,9 +259,9 @@ void equalsHierarchicalUriComponents(ParserType parserType) { @EnumSource(value = ParserType.class) void equalsOpaqueUriComponents(ParserType parserType) { String baseUrl = "http:example.com"; - UriComponents uric1 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bar", parserType).build(); - UriComponents uric2 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bar", parserType).build(); - UriComponents uric3 = UriComponentsBuilder.fromUriString(baseUrl + "/foo/bin", parserType).build(); + UriComponents uric1 = UriComponentsBuilder.forURIString(baseUrl + "/foo/bar", parserType).build(); + UriComponents uric2 = UriComponentsBuilder.forURIString(baseUrl + "/foo/bar", parserType).build(); + UriComponents uric3 = UriComponentsBuilder.forURIString(baseUrl + "/foo/bin", parserType).build(); assertThat(uric1).isEqualTo(uric1); assertThat(uric1).isEqualTo(uric2); diff --git a/today-web/src/testFixtures/java/infra/web/testfixture/http/MockClientHttpRequest.java b/today-web/src/testFixtures/java/infra/web/testfixture/http/MockClientHttpRequest.java index 87218b02b4..b7b1427e1a 100644 --- a/today-web/src/testFixtures/java/infra/web/testfixture/http/MockClientHttpRequest.java +++ b/today-web/src/testFixtures/java/infra/web/testfixture/http/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,7 +68,7 @@ public MockClientHttpRequest() { * URI template, and URI template variable values. */ public MockClientHttpRequest(HttpMethod httpMethod, String uriTemplate, Object... vars) { - this(httpMethod, UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(vars).encode().toUri()); + this(httpMethod, UriComponentsBuilder.forURIString(uriTemplate).buildAndExpand(vars).encode().toURI()); } /** diff --git a/today-web/src/testFixtures/java/infra/web/testfixture/http/client/reactive/MockClientHttpRequest.java b/today-web/src/testFixtures/java/infra/web/testfixture/http/client/reactive/MockClientHttpRequest.java index 52fa9b7963..600a029f29 100755 --- a/today-web/src/testFixtures/java/infra/web/testfixture/http/client/reactive/MockClientHttpRequest.java +++ b/today-web/src/testFixtures/java/infra/web/testfixture/http/client/reactive/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,7 +61,7 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest implements private Function, Mono> writeHandler; public MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars) { - this(httpMethod, UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(vars).encode().toUri()); + this(httpMethod, UriComponentsBuilder.forURIString(urlTemplate).buildAndExpand(vars).encode().toURI()); } public MockClientHttpRequest(HttpMethod httpMethod, URI url) { diff --git a/today-web/src/testFixtures/java/infra/web/testfixture/http/server/reactive/MockServerHttpRequest.java b/today-web/src/testFixtures/java/infra/web/testfixture/http/server/reactive/MockServerHttpRequest.java index f195a41efb..7c335a65b8 100755 --- a/today-web/src/testFixtures/java/infra/web/testfixture/http/server/reactive/MockServerHttpRequest.java +++ b/today-web/src/testFixtures/java/infra/web/testfixture/http/server/reactive/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -248,7 +248,7 @@ public static BodyBuilder method(String httpMethod, String uri, Object... vars) } private static URI toUri(String uri, Object[] vars) { - return UriComponentsBuilder.fromUriString(uri).buildAndExpand(vars).encode().toUri(); + return UriComponentsBuilder.forURIString(uri).buildAndExpand(vars).encode().toURI(); } /** @@ -450,7 +450,7 @@ private static class DefaultBodyBuilder implements BodyBuilder { @Nullable private String contextPath; - private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); + private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.create(); private final HttpHeaders headers = HttpHeaders.forWritable(); @@ -620,7 +620,7 @@ private URI getUrlToUse() { MultiValueMap params = this.queryParamsBuilder.buildAndExpand().encode().getQueryParams(); if (!params.isEmpty()) { - return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri(); + return UriComponentsBuilder.forURI(this.url).queryParams(params).build(true).toURI(); } return this.url; } diff --git a/today-websocket/src/main/java/infra/web/socket/client/ConnectionManagerSupport.java b/today-websocket/src/main/java/infra/web/socket/client/ConnectionManagerSupport.java index 8fd29763cf..0518a43532 100755 --- a/today-websocket/src/main/java/infra/web/socket/client/ConnectionManagerSupport.java +++ b/today-websocket/src/main/java/infra/web/socket/client/ConnectionManagerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,10 +50,10 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { private final Object lifecycleMonitor = new Object(); public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) { - this.uri = UriComponentsBuilder.fromUriString(uriTemplate) + this.uri = UriComponentsBuilder.forURIString(uriTemplate) .buildAndExpand(uriVariables) .encode() - .toUri(); + .toURI(); } /** diff --git a/today-websocket/src/main/java/infra/web/socket/client/WebSocketClient.java b/today-websocket/src/main/java/infra/web/socket/client/WebSocketClient.java index ea33ff22ea..d8fbd26ca4 100755 --- a/today-websocket/src/main/java/infra/web/socket/client/WebSocketClient.java +++ b/today-websocket/src/main/java/infra/web/socket/client/WebSocketClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2024 the original author or authors. + * Copyright 2017 - 2025 the original author or authors. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,7 +64,7 @@ default Future connect(UriBuilder uri, @Nullable HttpHeaders h * @since 5.0 */ default Future connect(UriComponents uri, @Nullable HttpHeaders headers, WebSocketHandler handler) { - return connect(uri.toUri(), headers, handler); + return connect(uri.toURI(), headers, handler); } /** @@ -78,7 +78,7 @@ default Future connect(UriComponents uri, @Nullable HttpHeader */ default Future connect(WebSocketHandler handler, String uriTemplate, Object... uriVariables) { Assert.notNull(uriTemplate, "'uriTemplate' is required"); - URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri(); + URI uri = UriComponentsBuilder.forURIString(uriTemplate).buildAndExpand(uriVariables).encode().toURI(); return connect(uri, null, handler); }