Tabnine Logo
URL.getHost
Code IndexAdd Tabnine to your IDE (free)

How to use
getHost
method
in
java.net.URL

Best Java code snippets using java.net.URL.getHost (Showing top 20 results out of 15,120)

Refine searchRefine arrow

  • URL.<init>
  • URL.getPort
  • URL.getProtocol
  • URL.getPath
  • URL.getQuery
  • URL.getFile
origin: Netflix/eureka

public String getBatcherName() {
  String batcherName;
  try {
    batcherName = new URL(serviceUrl).getHost();
  } catch (MalformedURLException e1) {
    batcherName = serviceUrl;
  }
  return "target_" + batcherName;
}
origin: Netflix/eureka

public DefaultEndpoint(String serviceUrl) {
  this.serviceUrl = serviceUrl;
  try {
    URL url = new URL(serviceUrl);
    this.networkAddress = url.getHost();
    this.port = url.getPort();
    this.isSecure = "https".equals(url.getProtocol());
    this.relativeUri = url.getPath();
  } catch (Exception e) {
    throw new IllegalArgumentException("Malformed serviceUrl: " + serviceUrl);
  }
}
origin: spring-projects/spring-framework

@Override
public boolean matches(WebRequest request) {
  URL url = request.getUrl();
  String host = url.getHost();
  if (this.hosts.contains(host)) {
    return true;
  }
  int port = url.getPort();
  if (port == -1) {
    port = url.getDefaultPort();
  }
  String hostAndPort = host + ":" + port;
  return this.hosts.contains(hostAndPort);
}
origin: apache/flink

/**
 * Method to validate if the given String represents a hostname:port.
 *
 * <p>Works also for ipv6.
 *
 * <p>See: http://stackoverflow.com/questions/2345063/java-common-way-to-validate-and-convert-hostport-to-inetsocketaddress
 *
 * @return URL object for accessing host and Port
 */
public static URL getCorrectHostnamePort(String hostPort) {
  try {
    URL u = new URL("http://" + hostPort);
    if (u.getHost() == null) {
      throw new IllegalArgumentException("The given host:port ('" + hostPort + "') doesn't contain a valid host");
    }
    if (u.getPort() == -1) {
      throw new IllegalArgumentException("The given host:port ('" + hostPort + "') doesn't contain a valid port");
    }
    return u;
  } catch (MalformedURLException e) {
    throw new IllegalArgumentException("The given host:port ('" + hostPort + "') is invalid", e);
  }
}
origin: wildfly/wildfly

public PreSignedUrlParser(String preSignedUrl) {
  try {
    URL url = new URL(preSignedUrl);
    this.bucket = parseBucketFromHost(url.getHost());
    String path = url.getPath();
    String[] pathParts = path.split("/");
    
    if (pathParts.length < 2) {
      throw new IllegalArgumentException("pre-signed url " + preSignedUrl + " must point to a file within a bucket");
    }
    if (pathParts.length > 3) {
      throw new IllegalArgumentException("pre-signed url " + preSignedUrl + " may only have only subdirectory under a bucket");
    }
    if (pathParts.length > 2) {
      this.prefix = pathParts[1];
    }
  } catch (MalformedURLException ex) {
    throw new IllegalArgumentException("pre-signed url " + preSignedUrl + " is not a valid url");
  }
}
origin: jenkinsci/jenkins

/**
 * If the first URL we try to access with a HTTP proxy is HTTPS then the authentication cache will not have been
 * pre-populated, so we try to access at least one HTTP URL before the very first HTTPS url.
 * @param proxy
 * @param url the actual URL being opened.
 */
