/** * Insert a base URL (if configured) unless the given URL has a host already. */ private URI insertBaseUrl(URI url) { try { String baseUrl = getBaseUrl(); if (baseUrl != null && url.getHost() == null) { url = new URI(baseUrl + url.toString()); } return url; } catch (URISyntaxException ex) { throw new IllegalArgumentException("Invalid URL after inserting base URL: " + url, ex); } }
protected String hostInfoForCommandline() { try { URI uri = new URI(url); if (uri.getUserInfo() != null) { //(String scheme, String userInfo, String host, int port, String path, String query, String fragment) uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); } return uri.toString(); } catch (URISyntaxException e) { // In subversion we may have a file path that is not actually a URL return url; } }
private List<String> matchingDirectories(File dir, String value) { List<String> output = new ArrayList<String>(); try { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( this.resourceLoader); String path = new File(dir, value).toURI().toString(); for (Resource resource : resolver.getResources(path)) { if (resource.getFile().isDirectory()) { output.add(resource.getURI().toString()); } } } catch (IOException e) { } return output; }
@Test public void testConfigWithIgnoreUsingInputSource() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new InputSource( new File(getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")) .toURI().toString()), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children[0].getChildren().length); }
private String downloadResource(URI srcUri, String subDir, boolean convertToUnix) throws IOException, URISyntaxException { LOG.debug("Converting to local {}", srcUri); File destinationDir = (subDir == null) ? resourceDir : new File(resourceDir, subDir); ensureDirectory(destinationDir); File destinationFile = new File(destinationDir, new Path(srcUri.toString()).getName()); String dest = destinationFile.getCanonicalPath(); if (destinationFile.exists()) { return dest; } FileSystem fs = FileSystem.get(srcUri, conf); fs.copyToLocalFile(new Path(srcUri.toString()), new Path(dest)); // add "execute" permission to downloaded resource file (needed when loading dll file) FileUtil.chmod(dest, "ugo+rx", true); return dest; }
@Test public void databases() throws TException, URISyntaxException { String[] dbNames = {"db1", "db9"}; String expectedLocation = new File(expectedBaseDir(), dbNames[0] + ".db").toURI().toString(); Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); Assert.assertEquals(expectedLocation, fetched.getLocationUri() + "/"); String db0Location = new URI(fetched.getLocationUri()).getPath(); File dir = new File(db0Location); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); Assert.assertEquals(new File(db1Location).toURI().toString(), fetched.getLocationUri() + "/"); dir = new File(new URI(fetched.getLocationUri()).getPath()); Assert.assertTrue(dir.exists() && dir.isDirectory()); Assert.assertEquals(expectedCatalog(), fetched.getCatalogName()); dir = new File(db0Location); Assert.assertFalse(dir.exists());
@Test // SPR-9317 public void fromUriEncodedQuery() throws URISyntaxException { URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D"); String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0); String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()) .build().getQueryParams().get("param").get(0); assertEquals(fromUri, fromUriString); }
@Test // SPR-14147 public void defaultUriVariables() throws Exception { Map<String, String> defaultVars = new HashMap<>(2); defaultVars.put("host", "api.example.com"); defaultVars.put("port", "443"); this.handler.setDefaultUriVariables(defaultVars); Map<String, Object> vars = new HashMap<>(1); vars.put("id", 123L); String template = "https://{host}:{port}/v42/customers/{id}"; URI actual = this.handler.expand(template, vars); assertEquals("https://api.example.com:443/v42/customers/123", actual.toString()); }
@Test public void testExplicitlySetToLocal() throws Exception { final Configuration conf = new Configuration(); conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString()); FileSystem.initialize(conf); URI justPath = new URI(tempFolder.newFile().toURI().getPath()); assertNull(justPath.getScheme()); FileSystem fs = FileSystem.get(justPath); assertEquals("file", fs.getUri().getScheme()); }
@Test public void shouldSetHeadersAndBaseDirectory() throws IOException { assertThat(handler.getContextPath(), is("/go/assets")); assertThat(((HandlerWrapper) handler.getHandler()).getHandler() instanceof AssetsContextHandler.AssetsHandler, is(true)); AssetsContextHandler.AssetsHandler assetsHandler = (AssetsContextHandler.AssetsHandler) ((HandlerWrapper) handler.getHandler()).getHandler(); ResourceHandler resourceHandler = (ResourceHandler) ReflectionUtil.getField(assetsHandler, "resourceHandler"); assertThat(resourceHandler.getCacheControl(), is("max-age=31536000,public")); assertThat(resourceHandler.getResourceBase(), isSameFileAs(new File("WEB-INF/rails.root/public/assets").toPath().toAbsolutePath().toUri().toString())); }
public String defaultRemoteUrl() { final String sanitizedUrl = sanitizeUrl(); try { URI uri = new URI(sanitizedUrl); if (uri.getUserInfo() != null) { uri = new URI(uri.getScheme(), removePassword(uri.getUserInfo()), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } } catch (URISyntaxException e) { return sanitizedUrl; } return sanitizedUrl; } }
@Test public void classpathURLWithWhitespace() throws Exception { PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); uriEditor.setAsText(" classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class "); Object value = uriEditor.getValue(); assertTrue(value instanceof URI); URI uri = (URI) value; assertEquals(uri.toString(), uriEditor.getAsText()); assertTrue(!uri.getScheme().startsWith("classpath")); }
private String ensureRelativeUri( String mountPoint ) { try { URI result = new URI( mountPoint ); if ( result.isAbsolute() ) { return result.getPath(); } else { return result.toString(); } } catch ( URISyntaxException e ) { log.debug( "Unable to translate [%s] to a relative URI in ensureRelativeUri(String mountPoint)", mountPoint ); return mountPoint; } }
@Documented( "Get non-existent node." ) @Test public void shouldGet404WhenRetrievingNonExistentNode() throws Exception { long nonExistentNode = helper.createNode(); helper.deleteNode( nonExistentNode ); URI nonExistentNodeUri = new URI( functionalTestHelper.nodeUri() + "/" + nonExistentNode ); gen.get() .expectedStatus( 404 ) .get( nonExistentNodeUri.toString() ); }