List of usage examples for java.net URI toURL
public URL toURL() throws MalformedURLException
From source file:org.commonjava.aprox.dotmaven.settings.AbstractSettingsTest.java
protected final String getDotMavenUrl(final String path) throws URISyntaxException, MalformedURLException { final String mavdavPath = PathUtils.normalize("/../mavdav", path); System.out.println("Resolving dotMaven URL. Base URL: '" + client.getBaseUrl() + "'\ndotMaven path: '" + mavdavPath + "'"); final URI result = resolve(new URI(client.getBaseUrl()), new URI(mavdavPath)); System.out.println("Resulting URI: '" + result.toString() + "'"); final String url = result.toURL().toExternalForm(); System.out.println("Resulting URL: '" + url + "'"); return url;//from w ww . j a v a 2s . c o m }
From source file:net.sf.jabref.importer.fetcher.GVKFetcher.java
private List<BibEntry> fetchGVK(String query) { List<BibEntry> result;// www.ja v a2 s . co m String urlPrefix = "http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query="; String urlSuffix = "&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1"; String searchstring = urlPrefix + query + urlSuffix; LOGGER.debug(searchstring); try { URI uri = new URI(searchstring); URL url = uri.toURL(); try (InputStream is = url.openStream()) { result = (new GVKParser()).parseEntries(is); } } catch (URISyntaxException e) { LOGGER.error("URI malformed error", e); return Collections.emptyList(); } catch (IOException e) { LOGGER.error("GVK: An I/O exception occurred", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOGGER.error("GVK: An internal parser error occurred", e); return Collections.emptyList(); } catch (SAXException e) { LOGGER.error("An internal parser error occurred", e); return Collections.emptyList(); } return result; }
From source file:no.dusken.aranea.admin.control.ImportStvMediaController.java
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { if (isImporting) { log.error("import already running"); return new ModelAndView("redirect:/"); } else {/*from w w w. j a va 2s . c o m*/ isImporting = true; } /* * parses the podcastfeed from stv to mediaResource */ URI uri = new URI(feedUrl); URL url = uri.toURL(); File file = new File(cacheDirectory + "/" + "feed.xml"); FileUtils.copyURLToFile(url, file); Document doc = parseXmlFile(file); // get the root elememt Element docEle = doc.getDocumentElement(); // get a nodelist of <item> elements NodeList nl = docEle.getElementsByTagName("item"); if (nl != null && nl.getLength() > 0) { for (int i = 0; i < nl.getLength(); i++) { // get the item element Element el = (Element) nl.item(i); //get the mediaresource MediaResource mr = getMediaResource(el); if (!isInDb(mr)) { mediaResourceService.saveOrUpdate(mr); log.info("Imported media, url: {}", mr.getUrlToResource()); } } } return new ModelAndView("redirect:/"); }
From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.CRLDistributionPointRevocationChecker.java
private void addURL(final List<URL> list, final String uriString) { try {/*w w w. j av a2 s . c o m*/ // Build URI by components to facilitate proper encoding of querystring // e.g. http://example.com:8085/ca?action=crl&issuer=CN=CAS Test User CA final URL url = new URL(uriString); final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null); list.add(uri.toURL()); } catch (final Exception e) { log.warn(uriString + " is not a valid distribution point URI."); } }
From source file:com.sap.core.odata.fit.basic.FitLoadTest.java
@Test public void useJavaHttpClient() throws IOException { final URI uri = URI.create(getEndpoint().toString() + "$metadata"); for (int i = 0; i < LOOP_COUNT; i++) { HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod("GET"); connection.connect();/* w w w . j a v a2 s . c o m*/ assertEquals(HttpStatusCodes.OK.getStatusCode(), connection.getResponseCode()); } }
From source file:io.druid.segment.realtime.firehose.HttpFirehoseFactory.java
@Override protected InputStream openObjectStream(URI object, long start) throws IOException { if (supportContentRange) { final URLConnection connection = object.toURL().openConnection(); // Set header for range request. // Since we need to set only the start offset, the header is "bytes=<range-start>-". // See https://tools.ietf.org/html/rfc7233#section-2.1 connection.addRequestProperty(HttpHeaders.RANGE, StringUtils.format("bytes=%d-", start)); return connection.getInputStream(); } else {//ww w . j a v a 2 s .co m log.warn( "Since the input source doesn't support range requests, the object input stream is opened from the start and " + "then skipped. This may make the ingestion speed slower. Consider enabling prefetch if you see this message" + " a lot."); final InputStream in = openObjectStream(object); in.skip(start); return in; } }
From source file:org.kalypso.simulation.grid.GridJobSubmitter.java
private String getUriAsString(final URI uri) { try {// w ww .j a va2 s .c om final URL url = FileLocator.toFileURL(uri.toURL()); return url.toExternalForm(); } catch (final IOException e) { return uri.toString(); } }
From source file:org.opencastproject.workflow.handler.HttpNotificationWorkflowOperationHandlerTest.java
@Before public void setUp() throws Exception { MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder(); // test resources URI uriMP = getClass().getResource("/concat_mediapackage.xml").toURI(); mp = builder.loadFromXml(uriMP.toURL().openStream()); // set up mock trusted http client client = EasyMock.createNiceMock(TrustedHttpClient.class); HttpResponse response = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_ACCEPTED, "")); EasyMock.expect(client.execute((HttpUriRequest) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())) .andReturn(response);// w w w.j a v a 2s. c o m EasyMock.replay(client); // set up service operationHandler = new HttpNotificationWorkflowOperationHandler(); }
From source file:org.codice.ddf.registry.publication.action.provider.RegistryPublicationActionProvider.java
private Action getAction(String regId, String destinationId, String destinationName, boolean publish) { URL url;/* w w w .j a va 2 s . co m*/ String title = publish ? PUBLISH_TITLE + destinationName : UNPUBLISH_TITLE + destinationName; String description = publish ? PUBLISH_DESCRIPTION + destinationName : UNPUBLISH_DESCRIPTION + destinationName; String operation = publish ? PUBLISH_OPERATION : UNPUBLISH_OPERATION; String httpOp = publish ? HTTP_POST : HTTP_DELETE; try { String path = String.format("%s/%s/%s/%s", REGISTRY_PATH, regId, PUBLICATION_PATH, URLEncoder.encode(destinationId, "UTF-8")); URI uri = new URI(SystemBaseUrl.EXTERNAL.constructUrl(path, true)); url = uri.toURL(); } catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) { LOGGER.debug("Malformed URL exception", e); return null; } String id = String.format("%s.%s.%s", getId(), operation, httpOp); return new ActionImpl(id, title, description, url); }
From source file:integration.util.graylog.ServerHelper.java
public String getNodeId() throws MalformedURLException, URISyntaxException { final URI uri = IntegrationTestsConfig.getGlServerURL(); ObjectMapper mapper = new ObjectMapper(); try {/* www . j av a 2s. c om*/ HttpURLConnection connection = (HttpURLConnection) new URL(uri.toURL(), "/system").openConnection(); connection.setConnectTimeout(HTTP_TIMEOUT); connection.setReadTimeout(HTTP_TIMEOUT); connection.setRequestMethod("GET"); if (uri.getUserInfo() != null) { String encodedUserInfo = Base64 .encodeBase64String(uri.getUserInfo().getBytes(StandardCharsets.UTF_8)); connection.setRequestProperty("Authorization", "Basic " + encodedUserInfo); } InputStream inputStream = connection.getInputStream(); JsonNode json = mapper.readTree(inputStream); return json.get("node_id").toString(); } catch (IOException e) { e.printStackTrace(); } return "00000000-0000-0000-0000-000000000000"; }