private void jenkins48775workaround(Proxy proxy, URL url) {
  if ("https".equals(url.getProtocol()) && !authCacheSeeded && proxy != Proxy.NO_PROXY) {
    HttpURLConnection preAuth = null;
    try {
      // We do not care if there is anything at this URL, all we care is that it is using the proxy
      preAuth = (HttpURLConnection) new URL("http", url.getHost(), -1, "/").openConnection(proxy);
      preAuth.setRequestMethod("HEAD");
      preAuth.connect();
    } catch (IOException e) {
      // ignore, this is just a probe we don't care at all
    } finally {
      if (preAuth != null) {
        preAuth.disconnect();
      }
    }
    authCacheSeeded = true;
  } else if ("https".equals(url.getProtocol())){
    // if we access any http url using a proxy then the auth cache will have been seeded
    authCacheSeeded = authCacheSeeded || proxy != Proxy.NO_PROXY;
  }
}
origin: apache/incubator-druid

 private String getPoolKey(URL url)
 {
  return StringUtils.format(
    "%s://%s:%s", url.getProtocol(), url.getHost(), url.getPort() == -1 ? url.getDefaultPort() : url.getPort()
  );
 }
}
origin: prestodb/presto

/**
 * Helper methods used for constructing an optimal stream for
 * parsers to use, when input is to be read from an URL.
 * This helps when reading file content via URL.
 */
protected InputStream _optimizedStreamFromURL(URL url) throws IOException {
  if ("file".equals(url.getProtocol())) {
    /* Can not do this if the path refers
     * to a network drive on windows. This fixes the problem;
     * might not be needed on all platforms (NFS?), but should not
     * matter a lot: performance penalty of extra wrapping is more
     * relevant when accessing local file system.
     */
    String host = url.getHost();
    if (host == null || host.length() == 0) {
      // [core#48]: Let's try to avoid probs with URL encoded stuff
      String path = url.getPath();
      if (path.indexOf('%') < 0) {
        return new FileInputStream(url.getPath());
      }
      // otherwise, let's fall through and let URL decoder do its magic
    }
  }
  return url.openStream();
}
origin: robovm/robovm

