List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:net.slkdev.swagger.confluence.service.impl.SwaggerToAsciiDocServiceImpl.java
private static File getSchemaFile(final String swaggerSchemaPath) throws FileNotFoundException, URISyntaxException { // First we'll try to find the file directly File swaggerFile = new File(swaggerSchemaPath); // If we can't find it, we'll check the classpath if (!swaggerFile.exists()) { final URL swaggerSchemaURL = SwaggerToAsciiDocServiceImpl.class.getResource(swaggerSchemaPath); if (swaggerSchemaURL == null) { swaggerFile = null;/*w ww . j a v a 2 s . c om*/ } else { swaggerFile = new File(swaggerSchemaURL.toURI()); } } if (swaggerFile == null || !swaggerFile.exists() || !swaggerFile.canRead()) { throw new FileNotFoundException( String.format("Unable to Locate Swagger Schema at Path <%s>", swaggerSchemaPath)); } return swaggerFile; }
From source file:com.honnix.cheater.cli.Main.java
private static boolean setTrustStore() { boolean result = true; URL trustStoreFileURL = Main.class.getClassLoader().getResource(CheaterConstant.TRUST_STORE_FILE_NAME); if (trustStoreFileURL == null) { result = false;// w w w .j ava 2 s.c om } else { String trustStoreFilePath = null; try { trustStoreFilePath = trustStoreFileURL.toURI().getPath(); } catch (URISyntaxException e) { LOG.fatal("Failed setting trust store.", e); result = false; } if (trustStoreFilePath == null) { result = false; } else { System.setProperty(CheaterConstant.TRUST_STORE_KEY, trustStoreFilePath); } } return result; }
From source file:com.github.jrh3k5.chef.client.jersey.JerseyCookbookClientITest.java
@BeforeClass public static void getApacheInfo() throws Exception { final ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonJsonProvider.class); final Client client = ClientBuilder.newClient(clientConfig); try {/*from w w w . j a va 2 s . com*/ apacheCookbook = client.target(JerseyCookbookClient.V1_API_URL).path("cookbooks").path("apache") .request(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE) .get(JsonCookbookObject.class); final String latestVersionUrlString = apacheCookbook.getLatestVersion().toExternalForm(); apacheVersions = new ArrayList<JsonCookbookVersionObject>(apacheCookbook.versions.length); for (URL version : apacheCookbook.versions) { final JsonCookbookVersionObject versionObject = client.target(version.toURI()) .request(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE) .get(JsonCookbookVersionObject.class); versionObject.location = version; apacheVersions.add(versionObject); if (version.toExternalForm().equals(latestVersionUrlString)) { apacheCookbook.setLatestVersionObject(versionObject); } } } finally { client.close(); } }
From source file:org.synchronoss.cloud.nio.multipart.example.FileUploadClientIntegrationTest.java
static Collection<TestCase> getTestCases() { try {// w w w . j a v a 2 s . c o m URL resourceUrl = FileUploadClientIntegrationTest.class.getResource("/test-files"); Path resourcePath = Paths.get(resourceUrl.toURI()); File[] files = resourcePath.toFile().listFiles(); if (files == null) { log.warn("Empty test-files folder"); return Collections.emptyList(); } int applicationServerPort = Integer.parseInt(System.getProperty("application.server.port", "8080")); List<TestCase> testCases = new ArrayList<TestCase>(); for (File file : files) { for (String url : URLS) { testCases.add(new TestCase(file, String.format(url, applicationServerPort))); } } return testCases; } catch (Exception e) { throw new IllegalStateException("Cannot find the test file", e); } }
From source file:com.netflix.nicobar.core.utils.ClassPathUtils.java
private static Path getRootPathFromDirectory(String resourceName, URL resource) { try {/* www. j av a 2 s . c om*/ Path result = Paths.get(resource.toURI()); int relativePathSize = Paths.get(resourceName).getNameCount(); for (int i = 0; i < relativePathSize; i++) { result = result.getParent(); } return result; } catch (URISyntaxException e) { throw new IllegalStateException("Unsupported URL syntax: " + resource, e); } }
From source file:org.jboss.as.test.manualmode.web.valve.authenticator.ValveUtil.java
/** * Access http://localhost///from w w w . j av a2 s.c om * @return "valve" headers */ public static Header[] hitValve(URL url, int expectedResponseCode) throws Exception { HttpGet httpget = new HttpGet(url.toURI()); DefaultHttpClient httpclient = new DefaultHttpClient(); log.info("executing request" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); int statusCode = response.getStatusLine().getStatusCode(); Header[] errorHeaders = response.getHeaders("X-Exception"); assertEquals("Wrong response code: " + statusCode + " On " + url, expectedResponseCode, statusCode); assertEquals("X-Exception(" + Arrays.toString(errorHeaders) + ") is null", 0, errorHeaders.length); return response.getHeaders("valve"); }
From source file:com.omertron.subbabaapi.tools.ApiBuilder.java
/** * Get the DigestedResponse from the URL * * @param url// w ww .j a va 2s . co m * @return * @throws SubBabaException */ private static DigestedResponse getResponse(URL url) throws SubBabaException { try { final HttpGet httpGet = new HttpGet(url.toURI()); httpGet.addHeader("accept", "application/json"); httpGet.addHeader(HTTP.USER_AGENT, UserAgentSelector.randomUserAgent()); final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, CHARSET); if (response.getStatusCode() >= HTTP_STATUS_500) { throw new SubBabaException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url); } else if (response.getStatusCode() >= HTTP_STATUS_300) { throw new SubBabaException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url); } return response; } catch (IOException ex) { throw new SubBabaException(ApiExceptionType.CONNECTION_ERROR, "Error retrieving URL", url, ex); } catch (URISyntaxException ex) { throw new SubBabaException(ApiExceptionType.INVALID_URL, "Invalid URL", url, ex); } }
From source file:com.doculibre.constellio.utils.SolrSchemaUtils.java
public static IndexSchema getSchema(ConnectorType connectorType) { IndexSchema connectorTypeSchema;//from w ww. jav a 2s. c o m String targetSchemaName; if (connectorType != null) { targetSchemaName = connectorType.getName(); } else { targetSchemaName = "constellio"; // Default } Resource[] classpathResources = ConstellioSpringUtils.getResources(SOLR_SCHEMA_PATTERN); if (classpathResources != null) { connectorTypeSchema = null; for (int i = 0; i < classpathResources.length; i++) { InputStream resourceInput = null; try { Resource resource = classpathResources[i]; resourceInput = resource.getInputStream(); Document schema = new SAXReader().read(resourceInput); Element schemaElement = schema.getRootElement(); String schemaName = schemaElement.attributeValue("name"); if (targetSchemaName.equals(schemaName)) { resourceInput = resource.getInputStream(); SolrConfig dummySolrConfig; URL dummySolrConfigURL = SolrSchemaUtils.class.getClassLoader() .getResource("config" + File.separator + "solrdefault" + File.separator); File dummySolrConfigDir = new File(dummySolrConfigURL.toURI()); File dummySolrConfigFile = new File(dummySolrConfigDir, "conf" + File.separator + "solrconfig.xml"); dummySolrConfig = new SolrConfig(dummySolrConfigDir.getPath(), dummySolrConfigFile.getPath(), null); connectorTypeSchema = new IndexSchema(dummySolrConfig, null, new InputSource(resourceInput)); break; } } catch (DocumentException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } finally { IOUtils.closeQuietly(resourceInput); } } } else { connectorTypeSchema = null; } return connectorTypeSchema; }
From source file:com.izforge.izpack.compiler.packager.impl.AbstractPackagerTest.java
public static File getBaseDir() { File path = null;/*from w w w .j ava 2 s . co m*/ try { URL url = AbstractPackagerTest.class.getClassLoader().getResource(""); if (url != null) { URI uri = url.toURI(); path = new File(uri); // path: <root>/target/test-classes path = path.getParentFile(); // <root>/target/ path = path.getParentFile(); // <root> } else { Assert.fail("Resource not found"); } } catch (URISyntaxException e) { Assert.fail(e.getMessage()); } return path; }
From source file:acromusashi.stream.resource.ResourceResolver.java
/** * Return target file path from class and resource's path. * * @param clazz Target class/*from ww w . j a v a 2 s.c om*/ * @param path resource's path * @return File object */ public static File resolve(Class<?> clazz, String path) { URL url = clazz.getResource(path); if (url == null) { return null; } File result; try { result = Paths.get(url.toURI()).toFile(); } catch (URISyntaxException ex) { return null; } return result; }