List of usage examples for java.net URI getHost
public String getHost()
From source file:com.subgraph.vega.impl.scanner.urls.UriParser.java
public IPathState processUri(URI uri) { final HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); final IWebHost webHost = getWebHost(host); IWebPath path = webHost.getRootPath(); final boolean hasTrailingSlash = uri.getPath().endsWith("/"); String[] parts = uri.getPath().split("/"); IWebPath childPath;/* w w w .j a v a 2s . c o m*/ for (int i = 1; i < parts.length; i++) { synchronized (path) { childPath = path.getChildPath(parts[i]); if (childPath == null) { childPath = path.addChildPath(parts[i]); } processPath(childPath, uri, (i == (parts.length - 1)), hasTrailingSlash); } path = childPath; } return pathStateManager.getStateForPath(path); }
From source file:com.abiquo.model.enumerator.RemoteServiceType.java
public String fixUri(final URI uri) { String protocol = uri.getScheme(); String domainName = uri.getHost(); Integer port = uri.getPort(); String path = uri.getPath();// w w w . j a va 2 s . c o m String domainHost = domainName + (port != null ? ":" + port : ""); String fullURL = StringUtils.join(new String[] { fixProtocol(protocol), domainHost }); if (!StringUtils.isEmpty(path)) { fullURL = UriHelper.appendPathToBaseUri(fullURL, path); } return fullURL; }
From source file:io.galeb.health.services.HealthCheckerService.java
private String buildHcHostFromTarget(Target target) { String hcHost;//from w w w .j a v a 2 s .com URI targetURI = URI.create(target.getName()); hcHost = targetURI.getHost() + ":" + targetURI.getPort(); return hcHost; }
From source file:org.restheart.test.performance.AbstractPT.java
public void prepare() { Authenticator.setDefault(new Authenticator() { @Override/*from ww w . j ava2s . c om*/ 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.onehippo.cms7.brokenlinks.TestHttpClient.java
@Override public HttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException { final URI uri = request.getURI(); final BasicStatusLine statusline; if (!"good".equals(uri.getHost())) { statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "Not Found"); } else {/*from w ww . j av a 2 s . c o m*/ statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); } return new BasicHttpResponse(statusline); }
From source file:org.jclouds.http.apachehc.ApacheHCHttpCommandExecutorService.java
private org.apache.http.HttpResponse executeRequest(HttpUriRequest nativeRequest) throws IOException, ClientProtocolException { URI endpoint = URI.create(nativeRequest.getRequestLine().getUri()); HttpHost host = new HttpHost(endpoint.getHost(), endpoint.getPort(), endpoint.getScheme()); org.apache.http.HttpResponse nativeResponse = client.execute(host, nativeRequest); return nativeResponse; }
From source file:com.cloud.utils.UriUtils.java
public static Pair<String, Integer> validateUrl(String format, String url) throws IllegalArgumentException { try {/*from www .j a va 2 s . c o m*/ URI uri = new URI(url); if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http") && !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) { throw new IllegalArgumentException("Unsupported scheme for url: " + url); } int port = uri.getPort(); if (!(port == 80 || port == 8080 || port == 443 || port == -1)) { throw new IllegalArgumentException("Only ports 80, 8080 and 443 are allowed"); } if (port == -1 && uri.getScheme().equalsIgnoreCase("https")) { port = 443; } else if (port == -1 && uri.getScheme().equalsIgnoreCase("http")) { port = 80; } String host = uri.getHost(); try { InetAddress hostAddr = InetAddress.getByName(host); if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) { throw new IllegalArgumentException("Illegal host specified in url"); } if (hostAddr instanceof Inet6Address) { throw new IllegalArgumentException( "IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")"); } } catch (UnknownHostException uhe) { throw new IllegalArgumentException("Unable to resolve " + host); } // verify format if (format != null) { String uripath = uri.getPath(); checkFormat(format, uripath); } return new Pair<String, Integer>(host, port); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid URL: " + url); } }
From source file:org.bedework.synch.cnctrs.file.FileConnectorInstance.java
@Override public URI getUri() throws SynchException { try {//from w w w. j a v a 2 s . c om //Get yesterdays date final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS); final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE); final URI infoUri = new URI(info.getUri()); return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost()) .setPort(infoUri.getPort()).setPath(infoUri.getPath()).build(); } catch (final SynchException se) { throw se; } catch (final Throwable t) { throw new SynchException(t); } }
From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java
@Override public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) { Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials"); String id = (String) serviceData.get("name"); try {//from w ww .j av a 2s . c o m URI uri = new URI((String) credentials.get("url")); String scheme = uri.getScheme(); int port = uri.getPort(); String host = uri.getHost(); String path = uri.getPath(); String query = uri.getQuery(); String fragment = uri.getFragment(); String url = new URI(scheme, "", host, port, path, query, fragment).toString(); String[] userInfo = uri.getUserInfo().split(":"); return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url); } catch (URISyntaxException e) { return null; } }
From source file:com.alibaba.napoli.metamorphosis.cluster.Broker.java
/** * @param id/* w w w . ja va2 s. c o m*/ * @param data * , meta://host:port or meta://host:port?slaveId=xx * * */ public Broker(final int id, final String data) { this.id = id; try { final URI uri = new URI(data); this.host = uri.getHost(); this.port = uri.getPort(); this.slaveId = slaveIdByUri(uri); } catch (final URISyntaxException e) { throw new RuntimeException(e); } }