PermissionCollection pc = super.getPermissions(codesource);
URL u = codesource.getLocation();
if (u.getProtocol().equals("jar")) {
  try {
if (u.getProtocol().equals("file")) {
  String path = u.getFile();
  String host = u.getHost();
  if (host != null && host.length() > 0) {
    path = "//" + host + path;
  String host = u.getHost();
  if (host.length() == 0) {
    host = "localhost";
origin: RipMeApp/ripme

public boolean canRip(URL url) {
  return url.getHost().endsWith(DOMAIN) && url.getPath().startsWith("/album");
}
origin: stackoverflow.com

 String urlStr = "http://abc.dev.domain.com/0007AC/ads/800x480 15sec h.264.mp4";
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();
origin: gocd/gocd

  public static String getClientIp(String serviceUrl) {
    try {
      URL url = new URL(serviceUrl);
      int port = url.getPort();
      if (port == -1) {
        port = url.getDefaultPort();
      }
      try (Socket socket = new Socket(url.getHost(), port)) {
        return socket.getLocalAddress().getHostAddress();
      }
    } catch (Exception e) {
      return SystemUtil.getFirstLocalNonLoopbackIpAddress();
    }
  }
}
origin: spring-projects/spring-security

/**
 * Creates a new instance
 * @param request the current {@link HttpServletRequest} to obtain the
 * {@link #getServiceUrl()} from.
 * @param artifactPattern the {@link Pattern} that will be used to clean up the query
 * string from containing the artifact name and value. This can be created using
 * {@link #createArtifactPattern(String)}.
 */
DefaultServiceAuthenticationDetails(String casService, HttpServletRequest request,
    Pattern artifactPattern) throws MalformedURLException {
  super(request);
  URL casServiceUrl = new URL(casService);
  int port = getServicePort(casServiceUrl);
  final String query = getQueryString(request, artifactPattern);
  this.serviceUrl = UrlUtils.buildFullRequestUrl(casServiceUrl.getProtocol(),
      casServiceUrl.getHost(), port, request.getRequestURI(), query);
}
origin: Netflix/eureka

private String extractDomain(String url) throws MalformedURLException {
  return new URL(url).getHost() + ".";
}
origin: apache/incubator-druid

private String getHost(URL url)
{
 int port = url.getPort();
 if (port == -1) {
  final String protocol = url.getProtocol();
  if ("http".equalsIgnoreCase(protocol)) {
   port = 80;
  } else if ("https".equalsIgnoreCase(protocol)) {
   port = 443;
  } else {
   throw new IAE("Cannot figure out default port for protocol[%s], please set Host header.", protocol);
  }
 }
 return StringUtils.format("%s:%s", url.getHost(), port);
}
origin: redisson/redisson

/**
 * Helper methods used for constructing an optimal stream for
 * parsers to use, when input is to be read from an URL.
 * This helps when reading file content via URL.
 */
protected InputStream _optimizedStreamFromURL(URL url) throws IOException {
  if ("file".equals(url.getProtocol())) {
    /* Can not do this if the path refers
     * to a network drive on windows. This fixes the problem;
     * might not be needed on all platforms (NFS?), but should not
     * matter a lot: performance penalty of extra wrapping is more
     * relevant when accessing local file system.
     */
    String host = url.getHost();
    if (host == null || host.length() == 0) {
      // [core#48]: Let's try to avoid probs with URL encoded stuff
      String path = url.getPath();
      if (path.indexOf('%') < 0) {
        return new FileInputStream(url.getPath());
      }
      // otherwise, let's fall through and let URL decoder do its magic
    }
  }
  return url.openStream();
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public void connect() throws IOException {
  URL url = getURL();
  // Gets class loader UUID.
  IgniteUuid ldrId = IgniteUuid.fromString(url.getHost());
  // Gets resource name.
  String name = url.getPath();
  GridDeployment dep = mgr.getDeployment(ldrId);
  if (dep != null) {
    in = dep.classLoader().getParent().getResourceAsStream(name);
    // If resource exists
    connected = true;
  }
}
origin: redisson/redisson

/**
 * Constructs an object importer.
 *
 * <p>Remote objects are imported from the web server that the given
 * applet has been loaded from.
 *
 * @param applet    the applet loaded from the <code>Webserver</code>.
 */
public ObjectImporter(Applet applet) {
  URL codebase = applet.getCodeBase();
  orgServername = servername = codebase.getHost();
  orgPort = port = codebase.getPort();
}
origin: dropwizard/dropwizard

/**
 * Appends a trailing '/' to a {@link URL} object. Does not append a slash if one is already present.
 *
 * @param originalURL The URL to append a slash to
 * @return a new URL object that ends in a slash
 */
public static URL appendTrailingSlash(URL originalURL) {
  try {
    return originalURL.getPath().endsWith("/") ? originalURL :
        new URL(originalURL.getProtocol(),
            originalURL.getHost(),
            originalURL.getPort(),
            originalURL.getFile() + '/');
  } catch (MalformedURLException ignored) { // shouldn't happen
    throw new IllegalArgumentException("Invalid resource URL: " + originalURL);
  }
}
origin: googleapis/google-cloud-java

 public String getEndpoint() {
  URL url;
  try {
   url = new URL(getHost());
  } catch (MalformedURLException e) {
   throw new IllegalArgumentException("Invalid host: " + getHost(), e);
  }
  return String.format(
    "%s:%s", url.getHost(), url.getPort() < 0 ? url.getDefaultPort() : url.getPort());
 }
}
java.netURLgetHost

Javadoc

Returns the host name or IP address of this URL.

Popular methods of URL

  • <init>
  • openStream
    Opens a connection to this URL and returns anInputStream for reading from that connection. This meth
  • openConnection
    Returns a new connection to the resource referred to by this URL.
  • toString
    Constructs a string representation of this URL. The string is created by calling the toExternalForm
  • getPath
    Gets the path part of this URL.
  • toURI
    Returns a java.net.URI equivalent to this URL. This method functions in the same way as new URI (thi
  • getProtocol
    Gets the protocol name of this URL.
  • getFile
    Gets the file name of this URL. The returned file portion will be the same as getPath(), plus the c
  • toExternalForm
    Constructs a string representation of this URL. The string is created by calling the toExternalForm
  • getPort
    Gets the port number of this URL.
  • getQuery
    Gets the query part of this URL.
  • equals
    Compares this URL for equality with another object. If the given object is not a URL then this metho
  • getQuery,
  • equals,
  • getRef,
  • getUserInfo,
  • getAuthority,
  • hashCode,
  • getDefaultPort,
  • getContent,
  • setURLStreamHandlerFactory

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • setScale (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now