Example usage for java.net InetSocketAddress getAddress

List of usage examples for java.net InetSocketAddress getAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress getAddress.

Prototype

public final InetAddress getAddress() 

Source Link

Document

Gets the InetAddress .

Usage

From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java

/**
 * Obtains a host from an {@link InetSocketAddress}.
 * /*from  w  w  w .j  a  v  a 2  s.  co  m*/
 * @param isa the socket address
 * @return a host string, either as a symbolic name or as a literal IP address string
 */
protected String getHost(InetSocketAddress isa) {
    return isa.isUnresolved() ? isa.getHostName() : isa.getAddress().getHostAddress();
}

From source file:org.scassandra.http.client.CurrentClient.java

public ClosedConnectionReport closeConnection(CloseType closeType, InetSocketAddress address) {
    return closeConnectionsByUrl(closeType,
            "/" + address.getAddress().getHostAddress() + "/" + address.getPort());
}

From source file:it.anyplace.sync.discovery.utils.AddressRanker.java

private int testTcpConnection(InetSocketAddress socketAddress) {
    return socketAddressScoreCache
            .getUnchecked(Pair.of(socketAddress.getAddress().getHostAddress(), socketAddress.getPort()));
}

From source file:org.hydracache.server.httpd.AsyncHttpLightServer.java

InetSocketAddress buildInetSocketAddress() {
    InetSocketAddress address = null;

    address = new InetSocketAddress(ip, portNumber);

    if (log.isDebugEnabled()) {
        log.debug("Server is listening on address [" + address.getAddress().getHostAddress() + ":"
                + address.getPort() + "]");
    }/*from w w  w . j  a  v  a2  s.c o m*/

    return address;
}

From source file:eu.stratosphere.client.CliFrontendJobManagerConnectionTest.java

@Test
public void testManualOptionsOverridesConfig() {
    try {//w w w.java  2 s.  com
        String[] arguments = { "-m", "10.221.130.22:7788" };
        CommandLine line = new PosixParser().parse(CliFrontend.getJobManagerAddressOption(new Options()),
                arguments, false);

        TestingCliFrontend frontend = new TestingCliFrontend(CliFrontendTestUtils.getConfigDir());

        InetSocketAddress address = frontend.getJobManagerAddress(line);

        assertNotNull(address);
        assertEquals("10.221.130.22", address.getAddress().getHostAddress());
        assertEquals(7788, address.getPort());
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail("Program caused an exception: " + e.getMessage());
    }
}

From source file:eu.stratosphere.client.CliFrontendJobManagerConnectionTest.java

@Test
public void testManualOptionsOverridesYarn() {
    try {//from  ww w .  j ava  2s.c o  m
        String[] arguments = { "-m", "10.221.130.22:7788" };
        CommandLine line = new PosixParser().parse(CliFrontend.getJobManagerAddressOption(new Options()),
                arguments, false);

        TestingCliFrontend frontend = new TestingCliFrontend(CliFrontendTestUtils.getConfigDirWithYarnFile());

        InetSocketAddress address = frontend.getJobManagerAddress(line);

        assertNotNull(address);
        assertEquals("10.221.130.22", address.getAddress().getHostAddress());
        assertEquals(7788, address.getPort());
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        fail("Program caused an exception: " + e.getMessage());
    }
}

From source file:ch.cyberduck.core.socket.NetworkInterfaceAwareSocketFactory.java

@Override
public Socket createSocket() throws IOException {
    return new HttpProxyAwareSocket(proxy) {
        @Override/*from   ww w.j  a  v a  2 s . c o m*/
        public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
            if (endpoint instanceof InetSocketAddress) {
                final InetSocketAddress address = (InetSocketAddress) endpoint;
                if (address.getAddress() instanceof Inet6Address) {
                    final NetworkInterface network = findIPv6Interface((Inet6Address) address.getAddress());
                    if (null != network) {
                        super.connect(new InetSocketAddress(NetworkInterfaceAwareSocketFactory.this
                                .getByAddressForInterface(network, address.getAddress()), address.getPort()),
                                timeout);
                        return;
                    }
                }
            }
            super.connect(endpoint, timeout);
        }
    };
}

