Example usage for java.net InetSocketAddress getPort

List of usage examples for java.net InetSocketAddress getPort

Introduction

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

Prototype

public final int getPort() 

Source Link

Document

Gets the port number.

Usage

From source file:com.github.brandtg.discovery.TestHelixServiceDiscoveryBundle.java

private static void checkServices(List<InetSocketAddress> services) throws Exception {
    for (InetSocketAddress service : services) {
        HttpURLConnection conn = (HttpURLConnection) new URL(
                String.format("http://%s:%d/hello-world", service.getHostName(), service.getPort()))
                        .openConnection();
        String result = IOUtils.toString(conn.getInputStream());
        Assert.assertEquals(result, "Hello World!");
    }//from  ww w .  ja  v  a  2  s . c  om
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static Object buildInetSocketAddress(InetSocketAddress data) {
    JSONArray address = new JSONArray();
    address.put(data.getHostName());//w w w. j  a  v a  2 s  .co m
    address.put(data.getPort());
    return address;
}

From source file:org.elasticsearch.test.SecuritySingleNodeTestCase.java

private static RestClient createRestClient(Client client,
        RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
    NodesInfoResponse nodesInfoResponse = client.admin().cluster().prepareNodesInfo().get();
    assertFalse(nodesInfoResponse.hasFailures());
    assertEquals(nodesInfoResponse.getNodes().size(), 1);
    NodeInfo node = nodesInfoResponse.getNodes().get(0);
    assertNotNull(node.getHttp());/*from  w  w w.  j  a va 2s  .co  m*/
    TransportAddress publishAddress = node.getHttp().address().publishAddress();
    InetSocketAddress address = publishAddress.address();
    final HttpHost host = new HttpHost(NetworkAddress.format(address.getAddress()), address.getPort(),
            protocol);
    RestClientBuilder builder = RestClient.builder(host);
    if (httpClientConfigCallback != null) {
        builder.setHttpClientConfigCallback(httpClientConfigCallback);
    }
    return builder.build();
}

From source file:android.net.Proxy.java

/**
 * Returns the preferred proxy to be used by clients. This is a wrapper
 * around {@link android.net.Proxy#getHost()}.
 *
 * @param context the context which will be passed to
 * {@link android.net.Proxy#getHost()}/*from w  w  w .jav a  2s.  co  m*/
 * @param url the target URL for the request
 * @note Calling this method requires permission
 * android.permission.ACCESS_NETWORK_STATE
 * @return The preferred proxy to be used by clients, or null if there
 * is no proxy.
 * {@hide}
 */
public static final HttpHost getPreferredHttpHost(Context context, String url) {
    java.net.Proxy prefProxy = getProxy(context, url);
    if (prefProxy.equals(java.net.Proxy.NO_PROXY)) {
        return null;
    } else {
        InetSocketAddress sa = (InetSocketAddress) prefProxy.address();
        return new HttpHost(sa.getHostName(), sa.getPort(), "http");
    }
}

From source file:com.zimbra.common.httpclient.HttpProxyConfig.java

public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) {
    if (!LC.client_use_system_proxy.booleanValue())
        return null;

    URI uri = null;/*ww  w  .  j a  va  2s . c o  m*/
    try {
        uri = new URI(uriStr);
    } catch (URISyntaxException x) {
        ZimbraLog.net.info(uriStr, x);
        return null;
    }

    //no need to filter out localhost as the DefaultProxySelector will do that.

    List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri);
    for (Proxy proxy : proxies) {
        switch (proxy.type()) {
        case DIRECT:
            return null;
        case HTTP:
            InetSocketAddress addr = (InetSocketAddress) proxy.address();
            if (ZimbraLog.net.isDebugEnabled()) {
                ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString());
            }
            ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc);
            nhc.setProxy(addr.getHostName(), addr.getPort());
            if (proxy instanceof AuthProxy) {
                nhc.setUsername(((AuthProxy) proxy).getUsername());
                nhc.setPassword(((AuthProxy) proxy).getPassword());
            }
            return nhc;
        case SOCKS: //socks proxy can be handled at socket factory level
        default:
            continue;
        }
    }
    return null;
}

From source file:ezbake.thrift.ThriftUtils.java

public static TServerSocket getSslServerSocket(InetSocketAddress addr, Properties properties)
        throws TTransportException {
    return EzSSLTransportFactory.getServerSocket(addr.getPort(), 0, addr.getAddress(),
            new EzSSLTransportFactory.EzSSLTransportParameters(properties));
}

From source file:co.cask.tigon.test.BasicFlowTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    // Create and start the Netty service.
    service = NettyHttpService.builder().addHttpHandlers(ImmutableList.of(new TestHandler())).build();

    service.startAndWait();/*w w w  .  jav a 2s.c om*/
    InetSocketAddress address = service.getBindAddress();
    baseURL = "http://" + address.getHostName() + ":" + address.getPort();

    httpClient = new HttpClient();
}

From source file:eu.stratosphere.nephele.net.NetUtils.java

/**
 * Returns InetSocketAddress that a client can use to
 * connect to the server. Server.getListenerAddress() is not correct when
 * the server binds to "0.0.0.0". This returns "127.0.0.1:port" when
 * the getListenerAddress() returns "0.0.0.0:port".
 * //from   w w w.  j a  v  a2  s.c o  m
 * @param server
 * @return socket address that a client can use to connect to the server.
 */
public static InetSocketAddress getConnectAddress(Server server) {
    InetSocketAddress addr = server.getListenerAddress();
    if (addr.getAddress().getHostAddress().equals("0.0.0.0")) {
        addr = new InetSocketAddress("127.0.0.1", addr.getPort());
    }
    return addr;
}

From source file:es.eucm.eadventure.editor.plugin.vignette.ProxySetup.java

private static void init() {
    proxyConfig = null;/*from   www . j a  va2  s  .  c om*/
    log = Logger.getLogger("es.eucm.eadventure.tracking.prv.service.ProxyConfig");
    handler = null;
    try {
        handler = new FileHandler("proxy.log");
        log.addHandler(handler);
    } catch (SecurityException e) {
        handler = null;
        e.printStackTrace();
    } catch (IOException e) {
        handler = null;
        e.printStackTrace();
    }
    //Log log = LogFactory.getLog( "es.eucm.eadventure.tracking.prv.service.ProxyConfig" );
    log("Setting prop java.net.useSystemProxies=true");
    System.setProperty("java.net.useSystemProxies", "true");
    Proxy proxy = getProxy();
    if (proxy != null) {
        InetSocketAddress addr = (InetSocketAddress) proxy.address();
        if (addr == null) {
            log("No proxy detected");
            System.out.println("NO PROXY");
        } else {
            String host = addr.getHostName();
            int port = addr.getPort();
            proxyConfig = new ProxyConfig();
            proxyConfig.setHostName(host);
            proxyConfig.setPort("" + port);
            proxyConfig.setProtocol("http");
            log("Proxy detected: host=" + host + " port=" + port);
            System.setProperty("java.net.useSystemProxies", "false");
            System.setProperty("http.proxyHost", host);
            System.setProperty("http.proxyPort", "" + port);
            log("Setting up system proxy host & port");
        }

    }
    System.setProperty("java.net.useSystemProxies", "false");
    log("Setting prop java.net.useSystemProxies=false");
    init = true;
}

From source file:org.apache.hadoop.hdfs.server.namenode.AvatarNodeZkUtil.java

public static String toIpPortString(InetSocketAddress addr) {
    return addr.getAddress().getHostAddress() + ":" + addr.getPort();
}