/** * Derive the host and port from virtual address if virtual address is indeed contains the actual * host and port of the server. This is the final resort to compute the final URI in {@link * #computeFinalUriWithLoadBalancer(ClientRequest)} if there is no load balancer available and the * request URI is incomplete. Sub classes can override this method to be more accurate or throws * ClientException if it does not want to support virtual address to be the same as physical * server address. * * <p>The virtual address is used by certain load balancers to filter the servers of the same * function to form the server pool. */ protected Pair<String, Integer> deriveHostAndPortFromVipAddress(String vipAddress) throws URISyntaxException, ClientException { Pair<String, Integer> hostAndPort = new Pair<String, Integer>(null, -1); URI uri = new URI(vipAddress); String scheme = uri.getScheme(); if (scheme == null) { uri = new URI("http://" + vipAddress); } String host = uri.getHost(); if (host == null) { throw new ClientException("Unable to derive host/port from vip address " + vipAddress); } int port = uri.getPort(); if (port < 0) { port = getDefaultPort(); } if (port < 0) { throw new ClientException("Unable to derive host/port from vip address " + vipAddress); } hostAndPort.setFirst(host); hostAndPort.setSecond(port); return hostAndPort; }