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

How to use
getPort
method
in
java.net.URL

Best Java code snippets using java.net.URL.getPort (Showing top 20 results out of 10,017)

Refine searchRefine arrow

  • URL.getHost
  • URL.getProtocol
  • URL.<init>
  • URL.getPath
  • URL.getQuery
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: 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: 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: jenkinsci/jenkins

URL jenkins_url = new URL(rootURL);
int jenkins_port = jenkins_url.getPort();
if (jenkins_port == -1) {
  jenkins_port = 80;
if (jenkins_url.getPath().length() > 0) {
  props.put("path", jenkins_url.getPath());
origin: scouter-project/scouter

ctx.apicall_name = url.getPath();
step.address = url.getHost() + ":" + url.getPort();
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: square/okhttp

@Override public Permission getPermission() throws IOException {
 URL url = getURL();
 String hostname = url.getHost();
 int hostPort = url.getPort() != -1
   ? url.getPort()
   : HttpUrl.defaultPort(url.getProtocol());
 if (usingProxy()) {
  InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address();
  hostname = proxyAddress.getHostName();
  hostPort = proxyAddress.getPort();
 }
 return new SocketPermission(hostname + ":" + hostPort, "connect, resolve");
}
origin: scouter-project/scouter

ctx.apicall_name = url.getPath();
step.address = url.getHost() + ":" + url.getPort();
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: gocd/gocd

private String getRootUrl(String string) {
  try {
    final URL url = new URL(string);
    return new URL(url.getProtocol(), url.getHost(), url.getPort(), "").toString();
  } catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}
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());
 }
}
origin: androidquery/androidquery

private HttpResponse execute(HttpUriRequest hr, DefaultHttpClient client, HttpContext context) throws ClientProtocolException, IOException{
  
  HttpResponse response = null;
  if(hr.getURI().getAuthority().contains("_")) {
    URL urlObj = hr.getURI().toURL();
    HttpHost host;
    if(urlObj.getPort() == -1) {
      host = new HttpHost(urlObj.getHost(), 80, urlObj.getProtocol());
    } else {
      host = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol());
    }
    response = client.execute(host, hr, context);
  } else {
    response = client.execute(hr, context);
  }
  
  
  return response;
}

origin: apache/flink

@Override
protected void initializeConnections() {
  URL contactUrl = NetUtils.getCorrectHostnamePort(seedBrokerAddresses[currentContactSeedBrokerIndex]);
  this.consumer = new SimpleConsumer(contactUrl.getHost(), contactUrl.getPort(), soTimeout, bufferSize, dummyClientId);
}
origin: rest-assured/rest-assured

  private CookieOrigin cookieOriginFromUri(String uri) {

    try {
      URL parsedUrl = new URL(uri);
      int port = parsedUrl.getPort() != -1 ? parsedUrl.getPort() : 80;
      return new CookieOrigin(
          parsedUrl.getHost(), port, parsedUrl.getPath(), "https".equals(parsedUrl.getProtocol()));
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException(e);
    }
  }
}
origin: log4j/log4j

URL url = new URL("http://" + host);
if (url.getHost() != null) {
  host = url.getHost();
  urlPort = url.getPort();
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: apache/flink

/**
 * Re-establish broker connection using the next available seed broker address.
 */
private void useNextAddressAsNewContactSeedBroker() {
  if (++currentContactSeedBrokerIndex == seedBrokerAddresses.length) {
    currentContactSeedBrokerIndex = 0;
  }
  URL newContactUrl = NetUtils.getCorrectHostnamePort(seedBrokerAddresses[currentContactSeedBrokerIndex]);
  this.consumer = new SimpleConsumer(newContactUrl.getHost(), newContactUrl.getPort(), soTimeout, bufferSize, dummyClientId);
}
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);
  }
}
java.netURLgetPort

Javadoc

Returns the port number of this URL or -1 if this URL has no explicit port.

If this URL has no explicit port, connections opened using this URL will use its #getDefaultPort().

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
  • getHost
    Gets the host name of this URL, if applicable. The format of the host conforms to RFC 2732, i.e. for
  • 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

  • Reading from database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getExternalFilesDir (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • JButton (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • CodeWhisperer alternatives
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