Example usage for java.net InetAddress getByName

List of usage examples for java.net InetAddress getByName

Introduction

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

Prototype

public static InetAddress getByName(String host) throws UnknownHostException 

Source Link

Document

Determines the IP address of a host, given the host's name.

Usage

From source file:org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
        throws IOException, UnknownHostException {
    return fireOffThread(InetAddress.getByName(host), port, localHost, localPort);
}

From source file:com.opensoc.enrichment.adapters.whois.WhoisHBaseAdapterTest.java

protected void setUp() throws Exception {
    super.setUp();
    Properties prop = super.getTestProperties();
    assertNotNull(prop);//from   ww w .  j  av  a  2s. c  o  m

    if (skipTests(this.getMode())) {
        return;//skip tests
    }

    String[] zk = prop.get("kafka.zk.list").toString().split(",");

    for (String z : zk) {
        InetAddress address = InetAddress.getByName(z);
        boolean reachable = address.isReachable(100);

        if (!reachable) {
            this.setMode("local");
            break;
            //throw new Exception("Unable to reach zookeeper, skipping WHois adapter test");
        }

        System.out.println("kafka.zk.list =" + (String) prop.get("kafka.zk.list"));
        System.out.println("kafka.zk.list =" + (String) prop.get("kafka.zk.port"));
        System.out.println("kafka.zk.list =" + (String) prop.get("bolt.enrichment.cif.tablename"));

    }

    if (skipTests(this.getMode())) {
        System.out.println("Local Mode Skipping tests !! ");
    } else {
        whoisHbaseAdapter = new WhoisHBaseAdapter((String) prop.get("bolt.enrichment.whois.hbase.table.name"),
                (String) prop.get("kafka.zk.list"), (String) prop.get("kafka.zk.port"));
        connected = whoisHbaseAdapter.initializeAdapter();
        assertTrue(connected);
    }

}

From source file:com.predic8.membrane.servlet.embedded.HttpServletHandler.java

public HttpServletHandler(HttpServletRequest request, HttpServletResponse response, Transport transport)
        throws IOException {
    super(transport);
    this.request = request;
    this.response = response;
    remoteAddr = InetAddress.getByName(request.getRemoteAddr());
    localAddr = InetAddress.getByName(request.getLocalAddr());
    exchange = new Exchange(this);

    exchange.setProperty(Exchange.HTTP_SERVLET_REQUEST, request);
}

From source file:com.couchbase.client.core.config.DefaultCouchbaseBucketConfigTest.java

@Test
public void shouldFallbackToNodeHostnameIfNotInNodesExt() throws Exception {
    String raw = Resources.read("nodes_ext_without_hostname.json", getClass());
    CouchbaseBucketConfig config = JSON_MAPPER.readValue(raw, CouchbaseBucketConfig.class);

    InetAddress expected = InetAddress.getByName("1.2.3.4");
    assertEquals(1, config.nodes().size());
    assertEquals(expected, config.nodes().get(0).hostname());

}

From source file:fr.gouv.finances.dgfip.xemelios.common.NetAccess.java

public static HttpClient getHttpClient(PropertiesExpansion applicationProperties)
        throws DataConfigurationException {
    String proxyHost = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_SERVER);
    String proxyPort = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PORT);
    String proxyUser = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_USER);
    String sTmp = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PASSWD);
    String proxyPasswd = sTmp != null ? Scramble.unScramblePassword(sTmp) : null;
    int intProxyPort = 0;
    if (proxyPort != null) {
        try {/*  w  ww .ja  va 2  s.c o m*/
            intProxyPort = Integer.parseInt(proxyPort);
        } catch (NumberFormatException nfEx) {
            throw new DataConfigurationException(proxyPort + " n'est pas un numro de port valide.");
        }
    }
    String domainName = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_DOMAIN);

    HttpClient client = new HttpClient();
    //client.getParams().setAuthenticationPreemptive(true);   // check use of this
    HostConfiguration hc = new HostConfiguration();
    if (proxyHost != null) {
        hc.setProxy(proxyHost, intProxyPort);
        client.setHostConfiguration(hc);
    }
    if (proxyUser != null) {
        Credentials creds = null;
        if (domainName != null && domainName.length() > 0) {
            String hostName = "127.0.0.1";
            try {
                InetAddress ip = InetAddress.getByName("127.0.0.1");
                hostName = ip.getHostName();
            } catch (Exception ex) {
                logger.error("", ex);
            }
            creds = new NTCredentials(proxyUser, proxyPasswd, hostName, domainName);
        } else {
            creds = new UsernamePasswordCredentials(proxyUser, proxyPasswd);
        }
        client.getState().setProxyCredentials(AuthScope.ANY, creds);
        //            client.getState().setProxyCredentials(AuthScope.ANY,new UsernamePasswordCredentials(proxyUser,proxyPasswd));
    }
    return client;
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchMultiTypeIndexTest.java

private void clear() throws Exception {
    try (final CloseableHttpClient httpClient = HttpClients.createDefault()) {
        final HttpHost host = new HttpHost(InetAddress.getByName(esr.getHostname()), ElasticsearchRunner.PORT);
        IOUtils.closeQuietly(httpClient.execute(host, new HttpDelete("janusgraph*")));
    }/*from  w w w. j a  v a2  s . c  o  m*/
}

From source file:com.microrisc.simply.network.SimpleNetworkConnectionStorageFactory.java

/** Creates and returns UDP configuration settings. */
private UDPConnectionInfo getUDPConnectionInfo(Configuration networkConfig) throws UnknownHostException {
    String hostStr = networkConfig.getString("host");
    InetAddress ipAddress = InetAddress.getByName(hostStr);
    int port = networkConfig.getInt("port");
    return new BaseUDPConnectionInfo(ipAddress, port);
}

From source file:com.neophob.sematrix.output.ArtnetDevice.java

/**
 * /*from w ww  .  j  av a 2 s .  c  om*/
 * @param controller
 */
public ArtnetDevice(ApplicationConfigurationHelper ph, PixelControllerOutput controller) {
    super(OutputDeviceEnum.ARTNET, ph, controller, 8);

    this.initialized = false;
    this.artnet = new ArtNet();
    try {
        this.pixelsPerUniverse = ph.getArtNetPixelsPerUniverse();
        this.targetAdress = InetAddress.getByName(ph.getArtNetIp());
        this.firstUniverseId = ph.getArtNetStartUniverseId();
        String broadcastAddr = ph.getArtNetBroadcastAddr();
        if (StringUtils.isBlank(broadcastAddr)) {
            broadcastAddr = ArtNetServer.DEFAULT_BROADCAST_IP;
        }

        LOG.log(Level.INFO, "Initialize ArtNet device IP: {0}, broadcast IP: {1}, Port: {2}",
                new Object[] { this.targetAdress.toString(), broadcastAddr, ArtNetServer.DEFAULT_PORT });

        this.artnet.init();
        this.artnet.setBroadCastAddress(broadcastAddr);
        this.artnet.start();
        this.artnet.getNodeDiscovery().addListener(this);
        this.artnet.startNodeDiscovery();

        //check how many universe we need
        this.nrOfUniverse = 1;
        int bufferSize = xResolution * yResolution;
        if (bufferSize > pixelsPerUniverse) {
            while (bufferSize > pixelsPerUniverse) {
                this.nrOfUniverse++;
                bufferSize -= pixelsPerUniverse;
            }
        }

        this.initialized = true;
        LOG.log(Level.INFO, "ArtNet device initialized using {0} universe with {1} pixels.",
                new Object[] { this.nrOfUniverse, this.pixelsPerUniverse });

    } catch (BindException e) {
        LOG.log(Level.WARNING, "\nFailed to initialize ArtNet device:", e);
        LOG.log(Level.WARNING, "Make sure no ArtNet Tools like DMX-Workshop are running!\n\n");
    } catch (Exception e) {
        LOG.log(Level.WARNING, "Failed to initialize ArtNet device:", e);
    }
}

From source file:iscas.SpringDataExamplesElasticsearch.Application.java

@Bean
public Client client() {
    TransportClient client = null;/* w w w  .  j a  va  2  s  .  c  o m*/
    try {
        client = TransportClient.builder().build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("124.16.136.144"), 9300));
    } catch (Exception e) {
        log.error(e.toString());
    }
    return client;
}

From source file:co.cask.cdap.security.server.ExternalLDAPAuthenticationServerSSLTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    URL certUrl = ExternalLDAPAuthenticationServerSSLTest.class.getClassLoader().getResource("cert.jks");
    Assert.assertNotNull(certUrl);/*from w  w  w.ja  v a 2s  .c  o m*/

    String authHandlerConfigBase = Constants.Security.AUTH_HANDLER_CONFIG_BASE;

    CConfiguration cConf = CConfiguration.create();
    SConfiguration sConf = SConfiguration.create();
    cConf.set(Constants.Security.AUTH_SERVER_BIND_ADDRESS, "127.0.0.1");
    cConf.set(Constants.Security.SSL.EXTERNAL_ENABLED, "true");
    cConf.set(Constants.Security.AuthenticationServer.SSL_PORT, "0");
    cConf.set(authHandlerConfigBase.concat("useLdaps"), "true");
    cConf.set(authHandlerConfigBase.concat("ldapsVerifyCertificate"), "false");
    sConf.set(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PATH, certUrl.getPath());
    configuration = cConf;
    sConfiguration = sConf;

    String keystorePassword = sConf.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PASSWORD);
    KeyStoreKeyManager keyManager = new KeyStoreKeyManager(certUrl.getFile(), keystorePassword.toCharArray());
    SSLUtil sslUtil = new SSLUtil(keyManager, new TrustAllTrustManager());
    ldapListenerConfig = InMemoryListenerConfig.createLDAPSConfig("LDAP", InetAddress.getByName("127.0.0.1"),
            ldapPort, sslUtil.createSSLServerSocketFactory(), sslUtil.createSSLSocketFactory());

    testServer = new ExternalLDAPAuthenticationServerSSLTest();
    testServer.setup();
}