List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:org.georchestra.security.Proxy.java
private void adjustLocation(HttpServletRequest request, HttpResponse proxiedResponse, HttpServletResponse finalResponse) { if (logger.isDebugEnabled()) { logger.debug("adjustLocation called for request: " + request.getRequestURI()); }/* w ww .ja v a 2s . co m*/ String target = findMatchingTarget(request); if (logger.isDebugEnabled()) { logger.debug("adjustLocation found target: " + target + " for request: " + request.getRequestURI()); } if (target == null) { copyLocationHeaders(proxiedResponse, finalResponse); return; } String baseURL = targets.get(target); URI baseURI = null; try { baseURI = new URI(baseURL); } catch (URISyntaxException e) { copyLocationHeaders(proxiedResponse, finalResponse); return; } for (Header locationHeader : proxiedResponse.getHeaders("Location")) { if (logger.isDebugEnabled()) { logger.debug("adjustLocation process header: " + locationHeader.getValue()); } try { URI locationURI = new URI(locationHeader.getValue()); URI resolvedURI = baseURI.resolve(locationURI); if (logger.isDebugEnabled()) { logger.debug( "Test location header: " + resolvedURI.toString() + " against: " + baseURI.toString()); } if (resolvedURI.toString().startsWith(baseURI.toString())) { // proxiedResponse.removeHeader(locationHeader); String newLocation = "/" + target + "/" + resolvedURI.toString().substring(baseURI.toString().length()); finalResponse.addHeader("Location", newLocation); // Header newLocationHeader = new BasicHeader("Location", // newLocation); if (logger.isDebugEnabled()) { logger.debug("adjustLocation from: " + locationHeader.getValue() + " to " + newLocation); } // proxiedResponse.addHeader(newLocationHeader); } else { finalResponse.addHeader(locationHeader.getName(), locationHeader.getValue()); } } catch (URISyntaxException e) { finalResponse.addHeader(locationHeader.getName(), locationHeader.getValue()); } } }
From source file:pl.psnc.dl.wf4ever.sms.SemanticMetadataServiceImplTest.java
@Test public final void getAggregatedResources() throws URISyntaxException, FileNotFoundException, ManifestTraversingException { URI fakeURI = new URI("http://www.example.com/ROs/"); File file = new File(PROJECT_PATH + "/src/test/resources/rdfStructure/ro1/.ro/manifest.ttl"); FileInputStream is = new FileInputStream(file); SemanticMetadataService sms = new SemanticMetadataServiceImpl(userProfile, ResearchObject.create(fakeURI), is, RDFFormat.TURTLE); //fill up data try {// w w w .ja va 2 s. c o m List<AggregatedResource> list = sms.getAggregatedResources(ResearchObject.create(fakeURI)); Assert.assertTrue(list.contains(new AggregatedResource(fakeURI.resolve("res1")))); Assert.assertTrue(list.contains(new AggregatedResource(fakeURI.resolve("res2")))); Assert.assertTrue(list.contains(new AggregatedResource(fakeURI.resolve("afinalfolder")))); Assert.assertFalse(list.contains(new AggregatedResource(fakeURI.resolve("ann1")))); } finally { sms.close(); } }
From source file:org.apache.ode.bpel.compiler.v1.BpelCompilerImpl.java
public void addWsdlImport(URI from, URI wsdlImport, SourceLocation sloc) { Definition4BPEL def;/*from w w w . java2 s.c o m*/ try { WSDLReader r = _wsdlFactory.newWSDLReader(); WSDLLocatorImpl locator = new WSDLLocatorImpl(_resourceFinder, from.resolve(wsdlImport)); def = (Definition4BPEL) r.readWSDL(locator); } catch (WSDLException e) { recoveredFromError(sloc, new CompilationException( __cmsgs.errWsdlParseError(e.getFaultCode(), e.getLocation(), e.getMessage()))); throw new CompilationException( __cmsgs.errWsdlImportFailed(wsdlImport.toASCIIString(), e.getFaultCode()).setSource(sloc), e); } try { _wsdlRegistry.addDefinition(def, _resourceFinder, from.resolve(wsdlImport)); if (__log.isDebugEnabled()) __log.debug("Added WSDL Definition: " + wsdlImport); } catch (CompilationException ce) { recoveredFromError(sloc, ce); } }
From source file:org.openremote.controller.service.Deployer.java
/** * TODO//w w w . ja v a 2 s. com * * @param resourcePath * @param config */ private void copyLircdConf(URI resourcePath, ControllerConfiguration config) { File lircdConfFile = new File(resourcePath.resolve(Constants.LIRCD_CONF).getPath()); File lircdconfDir = new File(config.getLircdconfPath().replaceAll(Constants.LIRCD_CONF, "")); try { if (lircdconfDir.exists() && lircdConfFile.exists()) { // this needs root user to put lircd.conf into /etc. // because it's readonly, or it won't be modified. if (config.isCopyLircdconf()) { FileUtils.copyFileToDirectory(lircdConfFile, lircdconfDir); log.info("copy lircd.conf to" + config.getLircdconfPath()); } } } catch (IOException e) { log.error("Can't copy lircd.conf to " + config.getLircdconfPath(), e); } }
From source file:org.apache.fop.apps.FopConfParser.java
private void configure(final URI baseURI, final ResourceResolver resourceResolver, Configuration cfg) throws FOPException { if (log.isDebugEnabled()) { log.debug("Initializing FopFactory Configuration"); }// w ww . j a va 2s.c o m // strict fo validation if (cfg.getChild("strict-validation", false) != null) { try { boolean strict = cfg.getChild("strict-validation").getValueAsBoolean(); fopFactoryBuilder.setStrictFOValidation(strict); } catch (ConfigurationException e) { LogUtil.handleException(log, e, false); } } boolean strict = false; if (cfg.getChild("strict-configuration", false) != null) { try { strict = cfg.getChild("strict-configuration").getValueAsBoolean(); fopFactoryBuilder.setStrictUserConfigValidation(strict); } catch (ConfigurationException e) { LogUtil.handleException(log, e, false); } } if (cfg.getChild("accessibility", false) != null) { try { fopFactoryBuilder.setAccessibility(cfg.getChild("accessibility").getValueAsBoolean()); } catch (ConfigurationException e) { LogUtil.handleException(log, e, false); } } // base definitions for relative path resolution if (cfg.getChild("base", false) != null) { try { URI confUri = InternalResourceResolver.getBaseURI(cfg.getChild("base").getValue(null)); fopFactoryBuilder.setBaseURI(baseURI.resolve(confUri)); } catch (URISyntaxException use) { LogUtil.handleException(log, use, strict); } } // renderer options if (cfg.getChild("source-resolution", false) != null) { float srcRes = cfg.getChild("source-resolution") .getValueAsFloat(FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION); fopFactoryBuilder.setSourceResolution(srcRes); if (log.isDebugEnabled()) { log.debug("source-resolution set to: " + srcRes + "dpi"); } } if (cfg.getChild("target-resolution", false) != null) { float targetRes = cfg.getChild("target-resolution") .getValueAsFloat(FopFactoryConfig.DEFAULT_TARGET_RESOLUTION); fopFactoryBuilder.setTargetResolution(targetRes); if (log.isDebugEnabled()) { log.debug("target-resolution set to: " + targetRes + "dpi"); } } if (cfg.getChild("break-indent-inheritance", false) != null) { try { fopFactoryBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary( cfg.getChild("break-indent-inheritance").getValueAsBoolean()); } catch (ConfigurationException e) { LogUtil.handleException(log, e, strict); } } Configuration pageConfig = cfg.getChild("default-page-settings"); if (pageConfig.getAttribute("height", null) != null) { String pageHeight = pageConfig.getAttribute("height", FopFactoryConfig.DEFAULT_PAGE_HEIGHT); fopFactoryBuilder.setPageHeight(pageHeight); if (log.isInfoEnabled()) { log.info("Default page-height set to: " + pageHeight); } } if (pageConfig.getAttribute("width", null) != null) { String pageWidth = pageConfig.getAttribute("width", FopFactoryConfig.DEFAULT_PAGE_WIDTH); fopFactoryBuilder.setPageWidth(pageWidth); if (log.isInfoEnabled()) { log.info("Default page-width set to: " + pageWidth); } } if (cfg.getChild("complex-scripts") != null) { Configuration csConfig = cfg.getChild("complex-scripts"); fopFactoryBuilder.setComplexScriptFeatures(!csConfig.getAttributeAsBoolean("disabled", false)); } setHyphPatNames(cfg, fopFactoryBuilder, strict); // prefer Renderer over IFDocumentHandler if (cfg.getChild(PREFER_RENDERER, false) != null) { try { fopFactoryBuilder.setPreferRenderer(cfg.getChild(PREFER_RENDERER).getValueAsBoolean()); } catch (ConfigurationException e) { LogUtil.handleException(log, e, strict); } } // configure font manager new FontManagerConfigurator(cfg, baseURI, fopFactoryBuilder.getBaseURI(), resourceResolver) .configure(fopFactoryBuilder.getFontManager(), strict); // configure image loader framework configureImageLoading(cfg.getChild("image-loading", false), strict); }
From source file:org.opencb.opencga.storage.hadoop.variant.AbstractHadoopVariantStoragePipeline.java
@Override public URI preLoad(URI input, URI output) throws StorageEngineException { boolean loadArch = options.getBoolean(HADOOP_LOAD_ARCHIVE); boolean loadVar = options.getBoolean(HADOOP_LOAD_VARIANT); if (!loadArch && !loadVar) { loadArch = true;//from w ww . java2 s .c o m loadVar = true; options.put(HADOOP_LOAD_ARCHIVE, loadArch); options.put(HADOOP_LOAD_VARIANT, loadVar); } if (loadArch) { super.preLoad(input, output); if (needLoadFromHdfs() && !input.getScheme().equals("hdfs")) { if (!StringUtils.isEmpty(options.getString(OPENCGA_STORAGE_HADOOP_INTERMEDIATE_HDFS_DIRECTORY))) { output = URI.create(options.getString(OPENCGA_STORAGE_HADOOP_INTERMEDIATE_HDFS_DIRECTORY)); } if (output.getScheme() != null && !output.getScheme().equals("hdfs")) { throw new StorageEngineException("Output must be in HDFS"); } try { long startTime = System.currentTimeMillis(); // Configuration conf = getHadoopConfiguration(options); FileSystem fs = FileSystem.get(conf); org.apache.hadoop.fs.Path variantsOutputPath = new org.apache.hadoop.fs.Path( output.resolve(Paths.get(input.getPath()).getFileName().toString())); logger.info("Copy from {} to {}", new org.apache.hadoop.fs.Path(input).toUri(), variantsOutputPath.toUri()); fs.copyFromLocalFile(false, new org.apache.hadoop.fs.Path(input), variantsOutputPath); logger.info("Copied to hdfs in {}s", (System.currentTimeMillis() - startTime) / 1000.0); startTime = System.currentTimeMillis(); URI fileInput = URI.create(VariantReaderUtils.getMetaFromTransformedFile(input.toString())); org.apache.hadoop.fs.Path fileOutputPath = new org.apache.hadoop.fs.Path( output.resolve(Paths.get(fileInput.getPath()).getFileName().toString())); logger.info("Copy from {} to {}", new org.apache.hadoop.fs.Path(fileInput).toUri(), fileOutputPath.toUri()); fs.copyFromLocalFile(false, new org.apache.hadoop.fs.Path(fileInput), fileOutputPath); logger.info("Copied to hdfs in {}s", (System.currentTimeMillis() - startTime) / 1000.0); input = variantsOutputPath.toUri(); } catch (IOException e) { e.printStackTrace(); } } } try { ArchiveDriver.createArchiveTableIfNeeded(dbAdaptor.getGenomeHelper(), archiveTableCredentials.getTable(), dbAdaptor.getConnection()); } catch (IOException e) { throw new StorageHadoopException("Issue creating table " + archiveTableCredentials.getTable(), e); } try { VariantTableDriver.createVariantTableIfNeeded(dbAdaptor.getGenomeHelper(), variantsTableCredentials.getTable(), dbAdaptor.getConnection()); } catch (IOException e) { throw new StorageHadoopException("Issue creating table " + variantsTableCredentials.getTable(), e); } if (loadVar) { preMerge(input); } return input; }
From source file:org.opendatakit.aggregate.odktables.api.perf.AggregateSynchronizer.java
private final URI normalizeUri(String aggregateUri, String additionalPathPortion) { URI uriBase = URI.create(aggregateUri).normalize(); String term = uriBase.getPath(); if (term.endsWith(FORWARD_SLASH)) { if (additionalPathPortion.startsWith(FORWARD_SLASH)) { term = term.substring(0, term.length() - 1); }//w w w . java 2s . c om } else if (!additionalPathPortion.startsWith(FORWARD_SLASH)) { term = term + FORWARD_SLASH; } term = term + additionalPathPortion; URI uri = uriBase.resolve(term).normalize(); logger.debug("normalizeUri: " + uri.toString()); return uri; }
From source file:org.dita.dost.module.GenMapAndTopicListModule.java
/** * Get pipe line filters//from w w w .j a v a2s . co m * * @param fileToParse absolute path to current file being processed */ private List<XMLFilter> getProcessingPipe(final URI fileToParse) { assert fileToParse.isAbsolute(); final List<XMLFilter> pipe = new ArrayList<>(); if (genDebugInfo) { final DebugFilter debugFilter = new DebugFilter(); debugFilter.setLogger(logger); debugFilter.setCurrentFile(currentFile); pipe.add(debugFilter); } if (filterUtils != null) { final ProfilingFilter profilingFilter = new ProfilingFilter(); profilingFilter.setLogger(logger); profilingFilter.setJob(job); profilingFilter.setFilterUtils(filterUtils); pipe.add(profilingFilter); } if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) { exportAnchorsFilter.setCurrentFile(fileToParse); exportAnchorsFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger)); pipe.add(exportAnchorsFilter); } keydefFilter.setCurrentDir(fileToParse.resolve(".")); keydefFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger)); pipe.add(keydefFilter); listFilter.setCurrentFile(fileToParse); listFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger)); pipe.add(listFilter); return pipe; }
From source file:org.opendatakit.sync.aggregate.AggregateSynchronizer.java
private final URI normalizeUri(String aggregateUri, String additionalPathPortion) { URI uriBase = URI.create(aggregateUri).normalize(); String term = uriBase.getPath(); if (term.endsWith(FORWARD_SLASH)) { if (additionalPathPortion.startsWith(FORWARD_SLASH)) { term = term.substring(0, term.length() - 1); }/*from ww w . ja va 2 s.c o m*/ } else if (!additionalPathPortion.startsWith(FORWARD_SLASH)) { term = term + FORWARD_SLASH; } term = term + additionalPathPortion; URI uri = uriBase.resolve(term).normalize(); log.d(LOGTAG, "normalizeUri: " + uri.toString()); return uri; }
From source file:org.opencb.opencga.app.cli.analysis.VariantCommandExecutor.java
@Deprecated private void stats(Job job) throws ClassNotFoundException, InstantiationException, CatalogException, IllegalAccessException, IOException, StorageManagerException { AnalysisCliOptionsParser.StatsVariantCommandOptions cliOptions = variantCommandOptions.statsVariantCommandOptions; // long inputFileId = catalogManager.getFileId(cliOptions.fileId); // 1) Initialize VariantStorageManager long studyId = catalogManager.getStudyId(cliOptions.studyId, sessionId); Study study = catalogManager.getStudy(studyId, sessionId).first(); /*//from w w w. ja va 2 s .com * Getting VariantStorageManager * We need to find out the Storage Engine Id to be used from Catalog */ DataStore dataStore = AbstractFileIndexer.getDataStore(catalogManager, studyId, File.Bioformat.VARIANT, sessionId); initVariantStorageManager(dataStore); /* * Create DBAdaptor */ VariantDBAdaptor dbAdaptor = variantStorageManager.getDBAdaptor(dataStore.getDbName()); StudyConfigurationManager studyConfigurationManager = dbAdaptor.getStudyConfigurationManager(); StudyConfiguration studyConfiguration = studyConfigurationManager.getStudyConfiguration((int) studyId, null) .first(); /* * Parse Options */ ObjectMap options = storageConfiguration.getStorageEngine(variantStorageManager.getStorageEngineId()) .getVariant().getOptions(); options.put(VariantStorageManager.Options.DB_NAME.key(), dataStore.getDbName()); options.put(VariantStorageManager.Options.OVERWRITE_STATS.key(), cliOptions.overwriteStats); options.put(VariantStorageManager.Options.UPDATE_STATS.key(), cliOptions.updateStats); if (cliOptions.region != null) { options.putIfNotNull(VariantDBAdaptor.VariantQueryParams.REGION.key(), cliOptions.region); } long fileId = catalogManager.getFileId(cliOptions.fileId, sessionId); if (fileId != 0) { options.put(VariantStorageManager.Options.FILE_ID.key(), fileId); } options.put(VariantStorageManager.Options.STUDY_ID.key(), studyId); if (cliOptions.commonOptions.params != null) { options.putAll(cliOptions.commonOptions.params); } Map<String, Integer> cohortIds = new HashMap<>(); Map<String, Set<String>> cohorts = new HashMap<>(); Properties aggregationMappingProperties = null; if (isNotEmpty(cliOptions.aggregationMappingFile)) { aggregationMappingProperties = new Properties(); try (InputStream is = new FileInputStream(cliOptions.aggregationMappingFile)) { aggregationMappingProperties.load(is); options.put(VariantStorageManager.Options.AGGREGATION_MAPPING_PROPERTIES.key(), aggregationMappingProperties); } catch (FileNotFoundException e) { logger.error("Aggregation mapping file {} not found. Population stats won't be parsed.", cliOptions.aggregationMappingFile); } } List<String> cohortNames; if (isEmpty(cliOptions.cohortIds)) { if (aggregationMappingProperties == null) { throw new IllegalArgumentException("Missing cohorts"); } else { cohortNames = new LinkedList<>( VariantAggregatedStatsCalculator.getCohorts(aggregationMappingProperties)); } } else { cohortNames = Arrays.asList(cliOptions.cohortIds.split(",")); } for (String cohort : cohortNames) { int cohortId; if (StringUtils.isNumeric(cohort)) { cohortId = Integer.parseInt(cohort); } else { if (studyConfiguration.getCohortIds().containsKey(cohort)) { cohortId = studyConfiguration.getCohortIds().get(cohort); } else { throw new IllegalArgumentException("Unknown cohort name " + cohort); } } Set<String> samples = studyConfiguration.getCohorts().get(cohortId).stream() .map(sampleId -> studyConfiguration.getSampleIds().inverse().get(sampleId)) .collect(Collectors.toSet()); cohorts.put(studyConfiguration.getCohortIds().inverse().get(cohortId), samples); } options.put(VariantStorageManager.Options.AGGREGATED_TYPE.key(), cliOptions.aggregated); /* * Create and load stats */ // URI outputUri = UriUtils.createUri(cliOptions.fileName == null ? "" : cliOptions.fileName); // URI outputUri = job.getTmpOutDirUri(); URI outputUri = IndexDaemon.getJobTemporaryFolder(job.getId(), catalogConfiguration.getTempJobsDir()) .toUri(); String filename; if (isEmpty(cliOptions.fileName)) { filename = VariantStorageManager.buildFilename(studyConfiguration.getStudyName(), (int) fileId); } else { filename = cliOptions.fileName; } // assertDirectoryExists(directoryUri); VariantStatisticsManager variantStatisticsManager = new VariantStatisticsManager(); boolean doCreate = true; boolean doLoad = true; // doCreate = statsVariantsCommandOptions.create; // doLoad = statsVariantsCommandOptions.load != null; // if (!statsVariantsCommandOptions.create && statsVariantsCommandOptions.load == null) { // doCreate = doLoad = true; // } else if (statsVariantsCommandOptions.load != null) { // filename = statsVariantsCommandOptions.load; // } QueryOptions queryOptions = new QueryOptions(options); if (doCreate) { filename += "." + TimeUtils.getTime(); outputUri = outputUri.resolve(filename); outputUri = variantStatisticsManager.createStats(dbAdaptor, outputUri, cohorts, cohortIds, studyConfiguration, queryOptions); } if (doLoad) { outputUri = outputUri.resolve(filename); variantStatisticsManager.loadStats(dbAdaptor, outputUri, studyConfiguration, queryOptions); } }