List of usage examples for java.net URI getScheme
public String getScheme()
From source file:io.druid.storage.hdfs.HdfsDataSegmentPuller.java
@Override public InputStream getInputStream(URI uri) throws IOException { if (!uri.getScheme().equalsIgnoreCase(HdfsStorageDruidModule.SCHEME)) { throw new IAE("Don't know how to load SCHEME [%s] for URI [%s]", uri.getScheme(), uri.toString()); }/*ww w . j a v a2s .co m*/ return buildFileObject(uri, config).openInputStream(); }
From source file:com.norconex.collector.http.url.impl.TikaLinkExtractor.java
private String resolve(String docURL, String extractedURL) { try {/* ww w . j a v a 2 s . c o m*/ URI uri = new URI(extractedURL); if (uri.getScheme() == null) { uri = new URI(docURL).resolve(extractedURL); } return uri.toString(); } catch (URISyntaxException e) { LOG.error( "Could not resolve extracted URL: \"" + extractedURL + "\" from document \"" + docURL + "\"."); } return null; }
From source file:com.microsoft.tfs.client.clc.CLCHTTPClientFactory.java
/** * Determines whether the given host should be proxied or not, based on the * comma-separated list of wildcards to not proxy (generally taken from the * <code>http.nonProxyHosts</code> system property. * * @param host/*from w ww. j a v a 2 s .c om*/ * the host to query (not <code>null</code>) * @param nonProxyHosts * the pipe-separated list of hosts (or wildcards) that should not be * proxied, or <code>null</code> if all hosts are proxied * @return <code>true</code> if the host should be proxied, * <code>false</code> otherwise */ static boolean hostExcludedFromProxyEnvironment(final URI serverURI, String nonProxyHosts) { if (serverURI == null || serverURI.getHost() == null || nonProxyHosts == null) { return false; } nonProxyHosts = nonProxyHosts.trim(); if (nonProxyHosts.length() == 0) { return false; } /* * The no_proxy setting may be '*' to indicate nothing is proxied. * However, this is the only allowable use of a wildcard. */ if ("*".equals(nonProxyHosts)) //$NON-NLS-1$ { return true; } final String serverHost = serverURI.getHost(); /* Map default ports to the appropriate default. */ int serverPort = serverURI.getPort(); if (serverPort == -1) { try { serverPort = Protocol.getProtocol(serverURI.getScheme().toLowerCase()).getDefaultPort(); } catch (final IllegalStateException e) { serverPort = 80; } } for (String nonProxyHost : nonProxyHosts.split(",")) //$NON-NLS-1$ { int nonProxyPort = -1; if (nonProxyHost.contains(":")) //$NON-NLS-1$ { final String[] nonProxyParts = nonProxyHost.split(":", 2); //$NON-NLS-1$ nonProxyHost = nonProxyParts[0]; try { nonProxyPort = Integer.parseInt(nonProxyParts[1]); } catch (final Exception e) { log.warn(MessageFormat.format("Could not parse port in non_proxy setting: {0}, ignoring port", //$NON-NLS-1$ nonProxyParts[1])); } } /* * If the no_proxy entry specifies a port, match it exactly. If it * does not, this means to match all ports. */ if (nonProxyPort != -1 && serverPort != nonProxyPort) { continue; } /* * Otherwise, the nonProxyHost portion is treated as the trailing * DNS entry */ if (LocaleInvariantStringHelpers.caseInsensitiveEndsWith(serverHost, nonProxyHost)) { return true; } } return false; }
From source file:org.dkpro.lab.engine.impl.DefaultTaskContextFactory.java
protected void resolveImports(TaskContext aContext) { for (Entry<String, String> e : aContext.getMetadata().getImports().entrySet()) { URI uri = URI.create(e.getValue()); // Try resolving by type if (LATEST_CONTEXT_SCHEME.equals(uri.getScheme()) || CONTEXT_ID_SCHEME.equals(uri.getScheme())) { String uuid;/*w w w .ja v a 2 s .c o m*/ uuid = aContext.resolve(uri).getId(); if (!getStorageService().containsKey(uuid, uri.getPath())) { throw new UnresolvedImportException(aContext, e.getKey(), e.getValue(), "Key not found"); } String resolvedUri = CONTEXT_ID_SCHEME + "://" + uuid + uri.getPath(); log.debug("Resolved import [" + e.getValue() + "] -> [" + resolvedUri + "]"); e.setValue(resolvedUri); } } }
From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java
public static String removeBVParameters(String url) { String newUrl = url;//from ww w . ja va2 s . c om if (newUrl.contains("bvstate=")) { // Handle usecase with more parameters after bvstate newUrl = newUrl.replaceAll(BVConstant.BVSTATE_REGEX_WITH_TRAILING_SEPARATOR, ""); // Handle usecase where bvstate is the last parameter if (newUrl.endsWith("?") | newUrl.endsWith("&")) { newUrl = newUrl.substring(0, newUrl.length() - 1); } if (newUrl.endsWith(BVConstant.ESCAPED_FRAGMENT_MULTIVALUE_SEPARATOR)) { newUrl = newUrl.substring(0, newUrl.length() - 3); } } if (hasBVQueryParameters(newUrl)) { final URI uri; try { uri = new URI(newUrl); } catch (URISyntaxException e) { return newUrl; } try { String newQuery = null; if (uri.getQuery() != null && uri.getQuery().length() > 0) { List<NameValuePair> newParameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), Charset.forName("UTF-8")); for (NameValuePair parameter : parameters) { if (!bvQueryParameters.contains(parameter.getName())) { newParameters.add(parameter); } } newQuery = newParameters.size() > 0 ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8")) : null; } return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString(); } catch (URISyntaxException e) { return newUrl; } } return newUrl; }
From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java
/** * Submit a job request.//from ww w . ja v a 2 s . c om * * @param request The job request * @param httpClient http client used to reporting status to job callback. * @return SandboxedJob job * * @throws OctopusIOException * @throws OctopusException * @throws URISyntaxException */ public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient) throws OctopusIOException, OctopusException, URISyntaxException { Credential credential = configuration.getCredential(); // filesystems cant have path in them so strip eg. file:///tmp to file:/// URI s = configuration.getSandboxRoot(); URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(), s.getFragment()); //create sandbox FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null); String sandboxRoot = configuration.getSandboxRoot().getPath(); AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot)); Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null); // create job description JobDescription description = request.toJobDescription(); description.setQueueName(configuration.getQueue()); description.setWorkingDirectory(sandbox.getPath().getPath()); long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout(); // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS); description.setMaxTime(maxTime); // stage input files sandbox.upload(); // submit job Job job = octopus.jobs().submitJob(scheduler, description); // store job in jobs map SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient); jobs.put(sjob.getIdentifier(), sjob); // JobsPoller will poll job status and download sandbox when job is done. return sjob; }
From source file:de.thingweb.client.ClientFactory.java
public Client getClientUrl(URI jsonld) throws JsonParseException, IOException, UnsupportedException, URISyntaxException { // URL can't handle coap uris --> use URI only if (isCoapScheme(jsonld.getScheme())) { CoapClient coap = new CoapClient(jsonld); // synchronous coap byte[] content = coap.get().getPayload(); thing = ThingDescriptionParser.fromBytes(content); return getClient(); } else {//from ww w. j a v a 2 s . co m return getClientUrl(jsonld.toURL()); } }
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private String getProtocolHostPort(URI u) throws MalformedURLException { return String.format("%s://%s%s", u.getScheme(), u.getHost(), u.getPort() >= 0 ? ":" + u.getPort() : ""); }
From source file:at.gv.egiz.bku.online.webapp.MoccaParameterBean.java
public String getAppletBackground() { String background = getString(PARAM_APPLET_BACKGROUND); if (background != null && !background.isEmpty()) { try {//from w ww. j a v a 2 s.c om // must be a valid http or https URL URI backgroundURL = new URI(background); if ("http".equals(backgroundURL.getScheme()) || "https".equals(backgroundURL.getScheme())) { return background.toString(); } else { log.warn("Parameter " + PARAM_APPLET_BACKGROUND + "='{}' is not a valid http/https URL.", background); } } catch (URISyntaxException e) { log.warn("Parameter " + PARAM_APPLET_BACKGROUND + "='{}' is not a valid http/https URL.", background, e); } } return null; }
From source file:com.ark.website.filter.CORSFilter.java
/** * Checks if a given origin is valid or not. Criteria: * <ul>/*from w w w . j a va2 s. c o m*/ * <li>If an encoded character is present in origin, it's not valid.</li> * <li>Origin should be a valid {@link URI}</li> * </ul> * * @param origin * @see <a href="http://tools.ietf.org/html/rfc952">RFC952</a> * @return */ public static boolean isValidOrigin(String origin) { // Checks for encoded characters. Helps prevent CRLF injection. if (origin.contains("%")) { return false; } URI originURI; try { originURI = new URI(origin); } catch (URISyntaxException e) { return false; } // If scheme for URI is null, return false. Return true otherwise. return originURI.getScheme() != null; }