List of usage examples for java.net URI getScheme
public String getScheme()
From source file:edu.stolaf.cs.wmrserver.JobServiceHandler.java
/** * Relativize the given path with respect to the WMR home directory *//*from w w w .j a v a 2 s .c o m*/ public static Path relativizePath(Path parentPath, Path childPath) { URI relative = parentPath.toUri().relativize(childPath.toUri()); return new Path(relative.getScheme(), relative.getAuthority(), relative.getPath()); }
From source file:org.hl7.fhir.client.ResourceAddress.java
public static URI buildEndpointUriFromString(String endpointPath) { URI uri = null; try {/*from w w w .jav a 2s .com*/ URIBuilder uriBuilder = new URIBuilder(endpointPath); uri = uriBuilder.build(); String scheme = uri.getScheme(); String host = uri.getHost(); if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) { throw new EFhirClientException("Scheme must be 'http' or 'https': " + uri); } if (StringUtils.isBlank(host)) { throw new EFhirClientException("host cannot be blank: " + uri); } } catch (URISyntaxException e) { throw new EFhirClientException("Invalid URI", e); } return uri; }
From source file:com.google.u2f.server.impl.U2FServerReferenceImpl.java
static String canonicalizeOrigin(String url) { URI uri; try {/*from w ww .j a v a 2 s . c o m*/ uri = new URI(url); } catch (URISyntaxException e) { throw new RuntimeException("specified bad origin", e); } return uri.getScheme() + "://" + uri.getAuthority(); }
From source file:co.cask.cdap.etl.tool.UpgradeTool.java
private static ClientConfig getClientConfig(CommandLine commandLine) throws IOException { String uriStr = commandLine.hasOption("u") ? commandLine.getOptionValue("u") : "localhost:10000"; if (!uriStr.contains("://")) { uriStr = "http://" + uriStr; }/* w w w . j a v a 2 s . c o m*/ URI uri = URI.create(uriStr); String hostname = uri.getHost(); int port = uri.getPort(); boolean sslEnabled = "https".equals(uri.getScheme()); ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port) .setSSLEnabled(sslEnabled).build(); int readTimeout = commandLine.hasOption("t") ? Integer.parseInt(commandLine.getOptionValue("t")) : DEFAULT_READ_TIMEOUT_MILLIS; ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(readTimeout) .setConnectionConfig(connectionConfig); if (commandLine.hasOption("a")) { String tokenFilePath = commandLine.getOptionValue("a"); File tokenFile = new File(tokenFilePath); if (!tokenFile.exists()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " does not exist."); } if (!tokenFile.isFile()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " is not a file."); } String tokenValue = new String(Files.readAllBytes(tokenFile.toPath()), StandardCharsets.UTF_8).trim(); AccessToken accessToken = new AccessToken(tokenValue, 82000L, "Bearer"); clientConfigBuilder.setAccessToken(accessToken); } return clientConfigBuilder.build(); }
From source file:io.github.swagger2markup.Swagger2MarkupConverter.java
/** * Creates a Swagger2MarkupConverter.Builder from a URI. * * @param swaggerUri the URI/*w ww . j a v a 2s.co m*/ * @return a Swagger2MarkupConverter */ public static Builder from(URI swaggerUri) { Validate.notNull(swaggerUri, "swaggerUri must not be null"); String scheme = swaggerUri.getScheme(); if (scheme != null && swaggerUri.getScheme().startsWith("http")) { try { return from(swaggerUri.toURL()); } catch (MalformedURLException e) { throw new RuntimeException("Failed to convert URI to URL", e); } } else if (scheme != null && swaggerUri.getScheme().startsWith("file")) { return from(Paths.get(swaggerUri)); } else { return from(URIUtils.convertUriWithoutSchemeToFileScheme(swaggerUri)); } }
From source file:password.pwm.http.servlet.oauth.OAuthMachine.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final String debugSource; final String redirect_uri; {//from w w w . j a va 2 s. c o m final String returnUrlOverride = pwmRequest.getConfig() .readAppProperty(AppProperty.OAUTH_RETURN_URL_OVERRIDE); final String siteURL = pwmRequest.getConfig().readSettingAsString(PwmSetting.PWM_SITE_URL); if (returnUrlOverride != null && !returnUrlOverride.trim().isEmpty()) { debugSource = "AppProperty(\"" + AppProperty.OAUTH_RETURN_URL_OVERRIDE.getKey() + "\")"; redirect_uri = returnUrlOverride + PwmServletDefinition.OAuthConsumer.servletUrl(); } else if (siteURL != null && !siteURL.trim().isEmpty()) { debugSource = "SiteURL Setting"; redirect_uri = siteURL + PwmServletDefinition.OAuthConsumer.servletUrl(); } else { debugSource = "Input Request URL"; final String inputURI = pwmRequest.getHttpServletRequest().getRequestURL().toString(); try { final URI requestUri = new URI(inputURI); final int port = requestUri.getPort(); redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost() + (port > 0 && port != 80 && port != 443 ? ":" + requestUri.getPort() : "") + pwmRequest.getContextPath() + PwmServletDefinition.OAuthConsumer.servletUrl(); } catch (URISyntaxException e) { throw new IllegalStateException( "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage()); } } } LOGGER.trace("calculated oauth self end point URI as '" + redirect_uri + "' using method " + debugSource); return redirect_uri; }
From source file:cn.org.rapid_framework.generator.util.ResourceHelper.java
/** * Resolve the given resource URI to a <code>java.io.File</code>, * i.e. to a file in the file system.// www . j a v a 2s .co m * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { if (resourceUri == null) throw new IllegalArgumentException("Resource URL must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException(description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitBusCleaner.java
@VisibleForTesting static RestTemplate buildRestTemplate(String adminUri, String user, String password) { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local; from the apache docs... // auth cache BasicScheme basicAuth = new BasicScheme(); URI uri;/*from ww w . j av a2 s .com*/ try { uri = new URI(adminUri); } catch (URISyntaxException e) { throw new RabbitAdminException("Invalid URI", e); } authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); // Add AuthCache to the execution context final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return localContext; } }); restTemplate.setMessageConverters( Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter())); return restTemplate; }
From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java
/** * Get the URI with irrelevant components (Fragment and Querystring) * stripped off/*from ww w . j av a2 s .co m*/ * * @param input * URI * @return URI with irrelevant components stripped off or null if stripping * is impossible */ private static String stripIrrelevantComponents(String input) { try { URI orig = new URI(input); return new URI(orig.getScheme(), orig.getUserInfo(), orig.getHost(), orig.getPort(), orig.getPath(), null, null).toString(); } catch (URISyntaxException e) { return null; } }
From source file:com.legstar.codegen.CodeGenUtil.java
/** * Checks that a URI is valid and HTTP scheme. * // w ww .j a v a 2 s.c om * @param httpUri the URI to check * @throws CodeGenMakeException if URI has wrong syntax */ public static void checkHttpURI(final String httpUri) throws CodeGenMakeException { try { if (httpUri == null || httpUri.length() == 0) { throw new CodeGenMakeException("You must specify a valid URI"); } URI uri = new URI(httpUri); if (uri.getScheme() == null || uri.getScheme().compareToIgnoreCase("http") != 0) { throw new CodeGenMakeException("URI " + uri + " must have http scheme"); } } catch (URISyntaxException e) { throw new CodeGenMakeException(e); } }