From source file:org.jenkinsci.plugins.newrelicnotifier.api.NewRelicClientImpl.java

private CloseableHttpClient getHttpClient(URI url) {
    HttpClientBuilder builder = HttpClientBuilder.create();

    ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
    if (proxyConfig != null) {
        Proxy proxy = proxyConfig.createProxy(url.getHost());
        if (proxy != null && proxy.type() == Proxy.Type.HTTP) {
            SocketAddress addr = proxy.address();
            if (addr != null && addr instanceof InetSocketAddress) {
                InetSocketAddress proxyAddr = (InetSocketAddress) addr;
                HttpHost proxyHost = new HttpHost(proxyAddr.getAddress().getHostAddress(), proxyAddr.getPort());
                DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
                builder = builder.setRoutePlanner(routePlanner);

                String proxyUser = proxyConfig.getUserName();
                if (proxyUser != null) {
                    String proxyPass = proxyConfig.getPassword();
                    CredentialsProvider cred = new BasicCredentialsProvider();
                    cred.setCredentials(new AuthScope(proxyHost),
                            new UsernamePasswordCredentials(proxyUser, proxyPass));
                    builder = builder.setDefaultCredentialsProvider(cred)
                            .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
                }/*from   ww  w.j a va 2  s.co m*/
            }
        }
    }

    return builder.build();
}

From source file:com.stratio.ingestion.sink.cassandra.CassandraSinkIT.java

private void _do() throws TTransportException, IOException, InterruptedException {
    final Context context = new Context();
    final InetSocketAddress contactPoint = CassandraTestHelper.getCassandraContactPoint();
    context.put("tables", "keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT");
    context.put("hosts", contactPoint.getAddress().getHostAddress());
    context.put("batchSize", "1");
    context.put("consistency", "QUORUM");

    final File cqlFile = File.createTempFile("flumeTest", "cql");
    cqlFile.deleteOnExit();/* w w w. ja v a 2  s .c  o m*/

    IOUtils.write(
            "CREATE KEYSPACE IF NOT EXISTS keyspaceTestCassandraSinkIT WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };\n\n"
                    + "CREATE TABLE IF NOT EXISTS keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT ("
                    + "id uuid, bool_field boolean, int_field int, PRIMARY KEY (int_field)" + ");\n\n",
            new FileOutputStream(cqlFile));

    context.put("cqlFile", cqlFile.getAbsolutePath());
    sink = new CassandraSink();
    sink.configure(context);

    Context channelContext = new Context();
    channelContext.put("capacity", "10000");
    channelContext.put("transactionCapacity", "200");
    channel = new MemoryChannel();
    channel.setName("junitChannel");
    Configurables.configure(channel, channelContext);
    sink.setChannel(channel);

    sink.start();
    sink.stop();
}

From source file:org.opennms.smoketest.minion.DiscoveryTest.java

@Test
public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException {
    Date startOfTest = new Date();

    final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress();
    final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980);
    final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(),
            opennmsHttp.getPort());//ww  w  .  j  av a  2 s  . c  o  m

    HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()) // Ignore the 302 response to the POST
            .build();

    Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin")
            .authPreemptive(opennmsHttpHost);

    // Configure Discovery with the specific address of our Tomcat server
    // No REST endpoint is currently available, so we resort to POSTin nasty form data
    executor.execute(Request
            .Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific",
                    opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort()))
            .bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000")
                    .add("specificretries", "1").add("initialsleeptime", "30000")
                    .add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION")
                    .add("retries", "1").add("timeout", "2000").build()))
            .returnContent();

    executor.execute(Request
            .Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart",
                    opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort()))
            .bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000")
                    .add("foreignsource", "NODES").add("location", "MINION").add("retries", "1")
                    .add("timeout", "2000").build()))
            .returnContent();

    InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);

    // TODO: Match the Monitoring System ID when this becomes available in the event
    Criteria criteria = new CriteriaBuilder(OnmsEvent.class)
            .eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest)
            .toCriteria();

    await().atMost(1, MINUTES).pollInterval(10, SECONDS)
            .until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
}