List of usage examples for java.net URI create
public static URI create(String str)
From source file:se.vgregion.pubsub.impl.DefaultTopic.java
@Override public URI getUrl() { return URI.create(url); }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
@Override public Set<CrawlEvent> handle(CrawlEvent event) throws Exception { Set<CrawlEvent> nextEvents = new HashSet<>(); // Get url/*ww w.j a v a 2 s.co m*/ URI url = URI.create(event.getUrl()); Document dom = null; boolean created = false; if (!checkErrors || !hasError(url)) { HttpGet req = new HttpGet(url); HttpResponse res = httpClient.execute(req); try { if (res.getStatusLine().getStatusCode() == 200) { byte[] domBytes = IOUtils.toByteArray(res.getEntity().getContent()); created = handleData(url, domBytes); dom = Jsoup.parse(new String(domBytes)); } else { LOG.error("Error for {} #=> {}", url, res.getStatusLine().getStatusCode()); markError(url, res.getStatusLine().getStatusCode()); } } finally { if (res.getEntity() != null) { EntityUtils.consumeQuietly(res.getEntity()); } } } // Extract links if ((created || traverseDuplicates) && dom != null) { for (Element element : dom.select("a")) { String href = element.attr("href"); if (href != null) { URI nextUri = getNextUri(url, href, event.getChroot()); if (shouldExplore(nextUri) && isSameDomain(url, nextUri) && isDifferentPage(url, nextUri)) { CrawlEvent nextEvent = new CrawlEvent(event); nextEvent.setUrl(nextUri.toString()); nextEvent.setParentUrl(event.getUrl()); nextEvent.setDepth(event.getDepth() + 1); nextEvents.add(nextEvent); LOG.debug("Exploring {}", nextUri); } else { LOG.debug("Skipping {}", nextUri); } } } } return nextEvents; }
From source file:org.eel.kitchen.jsonschema.uri.URIManagerTest.java
@Test(dependsOnMethods = "shouldBeAbleToRegisterScheme") public void shouldBeAbleToUnregisterScheme() throws IOException, JsonSchemaException { final URI uri = URI.create("foo://bar"); final InputStream sampleStream = new ByteArrayInputStream("{}".getBytes()); when(mock.fetch(any(URI.class))).thenReturn(sampleStream); manager.registerScheme("foo", mock); manager.getContent(uri);/*from ww w .java 2 s. c o m*/ manager.unregisterScheme("foo"); try { manager.getContent(uri); fail("No exception thrown!"); } catch (JsonSchemaException e) { final Message msg = e.getValidationMessage(); checkMsg(msg, "cannot handle scheme", uri); assertEquals(msg.getInfo("scheme").textValue(), uri.getScheme()); } }
From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java
@Test public void replace_binary_multipart_content_with_placeholder() { OperationRequestPart part1 = this.partFactory.create("field1", "file1.png", "BinaryContent".getBytes(), new HttpHeaders()); OperationRequestPart part2 = this.partFactory.create("field2", null, "TextContent".getBytes(), new HttpHeaders()); final OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.POST, null, new HttpHeaders(), new Parameters(), Arrays.asList(part1, part2)); this.preprocessor.field("field1", "<<placeholder>>"); final OperationRequest preprocessed = this.preprocessor.preprocess(request); final Collection<OperationRequestPart> parts = preprocessed.getParts(); assertThat(hasPart(parts, "field1", "<<placeholder>>"), is(true)); assertThat(hasPart(parts, "field2", "TextContent"), is(true)); }
From source file:com.collective.celos.GetSchedulerTest.java
@Before public void setup() throws Exception { File tmpDir = folder.newFolder(); this.workflowsDir = new File(tmpDir, WORKFLOWS_DIR); File defaultsDir = new File(tmpDir, DEFAULTS_DIR); this.slotDbDir = new File(tmpDir, DB_DIR); this.workflowsDir.mkdirs(); defaultsDir.mkdirs();// www . j av a 2 s .c o m this.slotDbDir.mkdirs(); this.celosServer = new CelosServer(); StateDatabase db = new FileSystemStateDatabase(slotDbDir); int port = celosServer.startServer(ImmutableMap.<String, String>of(), workflowsDir, defaultsDir, db); this.celosClient = new CelosClient(URI.create("http://localhost:" + port)); }
From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.StandardDirectorUtilsTest.java
@Test public void getVirtualMachines() { Set<Map<String, String>> expected = new HashSet<>(); expected.add(this.vm); when(this.restTemplate.getForObject(URI.create("http://localhost/deployments/test-deployment/vms"), Set.class)).thenReturn(expected); assertEquals(expected, this.directorUtils.getVirtualMachines("test-deployment")); }
From source file:net.ripe.rpki.commons.provisioning.serialization.CertificateUrlListConverter.java
@Override public List<URI> fromString(String str) { List<URI> result = new ArrayList<URI>(); for (String uri : str.split(",")) { result.add(URI.create(uri)); }/*from w w w.j a va2 s. c om*/ return result; }
From source file:com.csipsimple.models.RemoteLibInfo.java
/** * Constructor from json object (retrieved on the web) * @param library/*from w ww .ja v a 2s . co m*/ * @throws JSONException if json is not well formated or doesn't contains everything we want */ public RemoteLibInfo(JSONObject library) throws JSONException { JSONObject latestVersion; latestVersion = library.getJSONArray("versions").getJSONObject(0); changelog = latestVersion.getString("changelog"); version = latestVersion.getString("version"); uri = URI.create(latestVersion.getString("download_url")); description = library.getString("description"); label = library.getString("label"); id = library.getString("id"); }
From source file:io.druid.storage.s3.S3DataSegmentPullerTest.java
@Test public void testSimpleGetVersion() throws S3ServiceException, IOException { String bucket = "bucket"; String keyPrefix = "prefix/dir/0"; RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class); S3Object object0 = new S3Object(); object0.setBucketName(bucket);/* w w w.j a v a2 s .c o m*/ object0.setKey(keyPrefix + "/renames-0.gz"); object0.setLastModifiedDate(new Date(0)); EasyMock.expect(s3Client.getObject(EasyMock.eq(bucket), EasyMock.eq(object0.getKey()))).andReturn(object0) .once(); S3DataSegmentPuller puller = new S3DataSegmentPuller(s3Client); EasyMock.replay(s3Client); String version = puller.getVersion(URI.create(String.format("s3://%s/%s", bucket, object0.getKey()))); EasyMock.verify(s3Client); Assert.assertEquals(String.format("%d", new Date(0).getTime()), version); }
From source file:jease.cms.web.content.editor.TransitEditor.java
public void validate() { validate(uri.isEmpty(), I18N.get("Path_is_required")); validate(!URI.create(uri.getText()).isAbsolute(), I18N.get("Path_is_required")); }