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:org.opennms.minion.stests.utils.HibernateDaoFactory.java

public HibernateDaoFactory(InetSocketAddress pgsqlAddr) {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setPortNumber(pgsqlAddr.getPort());
    dataSource.setUser("postgres");
    dataSource.setPassword("postgres");
    dataSource.setServerName(pgsqlAddr.getAddress().getHostAddress());
    dataSource.setDatabaseName("opennms");

    AnnotationSessionFactoryBean sfb = new AnnotationSessionFactoryBean();
    sfb.setDataSource(dataSource);/*from ww w.  ja v a 2s.  c  o  m*/
    sfb.setPackagesToScan("org.opennms.netmgt.model");
    try {
        sfb.afterPropertiesSet();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    m_sessionFactory = sfb.getObject();
    m_hibernateTemplate = new HibernateTemplate(m_sessionFactory);
}

From source file:com.nesscomputing.service.discovery.client.DiscoveryClientModule.java

@Provides
@Singleton/*from  w w w.  ja v a  2s  .  com*/
@Named(ZOOKEEPER_CONNECT_NAME)
String getConnectString(@Named(ZOOKEEPER_CONNECT_NAME) final Map<Integer, InetSocketAddress> zookeeperServers,
        final DiscoveryClientConfig clientConfig) {
    final StringBuilder sb = new StringBuilder();

    for (final InetSocketAddress address : zookeeperServers.values()) {
        if (sb.length() > 0) {
            sb.append(',');
        }
        sb.append(address.getAddress().getHostAddress()).append(':').append(address.getPort());
    }

    if (sb.length() == 0) {
        if (clientConfig.isEnabled()) {
            throw new IllegalStateException("Service discovery is enabled but no servers found!");
        } else {
            LOG.info("No servers found!");
        }
    }
    return sb.toString();
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void connectShouldReturnTrueWhenConnecting() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();/*  w  w  w . j  a  v  a 2 s .  c  om*/

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());
    assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isTrue();
}

From source file:org.apache.tajo.master.querymaster.QueryMasterManagerService.java

@Override
public void init(Configuration conf) {
    Preconditions.checkArgument(conf instanceof TajoConf);
    TajoConf tajoConf = (TajoConf) conf;
    try {/* www. j av  a 2 s  .  c  o  m*/
        // Setup RPC server
        InetSocketAddress initIsa = new InetSocketAddress("0.0.0.0", port);
        if (initIsa.getAddress() == null) {
            throw new IllegalArgumentException("Failed resolve of " + initIsa);
        }

        int workerNum = tajoConf.getIntVar(TajoConf.ConfVars.QUERY_MASTER_RPC_SERVER_WORKER_THREAD_NUM);
        this.rpcServer = new AsyncRpcServer(QueryMasterProtocol.class, this, initIsa, workerNum);
        this.rpcServer.start();

        this.bindAddr = NetUtils.getConnectAddress(rpcServer.getListenAddress());
        this.addr = bindAddr.getHostName() + ":" + bindAddr.getPort();

        this.port = bindAddr.getPort();

        queryMaster = new QueryMaster(workerContext);
        addService(queryMaster);

    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    // Get the master address
    LOG.info("QueryMasterManagerService is bind to " + addr);
    ((TajoConf) conf).setVar(TajoConf.ConfVars.WORKER_QM_RPC_ADDRESS, addr);

    super.init(conf);
}

From source file:org.apache.tajo.querymaster.QueryMasterManagerService.java

@Override
public void serviceInit(Configuration conf) throws Exception {

    TajoConf tajoConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
    // Setup RPC server
    InetSocketAddress initIsa = tajoConf.getSocketAddrVar(TajoConf.ConfVars.WORKER_QM_RPC_ADDRESS);
    if (initIsa.getAddress() == null) {
        throw new IllegalArgumentException("Failed resolve of " + initIsa);
    }//  w w w. j  a v  a 2s . c o  m

    int workerNum = tajoConf.getIntVar(TajoConf.ConfVars.QUERY_MASTER_RPC_SERVER_WORKER_THREAD_NUM);
    this.rpcServer = new AsyncRpcServer(QueryMasterProtocol.class, this, initIsa, workerNum);
    this.rpcServer.start();

    this.bindAddr = NetUtils.getConnectAddress(rpcServer.getListenAddress());

    this.queryMaster = new QueryMaster(workerContext);
    addService(queryMaster);
    // Get the master address
    LOG.info("QueryMasterManagerService is bind to " + bindAddr);
    tajoConf.setVar(TajoConf.ConfVars.WORKER_QM_RPC_ADDRESS, NetUtils.getHostPortString(bindAddr));
    super.serviceInit(tajoConf);
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void ehloShouldReturnTrueWhenSendingTheCommand() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();/* w w w.j a va 2 s.c  o  m*/

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());

    smtpsClient.sendCommand("EHLO localhost");
    assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isTrue();
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void startTlsShouldBeAnnouncedWhenServerSupportsIt() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();//from   w  w w .  j a  va2  s .c  om

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());
    smtpsClient.sendCommand("EHLO localhost");

    assertThat(new StartTLSAssert(smtpsClient)).isStartTLSAnnounced();
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void startTlsShouldReturnTrueWhenServerSupportsIt() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();/*  w  w w .  ja v a  2  s . co  m*/

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());
    smtpsClient.sendCommand("EHLO localhost");

    boolean execTLS = smtpsClient.execTLS();
    assertThat(execTLS).isTrue();
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void startTlsShouldFailWhenFollowedByInjectedCommand() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();/*from ww w .  ja v  a  2  s  . co  m*/

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());
    smtpsClient.sendCommand("EHLO localhost");

    smtpsClient.sendCommand("STARTTLS\r\nRSET\r\n");
    assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse();
}

From source file:org.apache.james.protocols.smtp.netty.NettyStartTlsSMTPServerTest.java

@Test
public void startTlsShouldFailWhenFollowedByInjectedCommandAndNotAtBeginningOfLine() throws Exception {
    server = createServer(createProtocol(Optional.<ProtocolHandler>absent()),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    smtpsClient = createClient();/*from w ww .j  a va  2s.  c  o m*/

    server.bind();
    InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();
    smtpsClient.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort());
    smtpsClient.sendCommand("EHLO localhost");

    smtpsClient.sendCommand("RSET\r\nSTARTTLS\r\nRSET\r\n");
    assertThat(SMTPReply.isPositiveCompletion(smtpsClient.getReplyCode())).isFalse();
}