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);
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations