Example usage for java.net InetAddress getHostName

List of usage examples for java.net InetAddress getHostName

Introduction

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

Prototype

public String getHostName() 

Source Link

Document

Gets the host name for this IP address.

Usage

From source file:org.ambraproject.service.AmbraMailerImpl.java

public void sendError(String message) {
    final Map<String, Object> newMapFields = new HashMap<String, Object>();

    String host = "couldn't get hostname";

    try {// w  w w  . j  av  a  2s  . co  m
        InetAddress netAddress = InetAddress.getLocalHost();
        host = netAddress.getHostName();
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }

    newMapFields.putAll(errorEmailMap);
    newMapFields.put("error", message);
    newMapFields.put("host", host);

    sendEmail(errorEmailMap.get(TO_EMAIL_ADDRESS), getFromEmailAddress(), newMapFields);
}

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

/**
 * @throws UnknownHostException network problems
 *///from   ww w  .  ja  v a2 s. com
public void testReverseDNSWorking() throws UnknownHostException {
    InetAddress addr = InetAddress.getLocalHost();
    String hostname = addr.getHostName();
    logHostname(hostname);
}

From source file:com.eternity.common.communication.servlet.AsyncDispatch.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {/*from  ww w.  j  a v a2 s. c o m*/
        InetAddress addr = InetAddress.getLocalHost();
        hostName = addr.getHostName();
    } catch (UnknownHostException e) {
        log.error("", e);
    }
}

From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
    final String hostName = host.getHostName();
    final String resolvedHost = resolver.resolve(hostName);
    if (resolvedHost != null && !resolvedHost.equals(hostName)) {
        if (InetAddressUtils.isIPv6Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port);
        } else if (InetAddressUtils.isIPv4Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port);
        }/* ww w .ja va2 s .c o  m*/
    }
    return defaultFactory.createSocket(host, port);
}

From source file:com.github.kpavlov.ssl.DynamicSSLSocketFactory.java

@Override
public Socket createSocket(InetAddress address, int port) throws IOException {
    return getSslSocketFactory(address.getHostName()).createSocket(address, port);
}

From source file:org.usapi.common.USAPIException.java

private String getFailureArtifactFileName() {
    String hostname = "";
    try {//w w  w. jav  a 2 s  .  c  om
        InetAddress addr = InetAddress.getLocalHost();
        hostname = addr.getHostName() + "_";
    } catch (UnknownHostException e) {
        // ignore, default host name to empty string
    }

    String os = System.getProperty("os.name");
    os = os.replace(' ', '_');

    String browser = PropertyHelper.getSeleniumBrowserCommand();

    browser = browser.charAt(0) == '*' ? browser.substring(1) : browser;

    return hostname + os + "_" + browser + "_" + getCaller().getClassName() + "_" + getCaller().getMethodName();
}

From source file:org.mangelp.fakeSmtpWeb.httpServer.HttpServer.java

public HttpServer(InetAddress addr, int port) {
    super(addr != null ? addr.getHostName() : null, port);
    this.serverPort = port;
    this.serverAddr = addr != null ? addr.toString() : "";
}

From source file:org.onebusaway.webapp.actions.StatusAction.java

@Override
public String execute() {

    Map<String, Object> configuration = _configurationService.getConfiguration(_forceRefresh, ERROR);
    _model.putAll(configuration);/*from   ww  w  . ja  va  2 s.c  o m*/

    try {
        InetAddress address = InetAddress.getLocalHost();
        _model.put("hostAddress", address.getHostAddress());
        _model.put("hostName", address.getHostName());
    } catch (Exception ex) {
        _log.warn("error determining hostname", ex);
    }

    return SUCCESS;
}

From source file:org.chililog.server.engine.InternalLog4JAppender.java

/**
 * Basic Constructor/*from  w  w w. j  av a  2s.c o m*/
 * 
 * @throws ChiliLogException
 */
public InternalLog4JAppender() throws ChiliLogException {
    _tokenizer = TextTokenizer.getInstance();
    _db = MongoConnection.getInstance().getConnection();
    _coll = _db.getCollection(MONGODB_COLLECTION_NAME);

    try {
        InetAddress addr = InetAddress.getLocalHost();
        _host = addr.getHostName();
        if (StringUtils.isBlank(_host)) {
            _host = addr.getHostAddress();
        }
    } catch (Exception e) {
        _host = "unknown";
    }

    return;
}

From source file:org.mule.test.firewall.FirewallTestCase.java

protected String addressToString(InetAddress address) {
    return address.getHostName() + "/" + address.getCanonicalHostName() + "/" + address.getHostAddress();
}