List of usage examples for java.net URI getScheme
public String getScheme()
From source file:com.pwc.sns.testsupport.WireMockTestClient.java
public WireMockResponse getViaProxy(String url, int proxyPort) { URI targetUri = URI.create(url); HttpHost proxy = new HttpHost(address, proxyPort, targetUri.getScheme()); DefaultHttpClient httpclient = new DefaultHttpClient(createClientConnectionManagerWithSSLSettings()); try {// w ww.j ava 2 s . c om httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpHost target = new HttpHost(targetUri.getHost(), targetUri.getPort(), targetUri.getScheme()); HttpGet req = new HttpGet( targetUri.getPath() + (isNullOrEmpty(targetUri.getQuery()) ? "" : "?" + targetUri.getQuery())); req.removeHeaders("Host"); System.out.println("executing request to " + targetUri + "(" + target + ") via " + proxy); HttpResponse httpResponse = httpclient.execute(target, req); return new WireMockResponse(httpResponse); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:org.restheart.test.performance.AbstractPT.java
public void prepare() { Authenticator.setDefault(new Authenticator() { @Override//w ww . ja v a2 s . c o m protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(id, pwd.toCharArray()); } }); Configuration conf; StringBuilder ymlSB = new StringBuilder(); if (mongoUri != null) { ymlSB.append(Configuration.MONGO_URI_KEY).append(": ").append(mongoUri).append("\n"); } Yaml yaml = new Yaml(); Map<String, Object> configuration = (Map<String, Object>) yaml.load(ymlSB.toString()); try { MongoDBClientSingleton.init(new Configuration(configuration, true)); } catch (ConfigurationException ex) { System.out.println(ex.getMessage() + ", exiting..."); System.exit(-1); } httpExecutor = Executor.newInstance(); // for perf test better to disable the restheart security if (url != null && id != null && pwd != null) { String host = "127.0.0.1"; int port = 8080; String scheme = "http"; try { URI uri = new URI(url); host = uri.getHost(); port = uri.getPort(); scheme = uri.getScheme(); } catch (URISyntaxException ex) { Logger.getLogger(LoadPutPT.class.getName()).log(Level.SEVERE, null, ex); } httpExecutor.authPreemptive(new HttpHost(host, port, scheme)).auth(new HttpHost(host), id, pwd); } }
From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurer.java
/** * Configures the {@link HttpClientBuilder} with a proxy host. If the * {@code proxyUsername} and {@code proxyPassword} are not {@code null} * then a {@link CredentialsProvider} is also configured for the proxy host. * * @param proxyUri Must not be null and must be configured with a scheme (http or https). * @param proxyUsername May be null/*from www .j a v a 2 s. c o m*/ * @param proxyPassword May be null * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer withProxyCredentials(URI proxyUri, String proxyUsername, String proxyPassword) { Assert.notNull(proxyUri, "The proxyUri must not be null."); Assert.hasText(proxyUri.getScheme(), "The scheme component of the proxyUri must not be empty."); httpClientBuilder.setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme())); if (proxyUsername != null && proxyPassword != null) { final CredentialsProvider credentialsProvider = this.getOrInitializeCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(proxyUri.getHost(), proxyUri.getPort()), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } return this; }
From source file:com.smartitengineering.util.simple.reflection.DefaultClassScannerImpl.java
private void scanForVisit(URI u, String filePackageName, ClassVisitor classVisitor) { String scheme = u.getScheme(); if (scheme.equals("file")) { File f = new File(u.getPath()); if (f.isDirectory()) { scanDir(f, false, classVisitor); } else {// w ww . j av a 2 s .c o m } } else if (scheme.equals("jar") || scheme.equals("zip")) { URI jarUri = URI.create(u.getRawSchemeSpecificPart()); String jarFile = jarUri.getPath(); jarFile = jarFile.substring(0, jarFile.indexOf('!')); scanJar(new File(jarFile), filePackageName, classVisitor); } else { } }
From source file:com.seajas.search.profiler.wsdl.FeedTesting.java
/** * {@inheritDoc}//from www . j av a 2s .co m */ @Override public FeedResult isValidFeedUrl(final String url, final Boolean ignoreExisting) { FeedResult result = new FeedResult(); if (!Boolean.TRUE.equals(ignoreExisting)) { List<Feed> existingFeeds = profilerService.getFeedsByUrl(url); if (existingFeeds != null && existingFeeds.size() > 0) { if (logger.isInfoEnabled()) logger.info("The given feed URL already exists"); result.setStatus(Status.ALREADY_EXISTS); return result; } } // Validate the URL first URI validatedUri; try { validatedUri = new URI(url); if (!StringUtils.hasText(validatedUri.getScheme()) || !StringUtils.hasText(validatedUri.getHost())) throw new URISyntaxException("", "No scheme and/or host provided"); } catch (URISyntaxException e) { if (logger.isInfoEnabled()) logger.info("The given feed URL is not valid", e); result.setStatus(Status.UNKNOWN); return result; } // Then run it through the testing service for exploration try { Map<String, Boolean> testingResult = testingService.exploreUri(validatedUri); if (logger.isInfoEnabled()) logger.info("Exploration resulted in " + testingResult.size() + " result URL(s)"); List<String> validUrls = new ArrayList<String>(); for (Entry<String, Boolean> testingResultEntry : testingResult.entrySet()) { validUrls.add(testingResultEntry.getKey()); if (testingResultEntry.getValue()) { if (logger.isInfoEnabled()) logger.info("The given URL '" + url + "' is a direct RSS feed"); result.setStatus(Status.VALID); break; } else result.setStatus(Status.INDIRECTLY_VALID); } result.setValidUrls(validUrls); } catch (TestingException e) { if (logger.isInfoEnabled()) logger.info("URL exploration was unsuccessful", e); result.setStatus(Status.UNKNOWN); } return result; }
From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpacker.java
/** * Tries to return a sensible default media path for multi-volume installations. * <p/>// w w w.j a v a 2 s .c o m * This returns: * <ul> * <li>the directory the installer is located in; or </li> * <li>the user directory, if the installer location can't be determined</li> * </ul> * * @return the default media path. May be <tt>null</tt> */ private String getDefaultMediaPath() { String result = null; try { CodeSource codeSource = getClass().getProtectionDomain().getCodeSource(); if (codeSource != null) { URI uri = codeSource.getLocation().toURI(); if ("file".equals(uri.getScheme())) { File dir = new File(uri.getSchemeSpecificPart()).getAbsoluteFile(); if (dir.getName().endsWith(".jar")) { dir = dir.getParentFile(); } result = dir.getPath(); } } } catch (URISyntaxException exception) { // ignore } if (result == null) { result = System.getProperty("user.dir"); } return result; }
From source file:com.microsoft.gittf.client.clc.connection.GitTFHTTPClientFactory.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. * /*from w w w.j a va 2s. com*/ * @param host * 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(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; } 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 (IllegalStateException e) { serverPort = 80; } } for (String nonProxyHost : nonProxyHosts.split(",")) //$NON-NLS-1$ { int nonProxyPort = -1; if (nonProxyHost.contains(":")) //$NON-NLS-1$ { String[] nonProxyParts = nonProxyHost.split(":", 2); //$NON-NLS-1$ nonProxyHost = nonProxyParts[0]; try { nonProxyPort = Integer.parseInt(nonProxyParts[1]); } catch (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:com.machinepublishers.jbrowserdriver.CookieStore.java
/** * {@inheritDoc}// w w w. j a va 2s. c o m */ @Override public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException { if (isJavascript(uri.getScheme())) { for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) { for (String value : entry.getValue()) { try { List<Cookie> cookies = spec.parse(new BasicHeader(entry.getKey(), value), new CookieOrigin(uri.getHost(), canonicalPort(uri.getScheme(), uri.getPort()), canonicalPath(uri.getPath()), isSecure(uri.getScheme()))); for (Cookie cookie : cookies) { synchronized (store) { store.addCookie(cookie); } } } catch (MalformedCookieException e) { LogsServer.instance().warn( "Malformed cookie for cookie named " + entry.getKey() + ". " + e.getMessage()); } } } } }
From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java
/** * <p>//w ww .ja v a 2s. c o m * TEE will automatically correct the endpoints registered URL when creating * the web service, however we must provide a mechansim to correct fully * qualified URI's provided as additional URI from the same webservice. * </p> * <p> * We compare the passed uri with the registered web service endpoint, if * they share the same root (i.e. http://TFSERVER) then we correct the * passed uri to be the same as the corrected web service enpoint (i.e. * http://tfsserver.mycompany.com) * </p> * * @see WSSClient#getFixedURI(String) */ public String getFixedURI(final String uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ try { // Get what the server thinks the url is. String url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING); if (url == null || url.length() == 0) { // Might be a Rosario server url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING_WEB_SERVICE_URL); if (url == null || url.length() == 0) { // Couldn't figure this out - just give up and return what // we // were passed. return uri; } is2010Server = true; } final URI registeredEndpointUri = new URI(url); final URI passedUri = new URI(uri); if (passedUri.getScheme().equals(registeredEndpointUri.getScheme()) && passedUri.getHost().equals(registeredEndpointUri.getHost()) && passedUri.getPort() == registeredEndpointUri.getPort()) { final URI endpointUri = ((SOAPService) getProxy()).getEndpoint(); final URI fixedUri = new URI(endpointUri.getScheme(), endpointUri.getHost(), passedUri.getPath(), passedUri.getQuery(), passedUri.getFragment()); return fixedUri.toASCIIString(); } } catch (final URISyntaxException e) { // ignore; } return uri; }