Class GrpcUtils

java.lang.Object
org.springframework.grpc.internal.GrpcUtils

public final class GrpcUtils extends Object
Provides convenience methods for various gRPC functions.

NOTE: Even though this class visibility is `public` it is intended for internal use only and not recommended for direct use.

Author:
David Syer, Chris Bono
  • Field Details

    • ANY_IP_ADDRESS

      public static final String ANY_IP_ADDRESS
      Server should listen to any IPv4 and IPv6 address.
      See Also:
    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      Default port to use.
      See Also:
  • Method Details

    • getPort

      public static int getPort(String address)
      Gets the port given an address.

      The address is expected to conform to the requirements of the input address for URI(String) with the following exceptions:

      • do not include a scheme
      • wildcard '*' host is acceptable
      Parameters:
      address - the server address as described above
      Returns:
      the port extracted from the address or DEFAULT_PORT if port was not specified or was invalid (e.g. 'localhost:xxx')
      Throws:
      IllegalArgumentException - if the address represents a unix domain socket (i.e. starts with 'unix:') or includes a scheme or URI(String) is unable to parse the address
    • getHostName

      public static @Nullable String getHostName(String address)
      Gets the hostname given an address.

      The address is expected to conform to the requirements of the input address for URI(String) with the following exceptions:

      • do not include a scheme
      • wildcard '*' host is acceptable
      Parameters:
      address - the server address as described above
      Returns:
      the hostname extracted from the address or null if no hostname could be extracted
      Throws:
      IllegalArgumentException - if the address represents a unix domain socket (i.e. starts with 'unix:') or includes a scheme or URI(String) is unable to parse the address