Example usage for com.google.common.net InetAddresses forString

List of usage examples for com.google.common.net InetAddresses forString

Introduction

In this page you can find the example usage for com.google.common.net InetAddresses forString.

Prototype

public static InetAddress forString(String ipString) 

Source Link

Document

Returns the InetAddress having the given string representation.

Usage

From source file:org.sonar.process.NetworkUtilsImpl.java

@Override
public InetAddress toInetAddress(String hostOrAddress) throws UnknownHostException {
    if (InetAddresses.isInetAddress(hostOrAddress)) {
        return InetAddresses.forString(hostOrAddress);
    }//from w  ww  .  j  ava  2 s . c o m
    return InetAddress.getByName(hostOrAddress);
}

From source file:org.apache.airavata.common.utils.AwsMetadata.java

public InetAddress getPublicIpAddress() {
    if (publicIp == null) {
        String ip = getMetadataAt(PUBLIC_IPV4_SUFFIX);
        if (ip != null) {
            publicIp = InetAddresses.forString(ip);
        }/*from  w w  w .  j  a v  a  2s  .c  o  m*/
    }
    return publicIp;
}

From source file:io.airlift.node.NodeConfig.java

@Config("node.bind-ip")
public NodeConfig setNodeBindIp(String nodeBindIp) {
    if (nodeBindIp != null) {
        this.nodeBindIp = InetAddresses.forString(nodeBindIp);
    }/*from  w w  w.  ja va  2s.c  om*/
    return this;
}

From source file:org.opendaylight.controller.config.yang.bmp.impl.BmpMonitorImplModule.java

private Optional<KeyMapping> constructKeys() {
    final KeyMapping ret = KeyMapping.getKeyMapping();
    if (getMonitoredRouter() != null) {
        for (final MonitoredRouter mr : getMonitoredRouter()) {
            if (mr.getAddress() == null) {
                LOG.warn("Monitored router {} does not have an address skipping it", mr);
                continue;
            }/*from   www. ja  v  a  2s .  c om*/
            final Rfc2385Key rfc2385KeyPassword = mr.getPassword();
            if (rfc2385KeyPassword != null && !rfc2385KeyPassword.getValue().isEmpty()) {
                final String s = getAddressString(mr.getAddress());
                ret.put(InetAddresses.forString(s),
                        rfc2385KeyPassword.getValue().getBytes(StandardCharsets.US_ASCII));
            }
        }
    }

    return ret.isEmpty() ? Optional.<KeyMapping>absent() : Optional.<KeyMapping>of(ret);
}

From source file:org.onlab.packet.Ip4Address.java

/**
 * Converts an IPv4 string literal (e.g., "10.2.3.4") into an IP address.
 *
 * @param value an IPv4 address value in string form
 * @return an IPv4 address//  w  w  w.j a  va 2s. c om
 * @throws IllegalArgumentException if the argument is invalid
 */
public static Ip4Address valueOf(String value) {
    InetAddress inetAddress = null;
    try {
        inetAddress = InetAddresses.forString(value);
    } catch (IllegalArgumentException e) {
        final String msg = "Invalid IP address string: " + value;
        throw new IllegalArgumentException(msg);
    }
    return valueOf(inetAddress);
}

From source file:org.opendaylight.atrium.util.AtriumIp4Address.java

/**
 * Converts an IPv4 string literal (e.g., "10.2.3.4") into an IP address.
 *
 * @param value an IPv4 address value in string form
 * @return an IPv4 address/*from   w  w w  .j av  a  2s .  co  m*/
 * @throws IllegalArgumentException if the argument is invalid
 */
public static AtriumIp4Address valueOf(String value) {
    InetAddress inetAddress = null;
    try {
        inetAddress = InetAddresses.forString(value);
    } catch (IllegalArgumentException e) {
        final String msg = "Invalid IP address string: " + value;
        throw new IllegalArgumentException(msg);
    }
    return valueOf(inetAddress);
}

From source file:org.openhab.binding.km200.internal.KM200Binding.java

