Java Code Examples for java.net.URI#create()

The following examples show how to use java.net.URI#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTapeArchiveChartWriter.java    From microbean-helm with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
  // Chart is arbitrary, but it does have subcharts in it, which exercise some tricky logic
  final URI uri = URI.create("https://kubernetes-charts.storage.googleapis.com/wordpress-0.6.6.tgz");
  assertNotNull(uri);
  final URL url = uri.toURL();
  assertNotNull(url);
  try (final URLChartLoader loader = new URLChartLoader()) {
    this.chart = loader.load(url);
  }
  assertNotNull(this.chart);
  final Path buildDirectory = Paths.get(System.getProperty("project.build.directory"));
  assertNotNull(buildDirectory);
  assertTrue(Files.isDirectory(buildDirectory));
  assertTrue(Files.isWritable(buildDirectory));
  this.buildDirectory = buildDirectory;
}
 
Example 2
Source File: Origin.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
public Origin(String originUrl) {
    URI uri = URI.create(originUrl);
    this.scheme = uri.getScheme();
    this.host = uri.getHost();
    int originPort = uri.getPort();

    if (originPort == -1) {
        if (this.scheme == null) {
            throw new IllegalArgumentException(SCHEME_ERROR_MESSAGE);
        }
        switch (this.scheme) {
            case SCHEME_HTTPS:
                originPort = 443;
                break;
            case SCHEME_HTTP:
                originPort = 80;
                break;
            default:
                throw new IllegalArgumentException(SCHEME_ERROR_MESSAGE);
        }
    }
    this.port = originPort;
}
 
Example 3
Source File: GitlabDataGrabber.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * This method tries to get a repository from GitLab.
 * 
 * @param repoName
 * @param repoOwner
 * @param botToken
 * @param apiLink
 * @throws GitLabAPIException
 */
public GitLabRepository checkRepository(String repoName, String repoOwner, String botToken, String apiLink)
		throws GitLabAPIException {

	// Build URI
	URI gitlabURI = null;

	if (apiLink == null || apiLink.isEmpty()) {
		gitlabURI = URI.create(GITLAB_DEFAULT_APILINK + "/projects/" + repoOwner + "%2F" + repoName);
	} else {
		gitlabURI = URI.create(apiLink + "/projects/" + repoOwner + "%2F" + repoName);
	}

	RestTemplate rest = new RestTemplate();

	HttpHeaders headers = new HttpHeaders();
	headers.set("User-Agent", USER_AGENT);
	headers.set(TOKEN_HEADER, botToken);
	HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

	try {
		// Send request to the GitLab-API
		return rest.exchange(gitlabURI, HttpMethod.GET, entity, GitLabRepository.class).getBody();
	} catch (RestClientException e) {
		logger.error(e.getMessage(), e);
		throw new GitLabAPIException("Repository does not exist on GitLab or invalid Bot-Token!", e);
	}
}
 
Example 4
Source File: DataFlowIT.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before() {
	dataFlowOperations = new DataFlowTemplate(URI.create(testProperties.getDataflowServerUrl()));
	runtimeApps = new RuntimeApplicationHelper(dataFlowOperations,
			testProperties.getPlatformName(), testProperties.getKubernetesAppHostSuffix());
	tasks = new Tasks(dataFlowOperations);
	restTemplate = new RestTemplate(); // used for HTTP post in tests

	Awaitility.setDefaultPollInterval(Duration.ofSeconds(5));
	Awaitility.setDefaultTimeout(Duration.ofMinutes(10));
}
 
Example 5
Source File: HttpClientTest.java    From zsync4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testTransferListener() throws IOException, HttpError {
  final URI uri = URI.create("http://host/bla");

  final byte[] data = new byte[17];
  final ResponseBody body = mock(ResponseBody.class);
  when(body.contentLength()).thenReturn((long) data.length);
  when(body.source()).thenReturn(mock(BufferedSource.class));
  final InputStream inputStream = new ByteArrayInputStream(data);
  when(body.byteStream()).thenReturn(inputStream);

  final Request request = new Request.Builder().url(uri.toString()).build();
  final Response response = new Response.Builder().protocol(HTTP_1_1).body(body).request(request).code(200).build();

  final Call mockCall = mock(Call.class);
  when(mockCall.execute()).thenReturn(response);
  final OkHttpClient mockHttpClient = mock(OkHttpClient.class);
  when(mockHttpClient.newCall(any(Request.class))).thenReturn(mockCall);

  final EventLogHttpTransferListener listener = new EventLogHttpTransferListener();
  final InputStream in =
      new HttpClient(mockHttpClient).get(uri, Collections.<String, Credentials>emptyMap(), listener);
  final byte[] b = new byte[8];
  assertEquals(0, in.read());
  assertEquals(8, in.read(b));
  assertEquals(8, in.read(b, 0, 8));
  assertEquals(-1, in.read());
  in.close();

  final List<Event> events =
      ImmutableList.of(new Initialized(new Request.Builder().url(uri.toString()).build()), new Started(uri,
          data.length), new Transferred(1), new Transferred(8), new Transferred(8), Closed.INSTANCE);
  assertEquals(events, listener.getEventLog());
}
 
