List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:org.wso2.carbon.governance.registry.extensions.handlers.utils.SchemaUriProcessor.java
private String getAbsoluteSchemaURL(String schemaLocation) throws RegistryException { if (schemaLocation != null && baseURI != null) { try {//from ww w .j av a 2s . co m URI uri = new URI(baseURI); URI absoluteURI = uri.resolve(schemaLocation); return absoluteURI.toString(); } catch (URISyntaxException e) { throw new RegistryException(e.getMessage(), e); } } return schemaLocation; }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
/** * This method reads the History data from specified metaFolderPath and * loads it into the database;//from w w w . j a va 2 s. co m * * @param metaFolderPath * @throws SQLException */ public void loadUMLSHistory(URI folderPath) throws Exception { BufferedReader reader = getReader(folderPath.resolve("MRCUI.RRF")); try { String line = reader.readLine(); int lineNo = 0; readMrConso(folderPath); message_.info("Loading History info..."); while (line != null) { ++lineNo; if (line.startsWith("#") || line.length() == 0) { line = reader.readLine(); continue; } List<String> elements = deTokenizeString(line, token_); try { loadSystemReleaseInfo(elements); } catch (Exception e) { if (failOnAllErrors_) { // this call rethrow the exception message_.fatalAndThrowException( "Exception while loading System Release Info @ line : " + lineNo, e); } else { message_.error("Error occured in line: " + lineNo, e); // go to next line, continue. line = reader.readLine(); continue; } } try { loadUMLSHistoryInfo(elements); } catch (Exception e) { if (failOnAllErrors_) { // this call rethrow the exception message_.fatalAndThrowException("Exception while loadUMLSHistoryInfo @ line : " + lineNo, e); } else { message_.error("Error occured in line: " + lineNo, e); // go to next line, continue. line = reader.readLine(); continue; } } line = reader.readLine(); } } finally { reader.close(); } }
From source file:org.mcxiaoke.commons.http.util.URIUtilsEx.java
/** * Resolves a URI reference against a base URI. Work-around for bugs in * java.net.URI (e.g./*www . j a v a 2 s.com*/ * <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI * the base URI * @param reference * the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, URI reference) { if (baseURI == null) { throw new IllegalArgumentException("Base URI may nor be null"); } if (reference == null) { throw new IllegalArgumentException("Reference URI may nor be null"); } String s = reference.toString(); if (s.startsWith("?")) { return resolveReferenceStartingWithQueryString(baseURI, reference); } boolean emptyReference = s.length() == 0; if (emptyReference) { reference = URI.create("#"); } URI resolved = baseURI.resolve(reference); if (emptyReference) { String resolvedString = resolved.toString(); resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#'))); } return removeDotSegments(resolved); }
From source file:uk.org.taverna.commons.update.impl.UpdateManagerImpl.java
/** * @param requiredBundles// w ww .j a va 2 s. co m * @param file * @throws UpdateException */ private void downloadBundles(ApplicationProfile profile, Set<BundleInfo> requiredBundles, File file) throws UpdateException { Updates updates = profile.getUpdates(); String updateSite = updates.getUpdateSite(); String libDirectory = updates.getLibDirectory(); if (!libDirectory.endsWith("/")) { libDirectory = libDirectory + "/"; } URI updateLibDirectory; try { updateLibDirectory = new URI(updateSite).resolve(libDirectory); } catch (URISyntaxException e) { throw new UpdateException( String.format("Update site URL (%s) is not a valid URL", updates.getUpdateSite()), e); } for (BundleInfo bundle : requiredBundles) { URL bundleURL; URI bundleURI = updateLibDirectory.resolve(bundle.getFileName()); try { bundleURL = bundleURI.toURL(); } catch (MalformedURLException e) { throw new UpdateException(String.format("Bundle URL (%s) is not a valid URL", bundleURI), e); } File bundleDestination = new File(file, bundle.getFileName()); try { downloadManager.download(bundleURL, new File(file, bundle.getFileName()), DIGEST_ALGORITHM); } catch (DownloadException e) { throw new UpdateException( String.format("Error downloading %1$s to %2$s", bundleURL, bundleDestination), e); } } }
From source file:eu.asterics.mw.services.TestResourceRegistry.java
@Test public void testisSubURIOfAREBaseURI() { URI relative = URI.create(ResourceRegistry.MODELS_FOLDER); URI absolute = ResourceRegistry.getInstance().toAbsolute(ResourceRegistry.MODELS_FOLDER); assertTrue(ResourceRegistry.getInstance().isSubURIOfAREBaseURI(absolute)); assertFalse(ResourceRegistry.getInstance().isSubURIOfAREBaseURI(absolute.resolve("../../"))); }
From source file:com.netflix.genie.web.services.impl.JobDirectoryServerServiceImpl.java
/** * Constructor that accepts a handler factory mock for easier testing. *///from w ww. j a va 2s. c om @VisibleForTesting JobDirectoryServerServiceImpl(final ResourceLoader resourceLoader, final JobPersistenceService jobPersistenceService, final JobFileService jobFileService, final AgentFileStreamService agentFileStreamService, final MeterRegistry meterRegistry, final GenieResourceHandler.Factory genieResourceHandlerFactory) { this.resourceLoader = resourceLoader; this.jobPersistenceService = jobPersistenceService; this.jobFileService = jobFileService; this.agentFileStreamService = agentFileStreamService; this.meterRegistry = meterRegistry; this.genieResourceHandlerFactory = genieResourceHandlerFactory; // TODO: This is a local cache. It might be valuable to have a shared cluster cache? // TODO: May want to tweak parameters or make them configurable // TODO: Should we expire more proactively than just waiting for size to fill up? this.manifestCache = CacheBuilder.newBuilder().maximumSize(50L).recordStats() .build(new CacheLoader<String, ManifestCacheValue>() { @Override public ManifestCacheValue load(final String key) throws Exception { // TODO: Probably need more specific exceptions so we can map them to response codes final String archiveLocation = jobPersistenceService.getJobArchiveLocation(key) .orElseThrow(() -> new JobNotArchivedException("Job " + key + " wasn't archived")); final URI jobDirectoryRoot = new URI(archiveLocation + SLASH).normalize(); final URI manifestLocation; if (StringUtils.isBlank(JobArchiveService.MANIFEST_DIRECTORY)) { manifestLocation = jobDirectoryRoot.resolve(JobArchiveService.MANIFEST_NAME) .normalize(); } else { manifestLocation = jobDirectoryRoot .resolve(JobArchiveService.MANIFEST_DIRECTORY + SLASH) .resolve(JobArchiveService.MANIFEST_NAME).normalize(); } final Resource manifestResource = resourceLoader.getResource(manifestLocation.toString()); if (!manifestResource.exists()) { throw new GenieNotFoundException("No job manifest exists at " + manifestLocation); } final JobDirectoryManifest manifest = GenieObjectMapper.getMapper() .readValue(manifestResource.getInputStream(), JobDirectoryManifest.class); return new ManifestCacheValue(manifest, jobDirectoryRoot); } }); // TODO: Record metrics for cache using stats() method return }
From source file:com.collaborne.jsonschema.generator.pojo.AbstractPojoTypeGenerator.java
protected <T extends Exception> boolean visitSchema(URI elementUri, SchemaTree schema, SchemaVisitor<T> visitor) throws T { JsonNode element = schema.getNode(); if (!element.isContainerNode()) { return false; }//from w ww. j a va2 s . c o m // We handle "id" here in the same way as the json-schema-validator: it's fairly non-trust-worthy. // In a properly written document the id is useless, as we already had that with a $ref, and you cannot just modify things in place. if (element.hasNonNull("$ref")) { // A reference to something else. String refValue = element.get("$ref").textValue(); visitor.visitSchema(elementUri.resolve(refValue)); } else { visitor.visitSchema(elementUri, schema); } return true; }
From source file:com.github.grantjforrester.bdd.rest.httpclient.HttpClientRequest.java
HttpRequestBase getRequestImpl(URI baseUri) { HttpRequestBase request = null;//w w w. j av a2 s .com switch (method) { case HEAD: request = new HttpHead(); break; case OPTIONS: request = new HttpOptions(); break; case GET: request = new HttpGet(); break; case POST: request = new HttpPost(); break; case PUT: request = new HttpPut(); break; case DELETE: request = new HttpDelete(); break; case PATCH: request = new HttpPatch(); } request.setURI(baseUri.resolve(uri)); request.setHeaders(headers.toArray(new Header[headers.size()])); if (content != null) { ((HttpEntityEnclosingRequest) request).setEntity(new ByteArrayEntity(content)); } return request; }
From source file:de.sub.goobi.metadaten.FileManipulation.java
/** * import files from folder./*from w w w .j a v a2 s .c om*/ * */ public List<URI> getAllImportFolder() { URI tempDirectory = new File(ConfigCore.getParameter("tempfolder", "/usr/local/kitodo/tmp/")).toURI(); URI fileuploadFolder = tempDirectory.resolve("fileupload"); allImportFolder = new ArrayList<>(); if (fileService.isDirectory(fileuploadFolder)) { allImportFolder.addAll(fileService.getSubUris(directoryFilter, fileuploadFolder)); } return allImportFolder; }
From source file:org.eclipse.orion.server.tests.servlets.xfer.TransferTest.java
@Test public void testImportAndUnzip() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath);/*w w w. j a va2 s. c o m*/ //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location); //assert the file has been unzipped in the workspace assertTrue( checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/js/navigate-tree/navigate-tree.js")); }