Example usage for java.net InetSocketAddress getHostName

List of usage examples for java.net InetSocketAddress getHostName

Introduction

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

Prototype

public final String getHostName() 

Source Link

Document

Gets the hostname .

Usage

From source file:jetbrains.buildServer.buildTriggers.vcs.git.SNIHttpClientConnection.java

private HttpClient getClient() {
    if (client == null)
        client = new DefaultHttpClient();
    HttpParams params = client.getParams();
    if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
        isUsingProxy = true;//w w  w . j a  va  2  s  .  co  m
        InetSocketAddress adr = (InetSocketAddress) proxy.address();
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(adr.getHostName(), adr.getPort()));
    }
    if (timeout != null)
        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout.intValue());
    if (readTimeout != null)
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout.intValue());
    if (followRedirects != null)
        params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects.booleanValue());
    SSLSocketFactory sf = hostnameverifier != null ? new SNISSLSocketFactory(getSSLContext(), hostnameverifier)
            : new SNISSLSocketFactory(getSSLContext());
    Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$
    client.getConnectionManager().getSchemeRegistry().register(https);
    return client;
}

From source file:org.jolokia.jvmagent.handler.JolokiaHttpHandler.java

private String getHostName(InetSocketAddress address) {
    return configuration.getAsBoolean(ConfigKey.ALLOW_DNS_REVERSE_LOOKUP) ? address.getHostName() : null;
}

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