Example 6
Source File: Services.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/GetDefaultColor()")
public Response functionGetDefaultColor(
    @HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
    @QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {

  try {
    final Accept acceptType;
    if (StringUtils.isNotBlank(format)) {
      acceptType = Accept.valueOf(format.toUpperCase());
    } else {
      acceptType = Accept.parse(accept);
    }

    final Property property = new Property();
    property.setType("Microsoft.Test.OData.Services.ODataWCFService.Color");
    property.setValue(ValueType.ENUM, "Red");
    final ResWrap<Property> container = new ResWrap<Property>(
        URI.create(Constants.get(ConstantKey.ODATA_METADATA_PREFIX) + property.getType()), null,
        property);

    return xml.createResponse(
        null,
        xml.writeProperty(acceptType, container),
        null,
        acceptType);
  } catch (Exception e) {
    return xml.createFaultResponse(accept, e);
  }
}
 
Example 7
Source File: BagItIT.java    From fcrepo-import-export with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportSerializedBag() throws FcrepoOperationFailedException {
    final URI rootURI = URI.create(serverAddress);
    final URI resourceURI = URI.create(serverAddress + "testBagImport");
    final String bagPath = TARGET_DIR + "/test-classes/sample/compress/bag-tar.tar";

    final Config config = new Config();
    config.setMode("import");
    config.setBaseDirectory(bagPath);
    config.setRdfLanguage(DEFAULT_RDF_LANG);
    config.setResource(rootURI);
    config.setMap(new String[]{"http://localhost:8080/fcrepo/rest/", serverAddress});
    config.setUsername(USERNAME);
    config.setPassword(PASSWORD);
    config.setBagProfile(BagProfile.BuiltIn.BEYOND_THE_REPOSITORY.getIdentifier());
    config.setIncludeBinaries(true);
    config.setLegacy(true);

    // Resource doesn't exist
    if (exists(resourceURI)) {
        removeAndReset(resourceURI);
    }
    assertFalse(exists(resourceURI));

    // run import
    final Importer importer = new Importer(config, clientBuilder);
    importer.run();

    // Resource does exist.
    assertTrue(exists(resourceURI));
}
 
Example 8
Source File: RequestContentTypeTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void contentTypeAndSubtypeIllegal() throws Exception {
  HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "Rooms"));
  post.addHeader(HttpHeaders.CONTENT_TYPE, "illegal/illegal");
  final HttpResponse response = getHttpClient().execute(post);
  assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(), response.getStatusLine().getStatusCode());
}
 
Example 9
Source File: RoundtripIT.java    From fcrepo-import-export with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoundtripDirectContainer() throws Exception {
    final String baseURI = serverAddress + UUID.randomUUID();
    final URI res1 = URI.create(baseURI + "/res1");
    final URI parts = URI.create(baseURI + "/res1/parts");
    final URI part1 = URI.create(baseURI + "/res1/parts/part1");


    final String partsTurtle = " <> <" + LDP_HAS_MEMBER_RELATION + "> <" + DCTERMS_HAS_PART + "> ; "
        + "<" + LDP_MEMBERSHIP_RESOURCE + "> <" +  res1.toString() + "> .";

    create(res1);

    final Map<String, String> headers = new HashMap<>();
    headers.put("Link", "<" + LDP_DIRECT_CONTAINER + ">; rel=\"type\"");

    createTurtle(parts, partsTurtle, headers);
    create(part1);

    roundtrip(URI.create(baseURI), true);

    final Resource parent = createResource(res1.toString());
    final Resource container = createResource(parts.toString());
    final Resource member = createResource(part1.toString());

    final Model model1 = getAsModel(res1);
    assertTrue(model1.contains(parent, createProperty(DCTERMS_HAS_PART), member));

    final Model model2 = getAsModel(parts);
    assertTrue(model2.contains(container, RDF_TYPE, createResource(LDP_DIRECT_CONTAINER)));
    assertTrue(model2.contains(container, createProperty(LDP_HAS_MEMBER_RELATION),
            createResource(DCTERMS_HAS_PART)));
    assertTrue(model2.contains(container, createProperty(LDP_MEMBERSHIP_RESOURCE), parent));

    // make sure membership triples were generated by the container
    client.delete(part1).perform();
    final Model model3 = getAsModel(res1);
    assertFalse(model3.contains(parent, createProperty(DCTERMS_HAS_PART), member));
}
 
Example 10
Source File: Uri.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
public Uri(String uri) {
    this.uriAsString = uri;

    URI uriValue = null;
    try {
        uriValue = URI.create(uri);
    } catch (IllegalArgumentException e) {
        uriValue = null;
    }
    this.uri = uriValue;
}
 
Example 11
Source File: RdmaStorageActiveGroup.java    From crail with Apache License 2.0 5 votes vote down vote up
public StorageEndpoint createEndpoint(InetSocketAddress inetAddress) throws Exception {
	if (RdmaConstants.STORAGE_RDMA_LOCAL_MAP && CrailUtils.isLocalAddress(inetAddress.getAddress())){
		RdmaStorageLocalEndpoint localEndpoint = localCache.get(inetAddress.getAddress());
		if (localEndpoint == null){
			localEndpoint = new RdmaStorageLocalEndpoint(inetAddress);
			localCache.put(inetAddress, localEndpoint);
		}
		return localEndpoint;			
	}
	
	RdmaStorageActiveEndpoint endpoint = super.createEndpoint();
	URI uri = URI.create("rdma://" + inetAddress.getAddress().getHostAddress() + ":" + inetAddress.getPort());
	endpoint.connect(uri);
	return endpoint;
}
 
Example 12
Source File: T7142086.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public AnSource(int n) {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = classTemplate.replace("#N", String.valueOf(n));
}
 
Example 13
Source File: RoundtripIT.java    From fcrepo-import-export with Apache License 2.0 4 votes vote down vote up
@Test
public void testRoundtripIndirectContainer() throws Exception {
    final String baseURI = serverAddress + UUID.randomUUID();
    final URI res1 = URI.create(baseURI + "/res1");
    final URI res2 = URI.create(baseURI + "/res2");
    final URI parts = URI.create(baseURI + "/res2/parts");
    final URI proxy = URI.create(baseURI + "/res2/parts/proxy1");

    final String partsTurtle = "<> <" + LDP_HAS_MEMBER_RELATION + "> <" + DCTERMS_HAS_PART + "> ; "
        + "<" + LDP_MEMBERSHIP_RESOURCE + "> <" +  res2.toString() + "> ; "
        + "<" + LDP_INSERTED_CONTENT_RELATION + "> <" + ORE_PROXY_FOR + "> .";

    final String proxyTurtle = "<> a <" + ORE_PROXY + "> ; "
        + "<" + ORE_PROXY_FOR + "> <" + res1.toString() + "> . ";

    create(res1);
    create(res2);
    final Map<String, String> headers = new HashMap<>();
    headers.put("Link", "<" + LDP_INDIRECT_CONTAINER + ">; rel=\"type\"");
    createTurtle(parts, partsTurtle, headers);
    createTurtle(proxy, proxyTurtle);

    roundtrip(URI.create(baseURI), true);

    final Resource member = createResource(res1.toString());
    final Resource parent = createResource(res2.toString());
    final Resource container = createResource(parts.toString());

    final Model model1 = getAsModel(res2);
    assertTrue(model1.contains(parent, createProperty(DCTERMS_HAS_PART), member));

    final Model model2 = getAsModel(parts);
    assertTrue(model2.contains(container, RDF_TYPE, createResource(LDP_INDIRECT_CONTAINER)));
    assertTrue(model2.contains(container, createProperty(LDP_HAS_MEMBER_RELATION),
            createResource(DCTERMS_HAS_PART)));
    assertTrue(model2.contains(container, createProperty(LDP_MEMBERSHIP_RESOURCE), parent));
    assertTrue(model2.contains(container, createProperty(LDP_INSERTED_CONTENT_RELATION),
            createResource(ORE_PROXY_FOR)));

    // make sure membership triples were generated by the container
    client.delete(proxy).perform();
    final Model model3 = getAsModel(res2);
    assertFalse(model3.contains(parent, createProperty(DCTERMS_HAS_PART), member));
}
 
Example 14
Source File: DefaultDockerClientConfigTest.java    From docker-java with Apache License 2.0 4 votes vote down vote up
@Test()
public void testSslContextEmpty() throws Exception {
    new DefaultDockerClientConfig(URI.create("tcp://foo"), "dockerConfig", "apiVersion", "registryUrl", "registryUsername", "registryPassword", "registryEmail",
            null);
}
 
Example 15
Source File: TestRSAKeyPairGenerator.java    From java-license-manager with Apache License 2.0 4 votes vote down vote up
public MockJavaClassObject(String name, Kind kind)
{
    super(URI.create("string:///" + name.replace('.', '/') + kind.extension), kind);
}
 
Example 16
Source File: TestClose.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
MemFile(String name, String text) {
    super(URI.create(name), JavaFileObject.Kind.SOURCE);
    this.text = text;
}
 
Example 17
Source File: T6457284.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public MyFileObject() {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
}
 
Example 18
Source File: Avatar.java    From intercom-java with Apache License 2.0 4 votes vote down vote up
public Avatar setImageURL(String imageURL) {
    if(imageURL != null) {
        this.imageURL = URI.create(imageURL);
    }
    return this;
}
 
Example 19
Source File: TestSelfRef.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public JavaSource() {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = bodyTemplate.replace("#B",
            ek.enclStr.replace("#S", sk.siteStr.replace("#I", ik.innerStr.replace("#R", rk.refStr))));
}
 
Example 20
Source File: TestToString.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public JavaSource(String stmt) {
    super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
    source = source.replace("#S", stmt);
}