/**
 * {@inheritDoc}/*from   w w  w  .  jav  a2  s .co  m*/
 */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {

    if (config == null) {
        return;
    } else {
        if (config.isEmpty()) {
            return;
        }
        logger.info("Update KM200 Binding configuration, it takes a minute....");
        String ip = Objects.toString(config.get("ip4_address"), null);
        if (StringUtils.isNotBlank(ip)) {
            try {
                InetAddresses.forString(ip);
            } catch (IllegalArgumentException e) {
                logger.error("IP4_address in openhab.cfg is not valid!");
                throw new ConfigurationException("ip4_address", "ip4_address in openhab.cfg is not valid!");
            }
            device.setIP4Address(ip);
        } else {
            logger.error("No ip4_address in openhab.cfg set!");
            throw new ConfigurationException("ip4_address", "No ip4_address in openhab.cfg set!");
        }
        /* There a two possibilities of configuratiom */
        /* 1. With a private key */
        String PrivKey = Objects.toString(config.get("PrivKey"), null);
        if (StringUtils.isNotBlank(PrivKey)) {
            device.setCryptKeyPriv(PrivKey);

        } else { /* 2. With the MD5Salt, the device and user private password */
            String MD5Salt = Objects.toString(config.get("MD5Salt"), null);
            if (StringUtils.isNotBlank(MD5Salt)) {
                device.setMD5Salt(MD5Salt);
            } else {
                logger.error("No MD5Salt in openhab.cfg set!");
                throw new ConfigurationException("MD5Salt", "No MD5Salt in openhab.cfg set!");
            }

            String gpassword = Objects.toString(config.get("GatewayPassword"), null);
            if (StringUtils.isNotBlank(gpassword)) {
                device.setGatewayPassword(gpassword);
            } else {
                logger.error("No GatewayPassword in openhab.cfg set!");
                throw new ConfigurationException("GatewayPassword", "No GatewayPassword in openhab.cfg set!");
            }

            String ppassword = Objects.toString(config.get("PrivatePassword"), null);
            if (StringUtils.isNotBlank(ppassword)) {
                device.setPrivatePassword(ppassword);
            } else {
                logger.error("No PrivatePassword in openhab.cfg set!");
                throw new ConfigurationException("PrivatePassword", "No PrivatePassword in openhab.cfg set!");
            }
        }
        logger.info("Starting communication test..");
        /* Get HTTP Data from device */
        byte[] recData = comm.getDataFromService("/gateway/DateTime");
        if (recData == null) {
            throw new RuntimeException("Communication is not possible!");
        }
        if (recData.length == 0) {
            throw new RuntimeException("No reply from KM200!");
        }
        logger.info("Received data..");
        /* Derypt the message */
        String decodedData = comm.decodeMessage(recData);
        if (decodedData == null) {
            throw new RuntimeException("Decoding of the KM200 message is not possible!");
        }

        if (decodedData == "SERVICE NOT AVAILABLE") {
            logger.error("/gateway/DateTime: SERVICE NOT AVAILABLE");
        } else {
            logger.info("Test of the communication to the gateway was successful..");
        }
        logger.info("Init services..");
        /* communication is working */
        /* Checking of the devicespecific services and creating of a service list */
        for (KM200ServiceTypes service : KM200ServiceTypes.values()) {
            try {
                logger.debug(service.getDescription());
                comm.initObjects(service.getDescription());
            } catch (Exception e) {
                logger.error("Couldn't init service: {} error: {}", service, e.getMessage());
            }
        }
        /* Now init the virtual services */
        logger.debug("init Virtual Objects");
        try {
            comm.initVirtualObjects();
        } catch (Exception e) {
            logger.error("Couldn't init virtual services: {}", e.getMessage());
        }
        /* Output all availible services in the log file */
        /* Now init the virtual services */
        logger.debug("list All Services");
        device.listAllServices();
        logger.info("... Update of the KM200 Binding configuration completed");

        device.setInited(true);
        setProperlyConfigured(true);
    }

}

From source file:io.rhiot.cloudplatform.adapter.leshan.IoTConnectorClientRegistry.java

private static Client deviceToClient(Device device) {
    LinkObject[] linkObjects = device.getObjectLinks().stream()
            .map(link -> new LinkObject(link.getUrl(), link.getAttributes())).collect(Collectors.toList())
            .toArray(new LinkObject[device.getObjectLinks().size()]);

    String bindingModeValue = (String) device.getProperties().get("bindingMode");
    BindingMode bindingMode = bindingModeValue == null ? null : BindingMode.valueOf(bindingModeValue);

    InetAddress address = InetAddresses.forString(device.getAddress());

    String lwM2mVersion = (String) device.getProperties().get("lwM2mVersion");

    String smsNumber = (String) device.getProperties().get("smsNumber");

    return new Client(device.getRegistrationId(), device.getDeviceId(), address, device.getPort(), lwM2mVersion,
            device.getLifeTimeInSec(), smsNumber, bindingMode, linkObjects,
            device.getRegistrationEndpointAddress(), device.getRegistrationDate(), device.getLastUpdate());
}

From source file:org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModule.java

private Optional<KeyMapping> contructKeys() {
    KeyMapping ret = null;//from  www  . j  a v  a  2  s  .  c  o  m
    final List<Client> clients = getClient();

    if (clients != null && !clients.isEmpty()) {
        ret = KeyMapping.getKeyMapping();
        for (final Client c : clients) {
            if (c.getAddress() == null) {
                LOG.warn("Client {} does not have an address skipping it", c);
                continue;
            }
            final Rfc2385Key rfc2385KeyPassword = c.getPassword();
            if (rfc2385KeyPassword != null && !rfc2385KeyPassword.getValue().isEmpty()) {
                final String s = getAddressString(c.getAddress());
                ret.put(InetAddresses.forString(s),
                        rfc2385KeyPassword.getValue().getBytes(StandardCharsets.US_ASCII));
            }
        }
    }
    return Optional.fromNullable(ret);
}

From source file:org.apache.airavata.common.utils.AwsMetadata.java

public InetAddress getInternalIpAddress() {
    if (privateIp == null) {
        String ip = getMetadataAt(PRIVATE_IPV4_SUFFIX);
        if (ip != null) {
            privateIp = InetAddresses.forString(ip);
        }/*from   w w  w .j  a  va 2s.c  o  m*/
    }
    return privateIp;
}