@Test
public void startTlsShouldWorkWhenUsingJavamail() throws Exception {
    TestMessageHook hook = new TestMessageHook();
    server = createServer(createProtocol(Optional.<ProtocolHandler>of(hook)),
            Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
    server.bind();/*from www  .j  a  v a2 s  . c  o m*/
    SMTPTransport transport = null;

    try {
        InetSocketAddress bindedAddress = new ProtocolServerUtils(server).retrieveBindedAddress();

        Properties mailProps = new Properties();
        mailProps.put("mail.smtp.from", "test@localhost");
        mailProps.put("mail.smtp.host", bindedAddress.getHostName());
        mailProps.put("mail.smtp.port", bindedAddress.getPort());
        mailProps.put("mail.smtp.socketFactory.class", BogusSSLSocketFactory.class.getName());
        mailProps.put("mail.smtp.socketFactory.fallback", "false");
        mailProps.put("mail.smtp.starttls.enable", "true");

        Session mailSession = Session.getDefaultInstance(mailProps);

        InternetAddress[] rcpts = new InternetAddress[] { new InternetAddress("valid@localhost") };
        MimeMessage message = new MimeMessage(mailSession);
        message.setFrom(new InternetAddress("test@localhost"));
        message.setRecipients(Message.RecipientType.TO, rcpts);
        message.setSubject("Testmail", "UTF-8");
        message.setText("Test.....");

        transport = (SMTPTransport) mailSession.getTransport("smtps");

        transport.connect(new Socket(bindedAddress.getHostName(), bindedAddress.getPort()));
        transport.sendMessage(message, rcpts);

        assertThat(hook.getQueued()).hasSize(1);
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
}

From source file:org.eclipse.jgit.transport.http.apache.HttpClientConnection.java

private HttpClient getClient() {
    if (client == null) {
        HttpClientBuilder clientBuilder = HttpClients.custom();
        RequestConfig.Builder configBuilder = RequestConfig.custom();
        if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
            isUsingProxy = true;/*from  w w w  . j av a  2 s  . c  o m*/
            InetSocketAddress adr = (InetSocketAddress) proxy.address();
            clientBuilder.setProxy(new HttpHost(adr.getHostName(), adr.getPort()));
        }
        if (timeout != null) {
            configBuilder.setConnectTimeout(timeout.intValue());
        }
        if (readTimeout != null) {
            configBuilder.setSocketTimeout(readTimeout.intValue());
        }
        if (followRedirects != null) {
            configBuilder.setRedirectsEnabled(followRedirects.booleanValue());
        }
        if (hostnameverifier != null) {
            SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(getSSLContext(),
                    hostnameverifier);
            clientBuilder.setSSLSocketFactory(sslConnectionFactory);
            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("https", sslConnectionFactory)
                    .register("http", PlainConnectionSocketFactory.INSTANCE).build();
            clientBuilder.setConnectionManager(new BasicHttpClientConnectionManager(registry));
        }
        clientBuilder.setDefaultRequestConfig(configBuilder.build());
        client = clientBuilder.build();
    }

    return client;
}

From source file:eu.stratosphere.nephele.profiling.impl.JobManagerProfilerImpl.java

public JobManagerProfilerImpl(InetAddress jobManagerbindAddress) throws ProfilingException {

    // Start profiling IPC server
    final int handlerCount = GlobalConfiguration.getInteger(RPC_NUM_HANDLER_KEY, DEFAULT_NUM_HANLDER);
    final int rpcPort = GlobalConfiguration.getInteger(ProfilingUtils.JOBMANAGER_RPC_PORT_KEY,
            ProfilingUtils.JOBMANAGER_DEFAULT_RPC_PORT);

    final InetSocketAddress rpcServerAddress = new InetSocketAddress(jobManagerbindAddress, rpcPort);
    Server profilingServerTmp = null;//w w  w . j  a  va2  s .c  om
    try {

        profilingServerTmp = RPC.getServer(this, rpcServerAddress.getHostName(), rpcServerAddress.getPort(),
                handlerCount);
        profilingServerTmp.start();
    } catch (IOException ioe) {
        throw new ProfilingException(
                "Cannot start profiling RPC server: " + StringUtils.stringifyException(ioe));
    }
    this.profilingServer = profilingServerTmp;

}

From source file:org.apache.tajo.cli.tools.TajoAdmin.java

private void processMasters(Writer writer) throws ParseException, IOException, ServiceException, SQLException {

    if (tajoConf.getBoolVar(TajoConf.ConfVars.TAJO_MASTER_HA_ENABLE)) {

        List<String> list = serviceTracker.getMasters(tajoConf);
        int i = 0;
        for (String master : list) {
            if (i > 0) {
                writer.write(" ");
            }/*www.j  av  a2  s. c  o  m*/
            writer.write(master);
            i++;
        }
        writer.write("\n");
    } else {
        InetSocketAddress masterAddress = tajoConf
                .getSocketAddrVar(TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS);
        writer.write(masterAddress.getHostName());
        writer.write("\n");
    }
}

From source file:org.wso2.andes.thrift.ThriftClientFactory.java

/**
 * When a new connection needs to be created this method is called.
 *
 * @return A new thrift client which is connected to the server
 * @throws Exception Throws when a thrift client fails to connect to the server
 *//*from   w w  w.j  a v a 2 s  .c  o m*/
@Override
public SlotManagementService.Client create() throws Exception {

    ClusterAgent clusterAgent = AndesContext.getInstance().getClusterAgent();
    InetSocketAddress thriftAddressOfCoordinator = clusterAgent.getThriftAddressOfCoordinator();

    if (null == thriftAddressOfCoordinator) {
        throw new ThriftClientException("Thrift coordinator details are not updated in the map yet");
    }

    int soTimeout = AndesConfigurationManager.readValue(AndesConfiguration.COORDINATION_THRIFT_SO_TIMEOUT);

    TTransport transport = new TSocket(thriftAddressOfCoordinator.getHostName(),
            thriftAddressOfCoordinator.getPort(), soTimeout);
    try {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        return new SlotManagementService.Client(protocol);
    } catch (TTransportException e) {
        throw new TTransportException("Could not initialize the Thrift client", e);
    }
}

From source file:com.maxmind.minfraud.WebServiceClient.java

private WebServiceClient(WebServiceClient.Builder builder) {
    host = builder.host;/*from w  w w.  ja v a2  s . c  o m*/
    port = builder.port;
    useHttps = builder.useHttps;
    locales = builder.locales;
    licenseKey = builder.licenseKey;
    userId = builder.userId;

    mapper = new ObjectMapper();
    mapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    RequestConfig.Builder configBuilder = RequestConfig.custom().setConnectTimeout(builder.connectTimeout)
            .setSocketTimeout(builder.readTimeout);

    if (builder.proxy != null) {
        InetSocketAddress address = (InetSocketAddress) builder.proxy.address();
        HttpHost proxyHost = new HttpHost(address.getHostName(), address.getPort());
        configBuilder.setProxy(proxyHost);
    }

    RequestConfig config = configBuilder.build();
    httpClient = HttpClientBuilder.create().setUserAgent(userAgent()).setDefaultRequestConfig(config).build();
}

From source file:ch.cyberduck.core.http.HttpConnectionPoolBuilder.java

protected HttpConnectionPoolBuilder(final Host host, final X509TrustManager trust, final X509KeyManager key,
        final ProxyFinder proxy, final SocketFactory socketFactory) {
    this(host, new PlainConnectionSocketFactory() {
        @Override//from   www  .  ja va 2s .co  m
        public Socket createSocket(final HttpContext context) throws IOException {
            return socketFactory.createSocket();
        }
    }, new SSLConnectionSocketFactory(new CustomTrustSSLProtocolSocketFactory(trust, key),
            new DisabledX509HostnameVerifier()) {
        @Override
        public Socket createSocket(final HttpContext context) throws IOException {
            return socketFactory.createSocket();
        }

        @Override
        public Socket connectSocket(final int connectTimeout, final Socket socket, final HttpHost host,
                final InetSocketAddress remoteAddress, final InetSocketAddress localAddress,
                final HttpContext context) throws IOException {
            if (trust instanceof ThreadLocalHostnameDelegatingTrustManager) {
                ((ThreadLocalHostnameDelegatingTrustManager) trust).setTarget(remoteAddress.getHostName());
            }
            return super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
        }
    }, proxy);
}

From source file:org.cstor.cproc.cloudComputingFramework.CProcFramework.java

/**
 * Initialize name-node.//from   w w w  .j  av a 2s .  c o m
 * 
 * @param conf the configuration
 */
private void initialize() throws IOException {
    String port = this.port == null ? this.rpcConf.get("cproc.node.port", "8888") : this.port;
    LOG.info("port : " + port);
    InetSocketAddress socAddr = NetUtils.createSocketAddr("0.0.0.0:" + port);
    //cprocframework? 2 JobEntityStore,JobControl
    // create rpc server 
    this.server = RPC.getServer(this, socAddr.getHostName(), socAddr.getPort(),
            this.rpcConf.getInt("cproc.node.handle", 256), false, this.rpcConf);

    LOG.info("CProcFramework node up at: " + this.server.getListenerAddress());
    //JObEntityStore.JobEntityStoremaster????
    if (this.isNN == true) {
        this.jobEntityStore = new JobEntityStore(
                this.rpcConf.getInt("cproc.jobentity.depthOfPrintJobEntityType", 3));
    }
    this.server.start(); //start RPC server   

    //JobControl
    this.jobControl = new JobControl(this.nameNode, this.dataNode, this.cprocConf, this.rpcConf, this.isNN,
            this.network, this.nameNodeAddr);
    this.jobControlThread = new Thread(this.jobControl);
    this.jobControlThread.start();

}