Search in sources :

Example 1 with InetAddress

use of java.net.InetAddress in project camel by apache.

the class DnsIpProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    String domain = exchange.getIn().getHeader(DnsConstants.DNS_DOMAIN, String.class);
    ObjectHelper.notEmpty(domain, "Header " + DnsConstants.DNS_DOMAIN);
    InetAddress address = InetAddress.getByName(domain);
    exchange.getIn().setBody(address);
}
Also used : InetAddress(java.net.InetAddress)

Example 2 with InetAddress

use of java.net.InetAddress in project camel by apache.

the class HostUtils method getAddresses.

/**
     * Returns a {@link Set} of {@link InetAddress} that are non-loopback or mac.
     */
public static Set<InetAddress> getAddresses() {
    Set<InetAddress> allAddresses = new LinkedHashSet<InetAddress>();
    Map<String, Set<InetAddress>> interfaceAddressMap = getNetworkInterfaceAddresses();
    for (Map.Entry<String, Set<InetAddress>> entry : interfaceAddressMap.entrySet()) {
        Set<InetAddress> addresses = entry.getValue();
        if (!addresses.isEmpty()) {
            for (InetAddress address : addresses) {
                allAddresses.add(address);
            }
        }
    }
    return allAddresses;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) InetAddress(java.net.InetAddress) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 3 with InetAddress

use of java.net.InetAddress in project camel by apache.

the class HostUtils method getNetworkInterfaceAddresses.

/**
     * Returns a {@link Map} of {@link InetAddress} per {@link NetworkInterface}.
     */
public static Map<String, Set<InetAddress>> getNetworkInterfaceAddresses() {
    //JVM returns interfaces in a non-predictable order, so to make this more predictable
    //let's have them sort by interface name (by using a TreeMap).
    Map<String, Set<InetAddress>> interfaceAddressMap = new TreeMap<String, Set<InetAddress>>();
    try {
        Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
        while (ifaces.hasMoreElements()) {
            NetworkInterface iface = ifaces.nextElement();
            //We only care about usable non-loopback interfaces.
            if (iface.isUp() && !iface.isLoopback() && !iface.isPointToPoint()) {
                String name = iface.getName();
                Enumeration<InetAddress> ifaceAdresses = iface.getInetAddresses();
                while (ifaceAdresses.hasMoreElements()) {
                    InetAddress ia = ifaceAdresses.nextElement();
                    //We want to filter out mac addresses
                    if (!ia.isLoopbackAddress() && !ia.getHostAddress().contains(":")) {
                        Set<InetAddress> addresses = interfaceAddressMap.get(name);
                        if (addresses == null) {
                            addresses = new LinkedHashSet<InetAddress>();
                        }
                        addresses.add(ia);
                        interfaceAddressMap.put(name, addresses);
                    }
                }
            }
        }
    } catch (SocketException ex) {
    //noop
    }
    return interfaceAddressMap;
}
Also used : SocketException(java.net.SocketException) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) NetworkInterface(java.net.NetworkInterface) TreeMap(java.util.TreeMap) InetAddress(java.net.InetAddress)

Example 4 with InetAddress

use of java.net.InetAddress in project camel by apache.

the class Mina2SslContextParametersUdpTest method sendUdpMessages.

protected void sendUdpMessages() throws Exception {
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            String text = "Hello Message: " + Integer.toString(i);
            byte[] data = text.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
            socket.send(packet);
        }
        Thread.sleep(2000);
    } finally {
        socket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 5 with InetAddress

use of java.net.InetAddress in project camel by apache.

the class Mina2UdpTest method sendUdpMessages.

protected void sendUdpMessages() throws Exception {
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            String text = "Hello Message: " + Integer.toString(i);
            byte[] data = text.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
            socket.send(packet);
        }
        Thread.sleep(2000);
    } finally {
        socket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Aggregations

InetAddress (java.net.InetAddress)2063 UnknownHostException (java.net.UnknownHostException)377 IOException (java.io.IOException)284 Test (org.junit.Test)272 InetSocketAddress (java.net.InetSocketAddress)240 NetworkInterface (java.net.NetworkInterface)178 ArrayList (java.util.ArrayList)158 SocketException (java.net.SocketException)148 Inet6Address (java.net.Inet6Address)97 HashMap (java.util.HashMap)95 Inet4Address (java.net.Inet4Address)88 Socket (java.net.Socket)73 LinkAddress (android.net.LinkAddress)70 DatagramPacket (java.net.DatagramPacket)67 Token (org.apache.cassandra.dht.Token)67 DatagramSocket (java.net.DatagramSocket)61 RouteInfo (android.net.RouteInfo)56 Map (java.util.Map)55 LinkProperties (android.net.LinkProperties)52 ServerSocket (java.net.ServerSocket)50