Example usage for java.net InetAddress getCanonicalHostName

List of usage examples for java.net InetAddress getCanonicalHostName

Introduction

In this page you can find the example usage for java.net InetAddress getCanonicalHostName.

Prototype

public String getCanonicalHostName() 

Source Link

Document

Gets the fully qualified domain name for this IP address.

Usage

From source file:org.apache.geode.distributed.AbstractLauncher.java

/**
 * Asserts that the specified port is available on the specified network interface, indicated by
 * it's assigned IP address, on this local system.
 *
 * @param bindAddress an InetAddress indicating the bounded network interface to determine whether
 *        the service port is available or not.
 * @param port an integer indicating the network port to listen for client network requests.
 * @throws BindException if the network address and port are not available. Address defaults to
 *         localhost (or all network interfaces on the local system) if null.
 * @see org.apache.geode.internal.AvailablePort
 *///w  ww .j a  va  2s  .com
protected static void assertPortAvailable(final InetAddress bindAddress, final int port) throws BindException {
    if (!AvailablePort.isPortAvailable(port, AvailablePort.SOCKET, bindAddress)) {
        throw new BindException(String.format("Network is unreachable; port (%1$d) is not available on %2$s.",
                port, bindAddress != null ? bindAddress.getCanonicalHostName() : "localhost"));
    }
}

From source file:org.jasig.cas.support.spnego.util.ReverseDNSRunnable.java

/**
 * Runnable implementation to thread the work done in this class, allowing the
 * implementer to set a thread timeout and thereby short-circuit the lookup.
 */// w ww.ja v a  2 s .co m
@Override
public void run() {
    try {
        LOGGER.debug("Attempting to resolve {}", this.ipAddress);
        final InetAddress address = InetAddress.getByName(this.ipAddress);
        set(address.getCanonicalHostName());
    } catch (final UnknownHostException e) {
        /** N/A -- Default to IP address, but that's already done. **/
        LOGGER.debug("Unable to identify the canonical hostname for ip address.", e);
    }
}

From source file:org.smartfrog.test.unit.net.BasicNetworkingTest.java

/**
 * @throws UnknownHostException network problems
 */// ww w .  j a v a2s. c o m
public void testReverseDNSFullyWorking() throws UnknownHostException {
    InetAddress addr = InetAddress.getLocalHost();
    String hostname = addr.getCanonicalHostName();
    logHostname(hostname);
}

From source file:org.trafodion.rest.util.NetworkConfiguration.java

public void getCanonicalHostName(NetworkInterface ni, InetAddress inet) throws Exception {
    if (inet.getCanonicalHostName().contains(".")) {
        intHostAddress = extHostAddress = inet.getHostAddress();
        canonicalHostName = inet.getCanonicalHostName();
        LOG.info("Using interface [" + ni.getDisplayName() + "," + canonicalHostName + "," + extHostAddress
                + "]");
        ia = inet;/*from w  w w . ja v a 2 s. c  o m*/
    }

}

From source file:com.gomoob.embedded.command.GetConfigurationCommand.java

private JSONObject createNet(IMongoContext mongoContext) throws CommandException {

    String bindIp = mongoContext.getMongodConfig().net().getBindIp();
    int port = mongoContext.getMongodConfig().net().getPort();
    boolean ipv6 = mongoContext.getMongodConfig().net().isIpv6();

    JSONObject serverAddress = new JSONObject();

    try {//from   w w w. j a va2  s  . co  m
        InetAddress inetAddress = mongoContext.getMongodConfig().net().getServerAddress();
        serverAddress.put("canonicalHostName", inetAddress.getCanonicalHostName());
        serverAddress.put("hostAddress", inetAddress.getHostAddress());
        serverAddress.put("hostName", inetAddress.getHostName());
    } catch (UnknownHostException uhex) {
        throw new CommandException(uhex);
    }

    JSONObject net = new JSONObject();
    net.put("bindIp", bindIp);
    net.put("port", port);
    net.put("ipv6", ipv6);
    net.put("serverAddress", serverAddress);

    return net;

}

From source file:org.paxle.core.monitorable.provider.impl.NetworkMonitoring.java

public StatusVariable getStatusVariable(String name) throws IllegalArgumentException {
    if (!VAR_NAMES.contains(name)) {
        throw new IllegalArgumentException("Invalid Status Variable name " + name);
    }/*from   w  w  w. j ava 2s. c o m*/

    String value = null;
    try {
        final InetAddress localhost = InetAddress.getLocalHost();
        if (name.equals(VAR_NAME_HOSTNAME)) {
            value = localhost.getCanonicalHostName();
        } else if (name.equals(VAR_NAME_IP_ADDRESS)) {
            value = localhost.getHostAddress();
        }
    } catch (UnknownHostException e) {
        this.logger.error(e);
    }

    return new StatusVariable(name, StatusVariable.CM_SI, value == null ? "" : value);
}

From source file:org.ebayopensource.scc.track.TrackerClient.java

public String getHostName() {
    InetAddress ia = getInetAddress();
    return ia != null ? ia.getCanonicalHostName() : Tracker.UNKNOWN;
}

From source file:io.fabric8.apiman.ManagerApiMicroServiceConfig.java

@PostConstruct
protected void postConstruct() {

    String host = null;/*from  w ww .j a  va 2 s.  c om*/
    try {
        InetAddress initAddress = InetAddress.getByName("ELASTICSEARCH");
        host = initAddress.getCanonicalHostName();
    } catch (UnknownHostException e) {
        log.error("Could not resolve DNS for ELASTICSEARCH, trying ENV settings next.", e);
    }
    String hostAndPort = Systems.getServiceHostAndPort("ELASTICSEARCH", "localhost", "9200");
    String[] hp = hostAndPort.split(":");
    if (host == null) {
        log.info("ELASTICSEARCH host:port is set to " + hostAndPort + " using ENV settings.");
        host = hp[0];
    }
    String protocol = Systems.getEnvVarOrSystemProperty("ELASTICSEARCH_PROTOCOL", "http");
    System.out.println("*** Connecting to Elastic at service " + protocol + "://" + host + ":" + hp[1]);
    log.debug("CONNECTING TO 'elasticsearch' on " + protocol + "://" + host + ":" + hp[1]);
    config = new SystemConfiguration();
    config.setProperty(APIMAN_MANAGER_STORAGE_ES_HOST, host);
    config.setProperty(APIMAN_MANAGER_STORAGE_ES_PORT, hp[1]);
    config.setProperty(APIMAN_MANAGER_STORAGE_ES_PROTOCOL, protocol);
    config.setProperty(APIMAN_MANAGER_STORAGE_ES_CLUSTER_NAME, "elasticsearch");
}

From source file:org.apache.falcon.service.ProxyUserService.java

private String normalizeHostname(String name) {
    try {//from   w  ww  . j a v a 2s.com
        InetAddress address = InetAddress.getByName(name);
        return address.getCanonicalHostName();
    } catch (IOException ex) {
        throw new AccessControlException(
                MessageFormat.format("Could not resolve host [{0}], [{1}]", name, ex.getMessage()));
    }
}

From source file:com.kylinolap.rest.service.BasicService.java

public JobManager getJobManager() throws JobException, UnknownHostException {
    KylinConfig config = KylinConfig.getInstanceFromEnv();

    JobEngineConfig engineCntx = new JobEngineConfig(config);

    InetAddress ia = InetAddress.getLocalHost();
    return new JobManager(ia.getCanonicalHostName(), engineCntx);
}