List of usage examples for java.net URI getPort
public int getPort()
From source file:com.netflix.spinnaker.kork.jedis.JedisPoolFactory.java
public Pool<Jedis> build(String name, JedisDriverProperties properties) { if (properties.connection == null || "".equals(properties.connection)) { throw new MissingRequiredConfiguration("Jedis client must have a connection defined"); }//from w w w .j a v a 2s . co m URI redisConnection = URI.create(properties.connection); String host = redisConnection.getHost(); int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort(); int database = parseDatabase(redisConnection.getPath()); String password = parsePassword(redisConnection.getUserInfo()); GenericObjectPoolConfig objectPoolConfig = properties.poolConfig; boolean isSSL = redisConnection.getScheme().equals("rediss"); return new InstrumentedJedisPool(registry, // Pool name should always be "null", as setting this is incompat with some SaaS Redis offerings new JedisPool(objectPoolConfig, host, port, properties.timeoutMs, password, database, null, isSSL), name); }
From source file:com.basho.riak.client.raw.http.HTTPClusterClient.java
/** * Make an {@link HttpRoute} for the given URL * //from ww w .j a v a 2 s . co m * @param url * @return a {@link HttpRoute} for the given URL */ private HttpRoute makeRoute(String url) throws IOException { try { URI uri = new URI(url); HttpHost host = new HttpHost(uri.getHost(), uri.getPort()); return new HttpRoute(host); } catch (URISyntaxException e) { throw new IOException(e.toString()); } }
From source file:com.splunk.shuttl.archiver.copy.CallCopyBucketEndpointTest.java
public void _givenBucket_callsCopyBucketEndpointWithClientAndConfigurationWithSuccess() throws IOException { String host = "host"; when(shuttlMBean.getHttpHost()).thenReturn(host); int port = 1234; when(shuttlMBean.getHttpPort()).thenReturn(port); LocalBucket bucket = TUtilsBucket.createBucket(); copyBucketEndpoint.call(bucket);/*from w w w.ja va 2 s . c o m*/ HttpPost capturedRequest = getHttpClientsExecutedRequest(); URI capturedUri = capturedRequest.getURI(); assertEquals(host, capturedUri.getHost()); assertEquals(capturedUri.getPort(), port); }
From source file:net.netheos.pcsapi.oauth.PasswordSessionManager.java
@Override public CResponse execute(HttpUriRequest request) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("{}: {}", request.getMethod(), PcsUtils.shortenUrl(request.getURI())); }//from w w w . j ava 2 s . c o m try { URI uri = request.getURI(); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpContext context = getHttpContext(host); HttpResponse httpResponse = httpClient.execute(host, request, context); return new CResponse(request, httpResponse); } catch (IOException ex) { // a low level error should be retried : throw new CRetriableException(ex); } }
From source file:de.betterform.connector.xmlrpc.XMLRPCSubmissionHandler.java
/** * Parses the URI into three elements./* w w w. j a va2 s .c o m*/ * The xmlrpc URL, the function and the params * * @return a Vector */ private Vector parseURI(URI uri) { String host = uri.getHost(); int port = uri.getPort(); String path = uri.getPath(); String query = uri.getQuery(); /* Split the path up into basePath and function */ int finalSlash = path.lastIndexOf('/'); String basePath = ""; if (finalSlash > 0) { basePath = path.substring(1, finalSlash); } String function = path.substring(finalSlash + 1, path.length()); String rpcURL = "http://" + host + ":" + port + "/" + basePath; log.debug("New URL = " + rpcURL); log.debug("Function = " + function); Hashtable paramHash = new Hashtable(); if (query != null) { String[] params = query.split("&"); for (int i = 0; i < params.length; i++) { log.debug("params[" + i + "] = " + params[i]); String[] keyval = params[i].split("="); log.debug("\t" + keyval[0] + " -> " + keyval[1]); paramHash.put(keyval[0], keyval[1]); } } Vector ret = new Vector(); ret.add(rpcURL); ret.add(function); ret.add(paramHash); return ret; }
From source file:com.github.frankfarrell.snowball.Application.java
@Bean public RedissonClient redisson() throws URISyntaxException { /*//from w w w . ja va 2 s. c o m Three Possibilities here Redis Running on Local,etc Redis Running Embedded Redis Running Heroku */ Config config = new Config(); //Unfortunately this is the only way to get it to work if (redisHeroku) { URI redisURI = new URI(System.getenv("REDIS_URL")); config.useSingleServer().setAddress(redisURI.getHost() + ":" + redisURI.getPort()) .setPassword(redisURI.getAuthority().split("[:@]")[1]); //Strip the username from password } else { config.useSingleServer().setAddress(redisAddress + ":" + redisPort); } return Redisson.create(config); }
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 w w. j a v a 2s . c o 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.subgraph.vega.internal.model.web.WebModel.java
private HttpHost uriToHost(URI uri) { return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:com.cognifide.qa.bb.provider.http.HttpClientProvider.java
private AuthScope getAuthScope(String urlString) { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try {//from w w w . ja v a2 s . c o m URI uri = new URI(urlString); host = StringUtils.defaultString(uri.getHost(), AuthScope.ANY_HOST); port = uri.getPort(); } catch (URISyntaxException e) { LOG.error("Could not parse '{}' as a valid URI", urlString, e); } return new AuthScope(host, port); }
From source file:org.n52.ses.util.http.SESHttpClient.java
public SESHttpResponse sendPost(URL destination, String content, ContentType contentType) throws Exception { checkSetup();/*ww w . ja va 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; }