URI uri = new URI( "http", "www.google.com", "/ig/api", "weather=São Paulo", null); String request = uri.toASCIIString();
@Override public URI put(String key, Map<String, String> endpointDetails, URI defaultEndpoint) { loadAndScheduleRefresh(key, Long.valueOf(endpointDetails.get(Constants.CACHE_PERIOD)), defaultEndpoint); URI discoveredEndpoint = URI.create(String.format("%s://%s", defaultEndpoint.getScheme(), endpointDetails.get(Constants.ENDPOINT))); log.debug("Cached new endpoint from service: " + discoveredEndpoint.toASCIIString()); log.debug("Refresh scheduled in: " + endpointDetails.get(Constants.CACHE_PERIOD) + " minutes"); return cache.put(key, discoveredEndpoint); } }
@Test public void testCreateExternalTable() throws Exception { File tempDir = createTempDir(); File dataFile = new File(tempDir, "test.txt"); Files.write("hello\nworld\n", dataFile, UTF_8); @Language("SQL") String createTableSql = format("" + "CREATE TABLE %s.%s.test_create_external (\n" + " name varchar\n" + ")\n" + "WITH (\n" + " external_location = '%s',\n" + " format = 'TEXTFILE'\n" + ")", getSession().getCatalog().get(), getSession().getSchema().get(), new Path(tempDir.toURI().toASCIIString()).toString()); assertUpdate(createTableSql); MaterializedResult actual = computeActual("SHOW CREATE TABLE test_create_external"); assertEquals(actual.getOnlyValue(), createTableSql); actual = computeActual("SELECT name FROM test_create_external"); assertEquals(actual.getOnlyColumnAsSet(), ImmutableSet.of("hello", "world")); assertUpdate("DROP TABLE test_create_external"); // file should still exist after drop assertFile(dataFile); deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); }
@Test public void testReplaceParameters() { URI uri = uriBuilderFrom(URI.create("http://www.example.com:8081/?k1=1&k1=2&k2=3")) .replaceParameter("k1", "4") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com:8081/?k2=3&k1=4"); }
@Test public void testReplaceParameterMultivalued() { URI uri = uriBuilderFrom(URI.create("http://www.example.com/?k1=1&k1=2&k2=3")) .replaceParameter("k1", "a", "b", "c") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/?k2=3&k1=a&k1=b&k1=c"); }
URI uri = new URI( "http", "search.barnesandnoble.com", "/booksearch/é", null); String request = uri.toASCIIString();
String name = URI.create(issuer).getHost(); ClientAuthenticationMethod method = getClientAuthenticationMethod(issuer, metadata.getTokenEndpointAuthMethods()); List<GrantType> grantTypes = metadata.getGrantTypes(); .clientAuthenticationMethod(method) .redirectUriTemplate("{baseUrl}/{action}/oauth2/code/{registrationId}") .authorizationUri(metadata.getAuthorizationEndpointURI().toASCIIString()) .jwkSetUri(metadata.getJWKSetURI().toASCIIString()) .providerConfigurationMetadata(configurationMetadata) .userInfoUri(metadata.getUserInfoEndpointURI().toASCIIString()) .tokenUri(metadata.getTokenEndpointURI().toASCIIString()) .clientName(issuer);
@Test public void testDefaultPort() { URI uri = uriBuilderFrom(URI.create("http://www.example.com:8081")) .defaultPort() .build(); assertEquals(uri.toASCIIString(), "http://www.example.com"); }
/** * Encodes the URL by RFC 2396. * * I thought there's another spec that refers to UTF-8 as the encoding, * but don't remember it right now. * * @since 1.204 * @deprecated since 2008-05-13. This method is broken (see ISSUE#1666). It should probably * be removed but I'm not sure if it is considered part of the public API * that needs to be maintained for backwards compatibility. * Use {@link #encode(String)} instead. */ @Deprecated public static String encodeRFC2396(String url) { try { return new URI(null,url,null).toASCIIString(); } catch (URISyntaxException e) { LOGGER.log(Level.WARNING, "Failed to encode {0}", url); // could this ever happen? return url; } }
@Test public void filterWhenDefaultClientRegistrationIdThenAuthorizedClientResolved() { this.function.setDefaultClientRegistrationId(this.registration.getRegistrationId()); OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); when(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).thenReturn(Mono.just(authorizedClient)); when(this.clientRegistrationRepository.findByRegistrationId(any())).thenReturn(Mono.just(this.registration)); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void testReplaceParameterMultivalued() { URI uri = uriBuilderFrom(URI.create("http://www.example.com/?k1=1&k1=2&k2=3")) .replaceParameter("k1", "a", "b", "c") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/?k2=3&k1=a&k1=b&k1=c"); }
static URL encodeUrl(URL u) { try { // odd way to encode urls, but it works! String urlS = u.toExternalForm(); // URL external form may have spaces which is illegal in new URL() (odd asymmetry) urlS = urlS.replaceAll(" ", "%20"); final URI uri = new URI(urlS); return new URL(uri.toASCIIString()); } catch (Exception e) { return u; } }
@Test public void filterWhenClientRegistrationIdThenAuthorizedClientResolved() { OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); when(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).thenReturn(Mono.just(authorizedClient)); when(this.clientRegistrationRepository.findByRegistrationId(any())).thenReturn(Mono.just(this.registration)); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(clientRegistrationId(this.registration.getRegistrationId())) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void testReplaceParameters() { URI uri = HttpUriBuilder.uriBuilderFrom(URI.create("http://www.example.com:8081/?k1=1&k1=2&k2=3")) .replaceParameter("k1", "4") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com:8081/?k2=3&k1=4"); }
URI uri = new URI(null, null, "árvíztűrőtükörfúrógép.xls", null); System.out.println(uri.toASCIIString());
@Test public void filterWhenRefreshTokenNullThenShouldRefreshFalse() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void testReplaceParameterMultivalued() { URI uri = HttpUriBuilder.uriBuilderFrom(URI.create("http://www.example.com/?k1=1&k1=2&k2=3")) .replaceParameter("k1", "a", "b", "c") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/?k2=3&k1=a&k1=b&k1=c"); }
/** * Normalize a URI/part name * TODO: find a better way ... */ private static String normalizePartName(URI partName, String baseUri) throws XMLSignatureException { String pn = partName.toASCIIString(); if (!pn.startsWith(baseUri)) { pn = baseUri + pn; } try { pn = new URI(pn).normalize().getPath().replace('\\', '/'); LOG.log(POILogger.DEBUG, "part name: " + pn); } catch (URISyntaxException e) { throw new XMLSignatureException(e); } return pn; }
@Test public void filterWhenRefreshTokenNullThenShouldRefreshFalse() { this.function = new ServletOAuth2AuthorizedClientExchangeFilterFunction(this.clientRegistrationRepository, this.authorizedClientRepository); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void testDefaultPort() { URI uri = HttpUriBuilder.uriBuilderFrom(URI.create("http://www.example.com:8081")) .defaultPort() .build(); assertEquals(uri.toASCIIString(), "http://www.example.com"); }