List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.subgraph.vega.internal.model.web.WebPath.java
private URI generateURI() { final URI hostUri = mountPoint.getWebHost().getUri(); try {//w ww.j a va 2 s. c o m return new URI(hostUri.getScheme(), hostUri.getAuthority(), getFullPath(), null, null); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:gobblin.service.FlowConfigsResource.java
/** * Delete a configured flow. Running flows are not affected. The schedule will be removed for scheduled flows. * @param key composite key containing flow group and flow name that identifies the flow to remove from the * {@link FlowCatalog}//from ww w . java 2s . c o m * @return {@link UpdateResponse} */ @Override public UpdateResponse delete(ComplexResourceKey<FlowId, EmptyRecord> key) { String flowGroup = key.getKey().getFlowGroup(); String flowName = key.getKey().getFlowName(); URI flowUri = null; LOG.info("Delete called with flowGroup " + flowGroup + " flowName " + flowName); try { URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null); flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowGroup + "/" + flowName, null, null); FlowSpec flowSpec = (FlowSpec) getFlowCatalog().getSpec(flowUri); getFlowCatalog().remove(flowUri); return new UpdateResponse(HttpStatus.S_200_OK); } catch (URISyntaxException e) { logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowUri, e); } catch (SpecNotFoundException e) { logAndThrowRestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Flow does not exist: flowGroup " + flowGroup + " flowName " + flowName, null); } return null; }
From source file:com.box.restclientv2.httpclientsupport.HttpClientURIBuilder.java
private void digestURI(final URI uri) throws URISyntaxException { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), HttpClientConsts.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.helger.peppol.httpclient.AbstractGenericSMPClient.java
/** * Constructor with a direct SMP URL.<br> * Remember: must be HTTP and using port 80 only! * * @param aSMPHost/*from w w w . ja va2s. c o m*/ * The address of the SMP service. Must be port 80 and basic http only * (no https!). Example: http://smpcompany.company.org */ public AbstractGenericSMPClient(@Nonnull final URI aSMPHost) { ValueEnforcer.notNull(aSMPHost, "SMPHost"); if (!"http".equals(aSMPHost.getScheme())) s_aLogger.warn("SMP URI " + aSMPHost + " does not use the expected http scheme!"); // getPort () returns -1 if none was explicitly specified if (aSMPHost.getPort() != 80 && aSMPHost.getPort() != -1) s_aLogger.warn("SMP URI " + aSMPHost + " is not running on port 80!"); // Build string and ensure it ends with a "/" final String sSMPHost = aSMPHost.toString(); m_sSMPHost = sSMPHost.endsWith("/") ? sSMPHost : sSMPHost + '/'; // Set default proxy from configuration file m_aProxy = SMPClientConfiguration.getHttpProxy(); }
From source file:edu.unc.lib.dl.ingest.aip.VirusScanFilter.java
public ArchivalInformationPackage doFilter(ArchivalInformationPackage aip) throws AIPException { log.debug("Starting"); // get ClamScan software and database versions String version = this.clamScan.cmd("nVERSION\n".getBytes()).trim(); Map<String, String> failures = new HashMap<String, String>(); for (PID pid : aip.getPIDs()) { Document foxml = aip.getFOXMLDocument(pid); for (Element cLocation : FOXMLJDOMUtil.getFileLocators(foxml)) { String ref = cLocation.getAttributeValue("REF"); String dsid = cLocation.getParentElement().getParentElement().getAttributeValue("ID"); URI uri; try { uri = new URI(ref); } catch (URISyntaxException e) { throw new AIPException("Unable to construct URI for a METS file location.", e); }// w ww . j a v a 2 s . co m if (uri.getScheme() == null || uri.getScheme().contains("file")) { File file = aip.getFileForUrl(ref); ScanResult result = this.clamScan.scan(file); switch (result.getStatus()) { case FAILED: Element ev = aip.getEventLogger().logEvent(PremisEventLogger.Type.VIRUS_CHECK, "File failed pre-ingest scan for viruses.", pid, dsid); PremisEventLogger.addSoftwareAgent(ev, "ClamAV", version); PremisEventLogger.addDetailedOutcome(ev, "failure", "found virus signature " + result.getSignature(), null); failures.put(uri.toString(), result.getSignature()); break; case ERROR: throw new AIPException("Virus checks are producing errors: " + result.getException().getLocalizedMessage()); case PASSED: Element ev2 = aip.getEventLogger().logEvent(PremisEventLogger.Type.VIRUS_CHECK, "File passed pre-ingest scan for viruses.", pid, dsid); PremisEventLogger.addSoftwareAgent(ev2, "ClamAV", version); PremisEventLogger.addDetailedOutcome(ev2, "success", null, null); break; } } } } if (failures.size() > 0) { StringBuilder sb = new StringBuilder("Virus checks failed for some files:\n"); for (String uri : failures.keySet()) { sb.append(uri).append(" - ").append(failures.get(uri)).append("\n"); } throw new AIPException(sb.toString()); } log.debug("Finished"); return aip; }
From source file:be.solidx.hot.nio.http.SSLContextBuilder.java
private InputStream getInputStream(URI uri) throws IOException { InputStream jksFileInputStream; if (uri.getScheme() != null && uri.equals("file")) { jksFileInputStream = new FileInputStream(new File(uri)); } else {//from w w w . ja v a 2 s. c o m if (uri.isAbsolute()) { jksFileInputStream = getClass().getResourceAsStream(uri.getPath()); } else { jksFileInputStream = getClass().getClassLoader().getResourceAsStream(uri.getPath()); } } return jksFileInputStream; }
From source file:gobblin.service.FlowConfigsResource.java
/** * Update the flow configuration with the specified key. Running flows are not affected. * An error is raised if the flow configuration does not exist. * @param key composite key containing group name and flow name that identifies the flow to update * @param flowConfig new flow configuration * @return {@link UpdateResponse}//from w w w . ja v a2s . co m */ @Override public UpdateResponse update(ComplexResourceKey<FlowId, EmptyRecord> key, FlowConfig flowConfig) { String flowGroup = key.getKey().getFlowGroup(); String flowName = key.getKey().getFlowName(); URI flowUri = null; LOG.info("Update called with flowGroup " + flowGroup + " flowName " + flowName); if (!flowGroup.equals(flowConfig.getId().getFlowGroup()) || !flowName.equals(flowConfig.getId().getFlowName())) { logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "flowName and flowGroup cannot be changed in update", null); } try { URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null); flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowGroup + "/" + flowName, null, null); FlowSpec oldFlowSpec = (FlowSpec) getFlowCatalog().getSpec(flowUri); FlowSpec newFlowSpec = createFlowSpecForConfig(flowConfig); getFlowCatalog().put(newFlowSpec); return new UpdateResponse(HttpStatus.S_200_OK); } catch (URISyntaxException e) { logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowUri, e); } catch (SpecNotFoundException e) { logAndThrowRestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Flow does not exist: flowGroup " + flowGroup + " flowName " + flowName, null); } return null; }
From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java
/** * Tries to find an existing readable URI.<br> * <ul>/* ww w . j av a 2 s. c o m*/ * <li>if the URI isn't absolute: * <ul> * <li>if a new location is available it is resolved against that</li> * <li>if an old location is available it is resolved against that</li> * </ul> * </li> * <li>if the URI is absolute: * <ul> * <li>if an old and a new location is available it is transformed in the * same way</li> * <li>the URI is used as is</li> * </ul> * </li> * </ul> * If none of the applicable cases results in a valid, existing URI and * tryFallback is true {@link #updatePathFallback(URI)} is returned, * otherwise <code>null</code> is returned. * * @param uri the URI in question * @param tryFallback whether to use {@link #updatePathFallback(URI)} in the * end or not * @param allowResource whether to allow resolving through {@link Resources} * @param keepRelative If the URI is relative to the new location and * keepRelative is set, the URI is returned as is.<br> * Also, if the URI is relative to the old location and it is * possible to construct a relative path to the new location, * that is returned * @return a valid, existing URI or <code>null</code> */ public URI findLocation(URI uri, boolean tryFallback, boolean allowResource, boolean keepRelative) { if ("jdbc".equals(uri.getScheme())) { // not possible to update JDBC URLs or test the stream return uri; } if (!uri.isAbsolute()) { if (newLocation != null) { URI newAbsolute = newLocation.resolve(uri); if (HaleIO.testStream(newAbsolute, allowResource)) { if (keepRelative) { return uri; } else { return newAbsolute; } } else { // Check if the resource file name needs // to be URL-encoded first (for project archives // that were created w/ hale studio 3.2.0 and before) String resourcePath = FilenameUtils.getPath(uri.toString()); String resourceFileName = FilenameUtils.getName(uri.toString()); try { String encodedPath = resourcePath + URLEncoder.encode(resourceFileName, "UTF-8"); URI encodedUri = URI.create(encodedPath); newAbsolute = newLocation.resolve(encodedUri); if (HaleIO.testStream(newAbsolute, allowResource)) { if (keepRelative) { return encodedUri; } else { return newAbsolute; } } } catch (UnsupportedEncodingException e) { log.debug(MessageFormat.format("Could not URL-encode \"{0}\"", resourceFileName), e); } } } if (oldLocation != null) { URI oldAbsolute = oldLocation.resolve(uri); if (HaleIO.testStream(oldAbsolute, allowResource)) { if (keepRelative) return IOUtils.getRelativePath(oldAbsolute, newLocation); else return oldAbsolute; } } } else { if (oldLocation != null && newLocation != null) { URI changed = changePath(uri); if (HaleIO.testStream(changed, allowResource)) return changed; } if (HaleIO.testStream(uri, allowResource)) return uri; } if (tryFallback) return updatePathFallback(uri); else return null; }
From source file:gobblin.service.FlowConfigsResource.java
/** * Create a flow configuration that the service will forward to execution instances for execution * @param flowConfig flow configuration/*from w w w. j a va 2s .c o m*/ * @return {@link CreateResponse} */ @Override public CreateResponse create(FlowConfig flowConfig) { LOG.info("Create called with flowName " + flowConfig.getId().getFlowName()); LOG.info("ReadyToUse is: " + readyToUse); LOG.info("FlowCatalog is: " + getFlowCatalog()); if (!readyToUse && getFlowCatalog() == null) { throw new RuntimeException("Not ready for use."); } try { URI flowCatalogURI = new URI("gobblin-flow", null, "/", null, null); URI flowUri = new URI(flowCatalogURI.getScheme(), flowCatalogURI.getAuthority(), "/" + flowConfig.getId().getFlowGroup() + "/" + flowConfig.getId().getFlowName(), null, null); if (getFlowCatalog().getSpec(flowUri) != null) { logAndThrowRestLiServiceException(HttpStatus.S_409_CONFLICT, "Flow with the same name already exists: " + flowUri, null); } } catch (URISyntaxException e) { logAndThrowRestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "bad URI " + flowConfig.getId().getFlowName(), e); } catch (SpecNotFoundException e) { // okay if flow does not exist } getFlowCatalog().put(createFlowSpecForConfig(flowConfig)); return new CreateResponse(flowConfig.getId().getFlowName(), HttpStatus.S_201_CREATED); }
From source file:com.codeabovelab.dm.gateway.proxy.common.HttpProxyContext.java
public HttpProxyContext(HttpServletRequest request, HttpServletResponse response, URI target, String uid) { this.request = request; Assert.notNull(request, "request is null"); this.response = response; Assert.notNull(response, "response is null"); this.target = target; Assert.notNull(target, "target is null"); this.targetHost = new HttpHost(target.getHost(), target.getPort(), target.getScheme()); this.uid = uid; }