List of usage examples for java.net URI getScheme
public String getScheme()
From source file:password.pwm.http.servlet.oauth.OAuthConsumerServlet.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final String inputURI, debugSource; {//www . j av a2 s. c om 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()) { inputURI = returnUrlOverride; debugSource = "AppProperty(\"" + AppProperty.OAUTH_RETURN_URL_OVERRIDE.getKey() + "\")"; } else if (siteURL != null && !siteURL.trim().isEmpty()) { inputURI = siteURL; debugSource = "SiteURL Setting"; } else { debugSource = "Input Request URL"; inputURI = pwmRequest.getHttpServletRequest().getRequestURL().toString(); } } final String redirect_uri; try { final URI requestUri = new URI(inputURI); 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()); } LOGGER.trace("calculated oauth self end point URI as '" + redirect_uri + "' using method " + debugSource); return redirect_uri; }
From source file:org.soyatec.windowsazure.authenticate.HttpRequestAccessor.java
/** * Given the service endpoint in case of path-style URIs, path contains * container name and remaining part if they are present, this method * constructs the Full Uri.//from w w w . ja v a 2 s . c o m * * @param endPoint * @param path * @return Full URI */ private static URI constructUriFromUriAndString(URI endPoint, String path) { // This is where we encode the url path to be valid String encodedPath = Utilities.encode(path); if (!Utilities.isNullOrEmpty(encodedPath) && encodedPath.charAt(0) != ConstChars.Slash.charAt(0)) { encodedPath = ConstChars.Slash + encodedPath; } try { // @Note : rename blob with blank spaces in name return new URI(endPoint.getScheme(), null, endPoint.getHost(), endPoint.getPort(), encodedPath.replaceAll("%20", " "), endPoint.getQuery(), endPoint.getFragment()); // return new URI(endPoint.getScheme(), endPoint.getHost(), // encodedPath, endPoint.getFragment()); } catch (URISyntaxException e) { Logger.error("Can not new URI", e); return null; } }
From source file:org.aludratest.cloud.selenium.impl.SeleniumHttpProxy.java
public static SeleniumHttpProxy create(int id, SeleniumResourceImpl resource, String prefix, long timeout, long maxIdleTime, String accessUrl, ScheduledExecutorService healthCheckExecutor) { URI oUri = URI.create(resource.getOriginalUrl()); SeleniumHttpProxy proxy = new SeleniumHttpProxy(oUri.getScheme(), prefix, oUri.getHost(), oUri.getPort(), oUri.getPath());/* w ww . j a va 2 s. c om*/ proxy.id = id; proxy.resource = resource; proxy.timeout = timeout; proxy.accessUrl = accessUrl; proxy.maxIdleTime = maxIdleTime; proxy.healthCheckClient = createHealthCheckHttpClient(); proxy.healthCheckExecutor = healthCheckExecutor; // set resource to DISCONNECTED first resource.setState(ResourceState.DISCONNECTED); proxy.nextHealthCheck = healthCheckExecutor.schedule(proxy.checkStatusRunnable, 2000, TimeUnit.MILLISECONDS); return proxy; }
From source file:com.ibm.amc.FileManager.java
public static synchronized void setReferenceCount(URI file, int referenceCount) { if (logger.isEntryEnabled()) logger.entry("setReferenceCount", file, referenceCount); if (file == null) return;//from www. j a va 2s. c om if (!file.getScheme().equalsIgnoreCase(SCHEME)) return; // Only manage our own files. references.put(file, referenceCount); if (logger.isEntryEnabled()) logger.exit("setReferenceCount"); }
From source file:com.gamesalutes.utils.WebUtils.java
/** * Adds the query parameters to the uri <code>path</code>. * // w ww . j a v a2 s . c o m * @param path the uri * @param parameters the query parameters to set for the uri * @return <code>path</code> with the query parameters added */ public static URI setQueryParameters(URI path, Map<String, String> parameters) { try { return new URI(path.getScheme(), path.getRawUserInfo(), path.getHost(), path.getPort(), path.getRawPath(), urlEncode(parameters, false), path.getRawFragment()); } catch (URISyntaxException e) { // shouldn't happen throw new AssertionError(e); } }
From source file:org.eclipse.mylyn.commons.http.HttpUtil.java
public static HttpHost createHost(HttpRequestBase method) { URI uri = method.getURI(); return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:com.kegare.caveworld.util.CaveUtils.java
public static boolean archiveDirZip(final File dir, final File dest) { final Path dirPath = dir.toPath(); final String parent = dir.getName(); Map<String, String> env = Maps.newHashMap(); env.put("create", "true"); URI uri = dest.toURI(); try {//from ww w.jav a2 s . co m uri = new URI("jar:" + uri.getScheme(), uri.getPath(), null); } catch (Exception e) { return false; } try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { Files.createDirectory(zipfs.getPath(parent)); for (File file : dir.listFiles()) { if (file.isDirectory()) { Files.walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, zipfs.getPath(parent, dirPath.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Files.createDirectory(zipfs.getPath(parent, dirPath.relativize(dir).toString())); return FileVisitResult.CONTINUE; } }); } else { Files.copy(file.toPath(), zipfs.getPath(parent, file.getName()), StandardCopyOption.REPLACE_EXISTING); } } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
/** * Method returns a BufferedReader for the passes URI. * /*from www . ja va2 s . co m*/ * @param filePath * @return * @throws MalformedURLException * @throws IOException */ private static BufferedReader getReader(URI filePath) throws MalformedURLException, IOException { BufferedReader reader = null; if (filePath.getScheme().equals("file")) { reader = new BufferedReader(new FileReader(new File(filePath))); } else { reader = new BufferedReader(new InputStreamReader(filePath.toURL().openConnection().getInputStream())); } return reader; }
From source file:org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.java
private static Node readNode(String nodeId, JsonParser parser, Scheme scheme) throws IOException { HttpHost publishedHost = null;/*from w w w .ja v a2s.co m*/ /* * We sniff the bound hosts so we can look up the node based on any * address on which it is listening. This is useful in Elasticsearch's * test framework where we sometimes publish ipv6 addresses but the * tests contact the node on ipv4. */ Set<HttpHost> boundHosts = new HashSet<>(); String name = null; String version = null; /* * Multi-valued attributes come with key = `real_key.index` and we * unflip them after reading them because we can't rely on the order * that they arive. */ final Map<String, String> protoAttributes = new HashMap<String, String>(); boolean sawRoles = false; boolean master = false; boolean data = false; boolean ingest = false; String fieldName = null; while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { fieldName = parser.getCurrentName(); } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { if ("http".equals(fieldName)) { while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { URI publishAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); publishedHost = new HttpHost(publishAddressAsURI.getHost(), publishAddressAsURI.getPort(), publishAddressAsURI.getScheme()); } else if (parser.currentToken() == JsonToken.START_ARRAY && "bound_address".equals(parser.getCurrentName())) { while (parser.nextToken() != JsonToken.END_ARRAY) { URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); boundHosts.add(new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), boundAddressAsURI.getScheme())); } } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { parser.skipChildren(); } } } else if ("attributes".equals(fieldName)) { while (parser.nextToken() != JsonToken.END_OBJECT) { if (parser.getCurrentToken() == JsonToken.VALUE_STRING) { String oldValue = protoAttributes.put(parser.getCurrentName(), parser.getValueAsString()); if (oldValue != null) { throw new IOException("repeated attribute key [" + parser.getCurrentName() + "]"); } } else { parser.skipChildren(); } } } else { parser.skipChildren(); } } else if (parser.currentToken() == JsonToken.START_ARRAY) { if ("roles".equals(fieldName)) { sawRoles = true; while (parser.nextToken() != JsonToken.END_ARRAY) { switch (parser.getText()) { case "master": master = true; break; case "data": data = true; break; case "ingest": ingest = true; break; default: logger.warn("unknown role [" + parser.getText() + "] on node [" + nodeId + "]"); } } } else { parser.skipChildren(); } } else if (parser.currentToken().isScalarValue()) { if ("version".equals(fieldName)) { version = parser.getText(); } else if ("name".equals(fieldName)) { name = parser.getText(); } } } //http section is not present if http is not enabled on the node, ignore such nodes if (publishedHost == null) { logger.debug("skipping node [" + nodeId + "] with http disabled"); return null; } Map<String, List<String>> realAttributes = new HashMap<>(protoAttributes.size()); List<String> keys = new ArrayList<>(protoAttributes.keySet()); for (String key : keys) { if (key.endsWith(".0")) { String realKey = key.substring(0, key.length() - 2); List<String> values = new ArrayList<>(); int i = 0; while (true) { String value = protoAttributes.remove(realKey + "." + i); if (value == null) { break; } values.add(value); i++; } realAttributes.put(realKey, unmodifiableList(values)); } } for (Map.Entry<String, String> entry : protoAttributes.entrySet()) { realAttributes.put(entry.getKey(), singletonList(entry.getValue())); } if (version.startsWith("2.")) { /* * 2.x doesn't send roles, instead we try to read them from * attributes. */ boolean clientAttribute = v2RoleAttributeValue(realAttributes, "client", false); Boolean masterAttribute = v2RoleAttributeValue(realAttributes, "master", null); Boolean dataAttribute = v2RoleAttributeValue(realAttributes, "data", null); master = masterAttribute == null ? false == clientAttribute : masterAttribute; data = dataAttribute == null ? false == clientAttribute : dataAttribute; } else { assert sawRoles : "didn't see roles for [" + nodeId + "]"; } assert boundHosts.contains(publishedHost) : "[" + nodeId + "] doesn't make sense! publishedHost should be in boundHosts"; logger.trace("adding node [" + nodeId + "]"); return new Node(publishedHost, boundHosts, name, version, new Roles(master, data, ingest), unmodifiableMap(realAttributes)); }
From source file:io.confluent.rest.Application.java
static List<URI> parseListeners(List<String> listenersConfig, int deprecatedPort) { // handle deprecated case, using PORT_CONFIG. // TODO: remove this when `PORT_CONFIG` is deprecated, because LISTENER_CONFIG will have a default value which // includes the default port. if (listenersConfig.isEmpty() || listenersConfig.get(0).isEmpty()) { log.warn(//w w w . ja v a 2s .c o m "DEPRECATION warning: `listeners` configuration is not configured. Falling back to the deprecated " + "`port` configuration."); listenersConfig = new ArrayList<String>(1); listenersConfig.add("http://0.0.0.0:" + deprecatedPort); } List<URI> listeners = new ArrayList<URI>(listenersConfig.size()); for (String listenerStr : listenersConfig) { URI uri; try { uri = new URI(listenerStr); } catch (URISyntaxException use) { throw new ConfigException( "Could not parse a listener URI from the `listener` configuration option."); } String scheme = uri.getScheme(); if (scheme != null && (scheme.equals("http") || scheme.equals("https"))) { listeners.add(uri); } else { log.warn("Found a listener with an unsupported scheme (ony http and https are supported). Ignoring " + "listener '" + listenerStr + "'"); } } if (listeners.isEmpty()) { throw new ConfigException("No listeners are configured. Must have at least one listener."); } return listeners; }