本文整理了Java中java.net.URI.create()
方法的一些代码示例,展示了URI.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URI.create()
方法的具体详情如下:
包路径:java.net.URI
类名称:URI
方法名:create
[英]Returns the URI formed by parsing uri. This method behaves identically to the string constructor but throws a different exception on failure. The constructor fails with a checked URISyntaxException; this method fails with an unchecked IllegalArgumentException.
[中]返回通过解析URI形成的URI。此方法的行为与字符串构造函数相同,但在失败时抛出不同的异常。构造函数失败,出现选中的URISyntaxException;此方法因未检查的IllegalArgumentException而失败。
代码示例来源:origin: jenkinsci/jenkins
private static String normalizeURI(String uri) {
return URI.create(uri).normalize().toString();
}
代码示例来源:origin: prestodb/presto
@Test(groups = {TLS, PROFILE_SPECIFIC_TESTS})
public void testHttpPortIsClosed()
throws Exception
{
assertThat(httpPort).isNotNull();
assertThat(httpsPort).isNotNull();
waitForNodeRefresh();
List<String> activeNodesUrls = getActiveNodesUrls();
assertThat(activeNodesUrls).hasSize(3);
List<String> hosts = activeNodesUrls.stream()
.map((uri) -> URI.create(uri).getHost())
.collect(toList());
for (String host : hosts) {
assertPortIsOpen(host, httpsPort);
assertPortIsClosed(host, httpPort);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void postMono() {
URI uri = URI.create("http://localhost:" + port + "/mono");
Person person = new Person("Jack");
RequestEntity<Person> requestEntity = RequestEntity.post(uri).body(person);
ResponseEntity<Person> result = restTemplate.exchange(requestEntity, Person.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Jack", result.getBody().getName());
}
代码示例来源:origin: org.kie.commons/kie-nio2-jgit
@Test
public void testInvalidURIGetFileSystem() {
final URI newRepo = URI.create( "git:///new-repo-name" );
try {
PROVIDER.getFileSystem( newRepo );
failBecauseExceptionWasNotThrown( IllegalArgumentException.class );
} catch ( final IllegalArgumentException ex ) {
assertThat( ex.getMessage() ).isEqualTo( "Parameter named 'uri' is invalid, missing host repository!" );
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testRewriteURI()
{
DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class);
EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port");
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(request.getQueryString()).andReturn("param1=test¶m2=test2").anyTimes();
// %3A is a colon; test to make sure urlencoded paths work right.
EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes();
EasyMock.replay(druidLeaderClient, request);
URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request));
Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test¶m2=test2", uri.toString());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void pathPredicates() {
PathPatternParser parser = new PathPatternParser();
parser.setCaseSensitive(false);
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
URI uri = URI.create("http://localhost/path");
RequestPredicate predicate = pathPredicates.apply("/P*");
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
assertTrue(predicate.test(request));
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader()
{
// given
final String xForwardHostAndPort = "jimwebber.org:1234";
XForwardFilter filter = new XForwardFilter();
InBoundHeaders headers = new InBoundHeaders();
headers.add( X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort );
ContainerRequest request = new ContainerRequest( WEB_APPLICATION, "GET",
URI.create( "http://iansrobinson.com" ), URI.create( "http://iansrobinson.com/foo/bar" ),
headers, INPUT_STREAM );
// when
ContainerRequest result = filter.filter( request );
// then
assertThat( result.getBaseUri().toString(), containsString( xForwardHostAndPort ) );
}
代码示例来源:origin: prestodb/presto
@Test
public void testExplicitPropertyMappingsMultipleMetastores()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("hive.metastore.uri", "thrift://localhost:9083,thrift://192.0.2.3:8932")
.put("hive.metastore.username", "presto")
.build();
StaticMetastoreConfig expected = new StaticMetastoreConfig()
.setMetastoreUris("thrift://localhost:9083,thrift://192.0.2.3:8932")
.setMetastoreUsername("presto");
assertFullMapping(properties, expected);
assertEquals(expected.getMetastoreUris(), ImmutableList.of(
URI.create("thrift://localhost:9083"),
URI.create("thrift://192.0.2.3:8932")));
assertEquals(expected.getMetastoreUsername(), "presto");
}
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testListVolumes() {
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes");
VolumeApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<? extends Volume> volumes = api.list().toSet();
assertEquals(volumes, ImmutableSet.of(testVolume()));
}
代码示例来源:origin: prestodb/presto
private void testSetSessionWithParameters(String property, Expression expression, String expectedValue, List<Expression> parameters)
{
QualifiedName qualifiedPropName = QualifiedName.of(CATALOG_NAME, property);
QueryStateMachine stateMachine = QueryStateMachine.begin(
format("set %s = 'old_value'", qualifiedPropName),
TEST_SESSION,
URI.create("fake://uri"),
new ResourceGroupId("test"),
false,
transactionManager,
accessControl,
executor,
metadata,
WarningCollector.NOOP);
getFutureValue(new SetSessionTask().execute(new SetSession(qualifiedPropName, expression), transactionManager, metadata, accessControl, stateMachine, parameters));
Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
assertEquals(sessionProperties, ImmutableMap.of(qualifiedPropName.toString(), expectedValue));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void forwardedHeaders() {
// One integration test to verify triggering of Forwarded header support.
// More fine-grained tests in ForwardedHeaderTransformerTests.
RequestEntity<Void> request = RequestEntity
.get(URI.create("http://localhost:" + this.port + "/uri"))
.header("Forwarded", "host=84.198.58.199;proto=https")
.build();
ResponseEntity<String> entity = getRestTemplate().exchange(request, String.class);
assertEquals("https://84.198.58.199/uri", entity.getBody());
}
代码示例来源:origin: org.kie.commons/kie-nio2-fs
@Test
public void checkNewInputStream() throws IOException {
final File temp = File.createTempFile( "foo", "bar" );
final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider();
final Path path = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), temp );
final InputStream stream = fsProvider.newInputStream( path );
assertThat( stream ).isNotNull();
stream.close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void captureAndClaim() {
ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test");
ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response));
ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build();
WiretapConnector wiretapConnector = new WiretapConnector(connector);
ExchangeFunction function = ExchangeFunctions.create(wiretapConnector);
function.exchange(clientRequest).block(ofMillis(0));
WiretapConnector.Info actual = wiretapConnector.claimRequest("1");
ExchangeResult result = actual.createExchangeResult(Duration.ZERO, null);
assertEquals(HttpMethod.GET, result.getMethod());
assertEquals("/test", result.getUrl().toString());
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
protected URI removeFragment(URI id) {
return URI.create(substringBefore(id.toString(), "#"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void created() {
URI location = URI.create("http://example.com");
Mono<ServerResponse> result = ServerResponse.created(location).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()) &&
location.equals(response.headers().getLocation()))
.expectComplete()
.verify();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader()
{
// given
final String xForwardHostAndPort = "jimwebber.org:1234";
XForwardFilter filter = new XForwardFilter();
InBoundHeaders headers = new InBoundHeaders();
headers.add( X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort );
ContainerRequest request = new ContainerRequest( WEB_APPLICATION, "GET",
URI.create( "http://iansrobinson.com" ), URI.create( "http://iansrobinson.com/foo/bar" ),
headers, INPUT_STREAM );
// when
ContainerRequest result = filter.filter( request );
// then
assertTrue( result.getRequestUri().toString().startsWith( "http://" + xForwardHostAndPort ) );
}
代码示例来源:origin: prestodb/presto
@Test
public void testExplicitPropertyMappingsSingleMetastore()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("hive.metastore.uri", "thrift://localhost:9083")
.put("hive.metastore.username", "presto")
.build();
StaticMetastoreConfig expected = new StaticMetastoreConfig()
.setMetastoreUris("thrift://localhost:9083")
.setMetastoreUsername("presto");
assertFullMapping(properties, expected);
assertEquals(expected.getMetastoreUris(), ImmutableList.of(URI.create("thrift://localhost:9083")));
assertEquals(expected.getMetastoreUsername(), "presto");
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testListSnapshots() {
URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots");
VolumeApi api = requestsSendResponses(
keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<? extends VolumeSnapshot> snapshots = api.listSnapshots().toSet();
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
}
代码示例来源:origin: prestodb/presto
@Test
public void testExplicitPropertyMappings()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("metadata-uri", "file://test.json")
.build();
ExampleConfig expected = new ExampleConfig()
.setMetadata(URI.create("file://test.json"));
ConfigAssertions.assertFullMapping(properties, expected);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void expandUriTemplateVariablesFromExchangeAttribute() {
String url = "http://url.somewhere.com?foo={foo}";
Map<String, String> attributes = Collections.singletonMap("foo", "bar");
this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, attributes);
RedirectView view = new RedirectView(url);
view.render(new HashMap<>(), MediaType.TEXT_HTML, exchange).block();
assertEquals(URI.create("http://url.somewhere.com?foo=bar"), this.exchange.getResponse().getHeaders().getLocation());
}
内容来源于网络,如有侵权,请联系作者删除!