List of usage examples for java.net URI getScheme
public String getScheme()
From source file:org.forgerock.json.ref.jackson.JacksonReferenceTransformer.java
@Override protected boolean isResolvable(URI uri) { String scheme = (uri == null ? null : uri.getScheme()); return (scheme != null && (scheme.equalsIgnoreCase("file") || scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))); }
From source file:org.apache.hadoop.gateway.hbase.HBaseCookieManager.java
protected HttpRequest createKerberosAuthenticationRequest(HttpUriRequest userRequest) { URI userUri = userRequest.getURI(); try {// w w w. j ava 2 s . c om URI authUri = new URI(userUri.getScheme(), null, userUri.getHost(), userUri.getPort(), "/version", userUri.getQuery(), null); HttpRequest authRequest = new HttpGet(authUri); return authRequest; } catch (URISyntaxException e) { throw new IllegalArgumentException(userUri.toString(), e); } }
From source file:org.jets3t.service.utils.SignatureUtils.java
/** * Replace the hostname of the given URI endpoint to match the given region. * * @param uri//from w w w .j a v a 2 s . c om * @param region * * @return * URI with hostname that may or may not have been changed to be appropriate * for the given region. For example, the hostname "s3.amazonaws.com" is * unchanged for the "us-east-1" region but for the "eu-central-1" region * becomes "s3-eu-central-1.amazonaws.com". */ public static URI awsV4CorrectHostnameForRegion(URI uri, String region) { String[] hostSplit = uri.getHost().split("\\."); if (region.equals("us-east-1")) { hostSplit[hostSplit.length - 3] = "s3"; } else { hostSplit[hostSplit.length - 3] = "s3-" + region; } String newHost = ServiceUtils.join(hostSplit, "."); try { String rawPathAndQuery = uri.getRawPath(); if (uri.getRawQuery() != null) { rawPathAndQuery += "?" + uri.getRawQuery(); } return new URL(uri.getScheme(), newHost, uri.getPort(), rawPathAndQuery).toURI(); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.smartitengineering.cms.ws.resources.content.ContentResource.java
protected static ContentTypeResource getContentTypeResource(String uri, ServerResourceInjectables injectables) throws ClassCastException, ContainerException { final URI checkUri; if (uri.startsWith("http:")) { checkUri = URI.create(uri); } else {/*from w w w . jav a 2s. c om*/ URI absUri = injectables.getUriInfo().getBaseUriBuilder().build(); checkUri = UriBuilder.fromPath(uri).host(absUri.getHost()).port(absUri.getPort()) .scheme(absUri.getScheme()).build(); } return injectables.getResourceContext().matchResource(checkUri, ContentTypeResource.class); }
From source file:com.jaeksoft.searchlib.web.AbstractServlet.java
protected static URI buildUri(URI uri, String additionalPath, String indexName, String login, String apiKey, String additionnalQuery) throws URISyntaxException { StringBuilder path = new StringBuilder(uri.getPath()); if (additionalPath != null) path.append(additionalPath);// ww w . ja v a 2 s . c om StringBuilder query = new StringBuilder(); if (indexName != null) { query.append("index="); query.append(indexName); } if (login != null) { query.append("&login="); query.append(login); } if (apiKey != null) { query.append("&key="); query.append(apiKey); } if (additionnalQuery != null) { if (query.length() > 0) query.append("&"); query.append(additionnalQuery); } return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path.toString(), query.toString(), uri.getFragment()); }
From source file:brooklyn.util.ResourceUtils.java
public static URL tidy(URL url) { // File class has helpful methods for URIs but not URLs. So we convert. URI in; try {/*from ww w .j a v a 2s .com*/ in = url.toURI(); } catch (URISyntaxException e) { throw Exceptions.propagate(e); } URI out; Matcher matcher = pattern.matcher(in.toString()); if (matcher.matches()) { // home-relative File home = new File(Os.home()); File file = new File(home, matcher.group(1)); out = file.toURI(); } else if (in.getScheme().equals("file:")) { // some other file, so canonicalize File file = new File(in); out = file.toURI(); } else { // some other scheme, so no-op out = in; } URL urlOut; try { urlOut = out.toURL(); } catch (MalformedURLException e) { throw Exceptions.propagate(e); } if (!urlOut.equals(url) && log.isDebugEnabled()) { log.debug("quietly changing " + url + " to " + urlOut); } return urlOut; }
From source file:org.springframework.cloud.dataflow.shell.command.support.HttpClientUtils.java
/** * Ensures that the passed-in {@link RestTemplate} is using the Apache HTTP Client. If the optional {@code username} AND * {@code password} are not empty, then a {@link BasicCredentialsProvider} will be added to the {@link CloseableHttpClient}. * * Furthermore, you can set the underlying {@link SSLContext} of the {@link HttpClient} allowing you to accept self-signed * certificates./* w w w .j ava 2 s . co m*/ * * @param restTemplate Must not be null * @param username Can be null * @param password Can be null * @param skipSslValidation Use with caution! If true certificate warnings will be ignored. */ public static void prepareRestTemplate(RestTemplate restTemplate, URI host, String username, String password, boolean skipSslValidation) { Assert.notNull(restTemplate, "The provided RestTemplate must not be null."); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (StringUtils.hasText(username) && StringUtils.hasText(password)) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } if (skipSslValidation) { httpClientBuilder.setSSLContext(HttpClientUtils.buildCertificateIgnoringSslContext()); httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); } final CloseableHttpClient httpClient = httpClientBuilder.build(); final HttpHost targetHost = new HttpHost(host.getHost(), host.getPort(), host.getScheme()); final HttpComponentsClientHttpRequestFactory requestFactory = new PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory( httpClient, targetHost); restTemplate.setRequestFactory(requestFactory); }
From source file:org.fishwife.jrugged.httpclient.AbstractHttpClientDecorator.java
protected HttpHost getHttpHost(HttpUriRequest req) { URI uri = req.getURI(); String scheme = uri.getScheme(); if ("HTTPS".equalsIgnoreCase(scheme)) { return new HttpHost(uri.getScheme() + "://" + uri.getAuthority()); } else {/*from w ww. j a v a 2s . co m*/ return new HttpHost(uri.getAuthority()); } }
From source file:com.orange.clara.cloud.servicedbdumper.helper.UrlForge.java
public String createDownloadLink(DatabaseDumpFile databaseDumpFile) { URI appInUri = URI.create(appUri); String port = this.getPortInString(); return appInUri.getScheme() + "://" + databaseDumpFile.getUser() + ":" + databaseDumpFile.getPassword() + "@" + appInUri.getHost() + port + DOWNLOAD_ROUTE + "/" + databaseDumpFile.getId(); }
From source file:com.orange.clara.cloud.servicedbdumper.helper.UrlForge.java
public String createShowLink(DatabaseDumpFile databaseDumpFile) { if (!databaseDumpFile.isShowable()) { return ""; }/*from w ww . j a v a 2 s. c o m*/ URI appInUri = URI.create(appUri); String port = this.getPortInString(); return appInUri.getScheme() + "://" + appInUri.getHost() + port + SHOW_ROUTE + "/" + databaseDumpFile.getId(); }