congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
URL.getDefaultPort
Code IndexAdd Tabnine to your IDE (free)

How to use
getDefaultPort
method
in
java.net.URL

Best Java code snippets using java.net.URL.getDefaultPort (Showing top 20 results out of 1,278)

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: spring-projects/spring-security

  /**
   * Gets the port from the casServiceURL ensuring to return the proper value if the
   * default port is being used.
   * @param casServiceUrl the casServerUrl to be used (i.e.
   * "https://example.com/context/login/cas")
   * @return the port that is configured for the casServerUrl
   */
  private static int getServicePort(URL casServiceUrl) {
    int port = casServiceUrl.getPort();
    if (port == -1) {
      port = casServiceUrl.getDefaultPort();
    }
    return port;
  }
}
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: 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: yasserg/crawler4j

/**
 * This constructor should only be used by extending classes
 *
 * @param authenticationType Pick the one which matches your authentication
 * @param httpMethod Choose POST / GET
 * @param loginUrl Full URL of the login page
 * @param username Username for Authentication
 * @param password Password for Authentication
 *
 * @throws MalformedURLException Make sure your URL is valid
 */
protected AuthInfo(AuthenticationType authenticationType, MethodType httpMethod,
          String loginUrl, String username, String password)
    throws MalformedURLException {
  this.authenticationType = authenticationType;
  this.httpMethod = httpMethod;
  URL url = new URL(loginUrl);
  this.protocol = url.getProtocol();
  this.host = url.getHost();
  this.port =
      url.getPort() == -1 ? url.getDefaultPort() : url.getPort();
  this.loginTarget = url.getFile();
  this.username = username;
  this.password = password;
}
origin: spring-projects/spring-security-oauth

/**
 * Normalize the URL for use in the signature. The OAuth spec says the URL protocol and host are to be lower-case,
 * and the query and fragments are to be stripped.
 *
 * @param url The URL.
 * @return The URL normalized for use in the signature.
 */
protected String normalizeUrl(String url) {
 try {
  URL requestURL = new URL(url);
  StringBuilder normalized = new StringBuilder(requestURL.getProtocol().toLowerCase()).append("://").append(requestURL.getHost().toLowerCase());
  if ((requestURL.getPort() >= 0) && (requestURL.getPort() != requestURL.getDefaultPort())) {
   normalized.append(":").append(requestURL.getPort());
  }
  normalized.append(requestURL.getPath());
  return normalized.toString();
 }
 catch (MalformedURLException e) {
  throw new IllegalStateException("Illegal URL for calculating the OAuth signature.", 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: jersey/jersey

/**
 * Constructs the request URI, per section 9.1.2 of the OAuth 1.0
 * specification.
 *
 * @param request the incoming request to construct the URI from.
 * @return the constructed URI.
 */
private URI constructRequestURL(final OAuth1Request request) throws OAuth1SignatureException {
  try {
    final URL url = request.getRequestURL();
    if (url == null) {
      throw new OAuth1SignatureException();
    }
    final StringBuilder builder = new StringBuilder(url.getProtocol()).append("://").append(url.getHost().toLowerCase());
    final int port = url.getPort();
    if (port > 0 && port != url.getDefaultPort()) {
      builder.append(':').append(port);
    }
    builder.append(url.getPath());
    return new URI(builder.toString());
  } catch (final URISyntaxException mue) {
    throw new OAuth1SignatureException(mue);
  }
}
origin: spring-projects/spring-security-oauth

if ((requestURL.getPort() >= 0) && (requestURL.getPort() != requestURL.getDefaultPort())) {
 url.append(":").append(requestURL.getPort());
origin: knowm/XChange

port = url.getDefaultPort();
origin: yasserg/crawler4j

if (port == canonicalURL.getDefaultPort()) {
  port = -1;
origin: spring-projects/spring-framework

private void ports(UriComponents uriComponents, MockHttpServletRequest request) {
  int serverPort = uriComponents.getPort();
  request.setServerPort(serverPort);
  if (serverPort == -1) {
    int portConnection = this.webRequest.getUrl().getDefaultPort();
    request.setLocalPort(serverPort);
    request.setRemotePort(portConnection);
  }
  else {
    request.setRemotePort(serverPort);
  }
}
origin: apache/incubator-druid

final int port = url.getPort() == -1 ? url.getDefaultPort() : url.getPort();
final ChannelFuture retVal;
final ChannelFuture connectFuture = bootstrap.connect(new InetSocketAddress(host, port));
origin: apache/metron

 @Override
 public Object apply(List<Object> objects) {
  URL url =  toUrl(objects.get(0));
  if(url == null) {
   return null;
  }
  int port = url.getPort();
  return port >= 0?port:url.getDefaultPort();
 }
}
origin: wiztools/rest-client

final int urlPort = url.getPort()==-1?url.getDefaultPort():url.getPort();
final String urlProtocol = url.getProtocol();
final String urlStr = url.toString();
origin: googleapis/google-cloud-java

String host = url.getHost();
int port = url.getPort();
port = port > 0 ? port : url.toURL().getDefaultPort();
String path = "/upload" + url.getRawPath();
url = new GenericUrl(scheme + "://" + host + ":" + port + path);
origin: org.apache.thrift/libthrift

public THttpClient(String url, HttpClient client) throws TTransportException {
 try {
  url_ = new URL(url);
  this.client = client;
  this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort() : url_.getPort(), url_.getProtocol());
 } catch (IOException iox) {
  throw new TTransportException(iox);
 }
}
origin: SeanDragon/protools

  public static String getHostAndPort(String urlString) throws HttpException {
    try {
      URL url = new URL(urlString);
      String host = url.getHost();
      int port = url.getPort();
      if (port == -1) {
        port = url.getDefaultPort();
      }
      return host + port;
    } catch (MalformedURLException e) {
      throw new HttpException("URL is ERROR", e);
    }
  }
}
origin: alexa/alexa-skills-kit-sdk-for-java

  && (urlPort != url.getDefaultPort())) {
throw new CertificateException(String.format(
    "SigningCertificateChainUrl [%s] contains an invalid port [%d]",
origin: briandilley/jsonrpc4j

int port = serviceUrl.getPort() != -1 ? serviceUrl.getPort() : serviceUrl.getDefaultPort();
HttpRequest request = new BasicHttpEntityEnclosingRequest("POST", path);
java.netURLgetDefaultPort

Javadoc

Returns the default port number of the protocol used by this URL. If no default port is defined by the protocol or the URLStreamHandler, -1 will be returned.

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
  • getPort
    Gets the port number of this URL.
  • getQuery
    Gets the query part of this URL.
  • getPort,
  • getQuery,
  • equals,
  • getRef,
  • getUserInfo,
  • getAuthority,
  • hashCode,
  • getContent,
  • setURLStreamHandlerFactory

Popular in Java

  • Creating JSON documents from java classes using gson
  • getResourceAsStream (ClassLoader)
  • setRequestProperty (URLConnection)
  • onRequestPermissionsResult (Fragment)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Runner (org.openjdk.jmh.runner)
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Best plugins for Eclipse
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