List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java
private static File toClassPathRoot(Class<?> aClass, String uriQualifiedPath) { assert aClass != null; assert uriQualifiedPath != null; int entry = uriQualifiedPath.lastIndexOf('!'); String qualifier;// w w w . j a v a 2 s.com if (entry >= 0) { qualifier = uriQualifiedPath.substring(0, entry); } else { qualifier = uriQualifiedPath; } URI archive; try { archive = new URI(qualifier); } catch (URISyntaxException e) { LOG.warn(MessageFormat.format("Failed to locate the JAR library file {}: {}", qualifier, aClass.getName()), e); throw new UnsupportedOperationException(qualifier, e); } if (archive.getScheme().equals("file") == false) { LOG.warn("Failed to locate the library path (unsupported protocol {}): {}", archive, aClass.getName()); return null; } File file = new File(archive); assert file.isFile() : file; return file; }
From source file:com.microsoft.tfs.core.clients.registration.RegistrationData.java
public static String makeChildLocationName(final URI serverURI, final String instanceID) { Check.notNull(serverURI, "serverURI"); //$NON-NLS-1$ Check.notNull(instanceID, "instanceID"); //$NON-NLS-1$ final StringBuffer buffer = new StringBuffer(); buffer.append(instanceID.toLowerCase()); buffer.append("_"); //$NON-NLS-1$ buffer.append(serverURI.getScheme().toLowerCase()); return buffer.toString(); }
From source file:de.betterform.agent.web.WebFactory.java
/** * get the absolute file path for a given relative path in the webapp. Handles some differences in server behavior * with the execution of context.getRealPath on various servers/operating systems * * @param path a path relative to the context root of the webapp * @param context the servletcontext/*www. j ava2 s . c om*/ * @return the absolute file path for given relative webapp path */ public static String getRealPath(String path, ServletContext context) throws XFormsConfigException { if (path == null) { path = "/"; } if (!path.startsWith("/")) { path = "/" + path; } try { URI resourceURI = null; String computedRealPath = null; URL rootURL = Thread.currentThread().getContextClassLoader().getResource("/"); URL resourceURL = context.getResource(path); if (rootURL != null) { resourceURI = rootURL.toURI(); } if (resourceURI != null && resourceURI.getScheme().equalsIgnoreCase("file")) { String resourcePath = rootURL.getPath(); String rootPath = new File(resourcePath).getParentFile().getParent(); computedRealPath = new File(rootPath, path).getAbsolutePath(); } else if (resourceURL != null) { computedRealPath = new File(resourceURL.toExternalForm(), path).getAbsolutePath(); } else { String resourcePath = context.getRealPath("/"); computedRealPath = new File(resourcePath, path).getAbsolutePath(); } return java.net.URLDecoder.decode(computedRealPath, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } catch (URISyntaxException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } catch (MalformedURLException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } }
From source file:com.ibm.jaggr.core.test.TestUtils.java
private static IResource mockAggregatorNewResource(URI uri, File workDir) throws Throwable { final String aggrResPath = "/com.ibm.jaggr.core/"; // path for bundle resource in the aggregator String scheme = uri.getScheme(); if ("file".equals(scheme)) { return new FileResource(uri); } else if ("namedbundleresource".equals(scheme)) { if (uri.getPath().startsWith(aggrResPath)) { String path = uri.getPath().substring(aggrResPath.length()); return new FileResource(IAggregator.class.getClassLoader().getResource(path).toURI()); }//from w w w . j a v a2 s .c o m return new FileResource(new File(workDir, uri.getPath()).toURI()); } throw new UnsupportedOperationException(); }
From source file:org.pepstock.jem.commands.util.HttpUtil.java
/** * Configures SSL HTTP client, if necessary * /*w w w .j a v a2s .c om*/ * @param uri http URI to call * @return HTTP client * @throws KeyManagementException * @throws UnrecoverableKeyException * @throws NoSuchAlgorithmException * @throws KeyStoreException */ public static final CloseableHttpClient createHttpClient(URI uri) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { // sets SSL ONLY if the scheme is HTTPS return createHttpClientByScheme(uri.getScheme()).build(); }
From source file:com.netflix.iep.http.RxHttp.java
/** * Return the port taking care of handling defaults for http and https if not explicit in the * uri.//from w w w . j a va 2 s.c om */ static int getPort(URI uri) { final int defaultPort = ("https".equals(uri.getScheme())) ? 443 : 80; return (uri.getPort() <= 0) ? defaultPort : uri.getPort(); }
From source file:password.pwm.http.servlet.OAuthConsumerServlet.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final HttpServletRequest req = pwmRequest.getHttpServletRequest(); final String redirect_uri; try {/*from w w w . jav a2s . c om*/ final URI requestUri = new URI(req.getRequestURL().toString()); redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost() + (requestUri.getPort() > 0 ? ":" + requestUri.getPort() : "") + PwmServletDefinition.OAuthConsumer.servletUrl(); } catch (URISyntaxException e) { throw new IllegalStateException( "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage()); } return redirect_uri; }
From source file:edu.harvard.hul.ois.drs.pdfaconvert.PdfaConvert.java
private static void loadApplicationPropertiesFile() { // Set the projects properties. // First look for a system property pointing to a project properties file. // This value can be either a file path, file protocol (e.g. - file:/path/to/file), // or a URL (http://some/server/file). // If this value either does not exist or is not valid, the default // file that comes with this application will be used for initialization. String environmentProjectPropsFile = System.getProperty(ApplicationConstants.ENV_PROJECT_PROPS); logger.info("Have {} from environment: {}", ApplicationConstants.PROJECT_PROPS, environmentProjectPropsFile); URI projectPropsUri = null; if (environmentProjectPropsFile != null) { try {//from www . java 2 s .c o m projectPropsUri = new URI(environmentProjectPropsFile); // properties file needs a scheme in the URI so convert to file if necessary. if (null == projectPropsUri.getScheme()) { File projectProperties = new File(environmentProjectPropsFile); if (projectProperties.exists() && projectProperties.isFile()) { projectPropsUri = projectProperties.toURI(); } else { // No scheme and not a file - yikes!!! Let's bail and // use fall-back file. projectPropsUri = null; throw new URISyntaxException(environmentProjectPropsFile, "Not a valid file"); } } } catch (URISyntaxException e) { // fall back to default file logger.error("Unable to load properties file: {} -- reason: {}", environmentProjectPropsFile, e.getReason()); logger.error("Falling back to default {} file: {}", ApplicationConstants.PROJECT_PROPS, ApplicationConstants.PROJECT_PROPS); } } applicationProps = new Properties(); // load properties if environment value set if (projectPropsUri != null) { File envPropFile = new File(projectPropsUri); if (envPropFile.exists() && envPropFile.isFile() && envPropFile.canRead()) { Reader reader; try { reader = new FileReader(envPropFile); logger.info("About to load {} from environment: {}", ApplicationConstants.PROJECT_PROPS, envPropFile.getAbsolutePath()); applicationProps.load(reader); logger.info("Success -- loaded properties file."); } catch (IOException e) { logger.error("Could not load environment properties file: {}", projectPropsUri, e); // set URI back to null so default prop file loaded projectPropsUri = null; } } } if (projectPropsUri == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { InputStream resourceStream = loader.getResourceAsStream(ApplicationConstants.PROJECT_PROPS); applicationProps.load(resourceStream); logger.info("loaded default applicationProps: "); } catch (IOException e) { logger.error("Could not load properties file: {}", ApplicationConstants.PROJECT_PROPS, e); // couldn't load default properties so bail... throw new RuntimeException("Couldn't load an applications properties file.", e); } } }
From source file:org.esigate.DriverFactory.java
/** * Selects the Driver instance for this request based on the mappings declared in the configuration. * //from w ww . jav a 2 s . c o m * @param request * the incoming request * * @return a {@link MatchedRequest} containing the {@link Driver} instance and the relative URI * * @throws HttpErrorPage * if no instance was found for this request */ static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; }
From source file:annis.libgui.Helper.java
public static String generateClassicCitation(String aql, List<String> corpora, int contextLeft, int contextRight) { StringBuilder sb = new StringBuilder(); URI appURI = UI.getCurrent().getPage().getLocation(); sb.append(getContext());//from w ww .jav a 2 s.c om sb.append("/Cite/AQL("); sb.append(aql); sb.append("),CIDS("); sb.append(StringUtils.join(corpora, ",")); sb.append("),CLEFT("); sb.append(contextLeft); sb.append("),CRIGHT("); sb.append(contextRight); sb.append(")"); try { return new URI(appURI.getScheme(), null, appURI.getHost(), appURI.getPort(), sb.toString(), null, null) .toASCIIString(); } catch (URISyntaxException ex) { log.error(null, ex); } return "ERROR"; }