/** * Encodes an IP address and port to be included in URL. in particular, this method makes * sure that IPv6 addresses have the proper formatting to be included in URLs. * * @param address The address to be included in the URL. * @param port The port for the URL address. * @return The proper URL string encoded IP address and port. */ public static String ipAddressAndPortToUrlString(InetAddress address, int port) { return ipAddressToUrlString(address) + ':' + port; }
@Test public void testIPv6toURL() { try { final String addressString = "2001:01db8:00:0:00:ff00:42:8329"; final String normalizedAddress = "[2001:1db8::ff00:42:8329]"; InetAddress address = InetAddress.getByName(addressString); assertEquals(normalizedAddress, NetUtils.ipAddressToUrlString(address)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testIPv4toURL() { try { final String addressString = "192.168.0.1"; InetAddress address = InetAddress.getByName(addressString); assertEquals(addressString, NetUtils.ipAddressToUrlString(address)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testIPv4URLEncoding() { try { final String addressString = "10.244.243.12"; final int port = 23453; InetAddress address = InetAddress.getByName(addressString); InetSocketAddress socketAddress = new InetSocketAddress(address, port); assertEquals(addressString, NetUtils.ipAddressToUrlString(address)); assertEquals(addressString + ':' + port, NetUtils.ipAddressAndPortToUrlString(address, port)); assertEquals(addressString + ':' + port, NetUtils.socketAddressToUrlString(socketAddress)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testIPv6URLEncoding() { try { final String addressString = "2001:db8:10:11:12:ff00:42:8329"; final String bracketedAddressString = '[' + addressString + ']'; final int port = 23453; InetAddress address = InetAddress.getByName(addressString); InetSocketAddress socketAddress = new InetSocketAddress(address, port); assertEquals(bracketedAddressString, NetUtils.ipAddressToUrlString(address)); assertEquals(bracketedAddressString + ':' + port, NetUtils.ipAddressAndPortToUrlString(address, port)); assertEquals(bracketedAddressString + ':' + port, NetUtils.socketAddressToUrlString(socketAddress)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
/** * Encodes an IP address and port to be included in URL. in particular, this method makes * sure that IPv6 addresses have the proper formatting to be included in URLs. * * @param address The address to be included in the URL. * @param port The port for the URL address. * @return The proper URL string encoded IP address and port. */ public static String ipAddressAndPortToUrlString(InetAddress address, int port) { return ipAddressToUrlString(address) + ':' + port; }
/** * Encodes an IP address and port to be included in URL. in particular, this method makes * sure that IPv6 addresses have the proper formatting to be included in URLs. * * @param address The address to be included in the URL. * @param port The port for the URL address. * @return The proper URL string encoded IP address and port. */ public static String ipAddressAndPortToUrlString(InetAddress address, int port) { return ipAddressToUrlString(address) + ':' + port; }
public static ActorSystem startJobClientActorSystem(Configuration config) throws IOException { LOG.info("Starting JobClient actor system"); Option<Tuple2<String, Object>> remoting = new Some<>(new Tuple2<String, Object>("", 0)); // start a remote actor system to listen on an arbitrary port ActorSystem system = AkkaUtils.createActorSystem(config, remoting); Address address = system.provider().getDefaultAddress(); String hostAddress = address.host().isDefined() ? NetUtils.ipAddressToUrlString(InetAddress.getByName(address.host().get())) : "(unknown)"; int port = address.port().isDefined() ? ((Integer) address.port().get()) : -1; LOG.info("Started JobClient actor system at " + hostAddress + ':' + port); return system; }