List of usage examples for java.net URI getHost
public String getHost()
From source file:org.apache.storm.elasticsearch.common.EsConfig.java
/** * EsConfig Constructor to be used in EsIndexBolt, EsPercolateBolt and EsStateFactory * * @param urls Elasticsearch addresses in scheme://host:port pattern string array * @throws IllegalArgumentException if urls are empty * @throws NullPointerException on any of the fields being null *//*from w ww. j a va 2 s . co m*/ public EsConfig(String... urls) { if (urls.length == 0) { throw new IllegalArgumentException("urls is required"); } this.httpHosts = new HttpHost[urls.length]; for (int i = 0; i < urls.length; i++) { URI uri = toURI(urls[i]); this.httpHosts[i] = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); } }
From source file:com.redhat.jenkins.plugins.bayesian.Bayesian.java
public Bayesian(String url) throws URISyntaxException { URI uri = new URI(url); String host = uri.getHost(); if (host.indexOf('.') == -1) { // looks like it's a short domain name // TODO: there can be dots in short domain names as well List<String> cnames = DnsFiddler.getActualCNAME(host); if (!cnames.isEmpty()) { String hostname = cnames.get(0); if (hostname.endsWith(".")) { hostname = hostname.substring(0, hostname.length() - 1); }/*from w ww . j av a2 s . c om*/ uri = new URIBuilder(uri).setHost(hostname).build(); } cnames = null; } this.url = uri.toString(); }
From source file:com.subgraph.vega.internal.model.web.WebModel.java
private HttpHost uriToHost(URI uri) { return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:org.geosdi.geoplatform.connector.server.security.PreemptiveSecurityConnector.java
protected HttpHost extractHost(URI uri) { if (this.httpHost == null) { this.httpHost = new HttpHost(uri.getHost(), this.retrieveNoSetPort(uri), uri.getScheme()); }/*from ww w. ja v a2 s. c o m*/ return this.httpHost; }
From source file:fakingXmocking.CurrencyConversionHttpClientFake.java
@Mock public HttpResponse execute(HttpUriRequest req) { URI uri = req.getURI(); final String response; if ("www.jhall.demon.co.uk".equals(uri.getHost())) { response = "<h3>Currency Data</h3>\r\n" + "<table><tr>\r\n" + " <td valign=top>USD</td>\r\n" + " <td valign=top>EUR</td>\r\n" + " <td valign=top>BRL</td>\r\n" + " <td valign=top>CNY</td>\r\n" + "</tr></table>"; } else {//from w w w.j a v a 2 s . c o m String[] params = uri.getQuery().split("&"); response = formatResultContainingCurrencyConversion(params); } return new BasicHttpResponse(req.getProtocolVersion(), 200, "OK") { @Override public HttpEntity getEntity() { return createHttpResponse(response); } }; }
From source file:org.n52.ses.util.http.SESHttpClient.java
public SESHttpResponse sendPost(URL destination, String content, ContentType contentType) throws Exception { checkSetup();//from w ww . j a v a 2 s. c o m if (this.authenticator != null) { URI uri = destination.toURI(); HttpHost host = new HttpHost(uri.getHost(), uri.getPort()); this.httpClient.provideAuthentication(host, this.authenticator.getUsername(), this.authenticator.getPassword()); } HttpResponse postResponse = this.httpClient.executePost(destination.toString(), content, contentType); SESHttpResponse response = null; if (postResponse != null && postResponse.getEntity() != null) { response = new SESHttpResponse(postResponse.getEntity().getContent(), postResponse.getEntity().getContentType().getValue()); } else if (postResponse != null && postResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { return SESHttpResponse.NO_CONTENT_RESPONSE; } return response; }
From source file:com.garethahealy.resteastpathparamescape.utils.RestFactory.java
protected HttpClientContext getBasicAuthContext(URI uri, String userName, String password) { HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password)); // Create AuthCache instance // Generate BASIC scheme object and add it to the local auth cache AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); // Add AuthCache to the execution context HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache);//from w w w . j a va 2 s . c o m return context; }
From source file:org.apache.olingo.client.core.http.BasicAuthHttpClientFactory.java
@Override public DefaultHttpClient create(final HttpMethod method, final URI uri) { final DefaultHttpClient httpclient = super.create(method, uri); httpclient.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); return httpclient; }
From source file:com.collective.celos.ci.deploy.JScpWorker.java
URI getURIRespectingUsername(URI uri) throws URISyntaxException { if (userName != null && uri.getUserInfo() == null) { uri = new URI(uri.getScheme(), userName, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());/*from w w w . j a v a2 s . co m*/ } return uri; }
From source file:com.gopivotal.cla.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() {//from w w w .j a va2 s .com URI dbUri = URI.create(this.databaseUrl); String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); String[] userInfoTokens = dbUri.getUserInfo().split(":"); dataSource.setUsername(userInfoTokens.length > 0 ? userInfoTokens[0] : ""); dataSource.setPassword(userInfoTokens.length > 1 ? userInfoTokens[1] : ""); dataSource.setMaxConnectionsPerPartition(2); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setLocations("META-INF/db/migration"); flyway.migrate(); return dataSource; }