List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:eu.esdihumboldt.util.http.client.ClientProxyUtil.java
/** * Set-up the given HTTP client to use the given proxy * //from www . ja v a2s.c o m * @param builder the HTTP client builder * @param proxy the proxy * @return the client builder adapted with the proxy settings */ public static HttpClientBuilder applyProxy(HttpClientBuilder builder, Proxy proxy) { ProxyUtil.init(); // check if proxy shall be used if (proxy != null && proxy.type() == Type.HTTP) { InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); // set the proxy HttpHost proxyHost = new HttpHost(proxyAddress.getHostName(), proxyAddress.getPort()); builder = builder.setProxy(proxyHost); String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ String password = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ boolean useProxyAuth = user != null && !user.isEmpty(); if (useProxyAuth) { // set the proxy credentials CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyAddress.getHostName(), proxyAddress.getPort()), createCredentials(user, password)); builder = builder.setDefaultCredentialsProvider(credsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } _log.trace("Set proxy to " + proxyAddress.getHostName() + ":" + //$NON-NLS-1$ //$NON-NLS-2$ proxyAddress.getPort() + ((useProxyAuth) ? (" as user " + user) : (""))); //$NON-NLS-1$ //$NON-NLS-2$ } return builder; }
From source file:org.apache.hadoop.hbase.HServerAddress.java
private static InetSocketAddress getResolvedAddress(InetSocketAddress address) { String bindAddress = getBindAddressInternal(address); int port = address.getPort(); return new InetSocketAddress(bindAddress, port); }
From source file:com.helger.httpclient.HttpClientHelper.java
@Nullable public static HttpHost createHttpHost(@Nullable final Proxy aProxy) { if (aProxy != null && aProxy.type() == Proxy.Type.HTTP) { if (aProxy.address() instanceof InetSocketAddress) { final InetSocketAddress aISA = (InetSocketAddress) aProxy.address(); return new HttpHost(aISA.getHostName(), aISA.getPort()); }/*w w w . j a v a2s. c o m*/ } return null; }
From source file:com.kixeye.chassis.transport.shared.JettyConnectorRegistry.java
/** * Register to listen to HTTP.//from w ww . j av a 2 s.c o m * * @param server * @param address */ public static void registerHttpConnector(Server server, InetSocketAddress address) { ServerConnector connector = new ServerConnector(server); connector.setHost(address.getHostName()); connector.setPort(address.getPort()); server.addConnector(connector); }
From source file:org.apache.hadoop.hdfs.web.TestWebHdfsWithMultipleNameNodes.java
private static void setupCluster(final int nNameNodes, final int nDataNodes) throws Exception { LOG.info("nNameNodes=" + nNameNodes + ", nDataNodes=" + nDataNodes); conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true); cluster = new MiniDFSCluster.Builder(conf).nnTopology(MiniDFSNNTopology.simpleHOPSTopology(nNameNodes)) .numDataNodes(nDataNodes).format(true).build(); cluster.waitActive();/* w w w. j a v a 2 s . c om*/ webhdfs = new WebHdfsFileSystem[nNameNodes]; for (int i = 0; i < webhdfs.length; i++) { final InetSocketAddress addr = cluster.getNameNode(i).getHttpAddress(); final String uri = WebHdfsFileSystem.SCHEME + "://" + addr.getHostName() + ":" + addr.getPort() + "/"; webhdfs[i] = (WebHdfsFileSystem) FileSystem.get(new URI(uri), conf); } }
From source file:co.cask.tigon.test.SQLFlowTestBase.java
/** * This function deploys an instance of the flowClass. * Recommended, make this function call from a {@link org.junit.BeforeClass} annotated method. * @param flowClass Class of the {@link co.cask.tigon.api.flow.Flow} to be deployed * @throws Exception/*from w w w . jav a2s .co m*/ */ public static void setupFlow(Class<? extends Flow> flowClass) throws Exception { Map<String, String> runtimeArgs = Maps.newHashMap(); handler = new TestHandler(); service = NettyHttpService.builder().addHttpHandlers(ImmutableList.of(handler)) .setPort(Networks.getRandomPort()).build(); service.startAndWait(); InetSocketAddress address = service.getBindAddress(); serviceURL = "http://" + address.getHostName() + ":" + address.getPort() + "/queue"; runtimeArgs.put("baseURL", serviceURL); runtimeArgs.put(Constants.HTTP_PORT, Integer.toString(httpPort)); flowManager = deployFlow(flowClass, runtimeArgs); int maxWait = 100; // Waiting for the Tigon SQL Flow initialization while ((!flowManager.discover(Constants.HTTP_PORT).iterator().hasNext()) && (maxWait > 0)) { TimeUnit.SECONDS.sleep(1); maxWait = maxWait - 1; } if (maxWait <= 0) { throw new TimeoutException("Timeout Error, Tigon SQL flow took too long to initiate"); } }
From source file:com.mirth.connect.server.util.ConnectorUtil.java
public static ConnectionTestResponse testConnection(String host, int port, int timeout, String localAddr, int localPort) throws Exception { Socket socket = null;//w ww. ja v a 2s . c om InetSocketAddress address = null; InetSocketAddress localAddress = null; try { address = new InetSocketAddress(host, port); if (StringUtils.isBlank(address.getAddress().getHostAddress()) || (address.getPort() < 0) || (address.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid host or port."); } if (localAddr != null) { try { localAddress = new InetSocketAddress(localAddr, localPort); if (StringUtils.isBlank(localAddress.getAddress().getHostAddress()) || (localAddress.getPort() < 0) || (localAddress.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid local host or port."); } } try { socket = new Socket(); if (localAddress != null) { try { socket.bind(localAddress); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not bind to local address: " + localAddress.getAddress().getHostAddress() + ":" + localAddress.getPort()); } } socket.connect(address, timeout); String connectionInfo = socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " -> " + address.getAddress().getHostAddress() + ":" + address.getPort(); return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS, "Successfully connected to host: " + connectionInfo, connectionInfo); } catch (SocketTimeoutException ste) { return new ConnectionTestResponse(ConnectionTestResponse.Type.TIME_OUT, "Timed out connecting to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not connect to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } finally { if (socket != null) { socket.close(); } } }
From source file:eu.esdihumboldt.util.http.ProxyUtil.java
/** * Set-up the given HTTP client to use the given proxy * // www .j a v a 2 s . c om * @param builder the HTTP client builder * @param proxy the proxy * @return the client builder adapted with the proxy settings */ public static HttpClientBuilder applyProxy(HttpClientBuilder builder, Proxy proxy) { init(); // check if proxy shall be used if (proxy != null && proxy.type() == Type.HTTP) { InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); // set the proxy HttpHost proxyHost = new HttpHost(proxyAddress.getHostName(), proxyAddress.getPort()); builder = builder.setProxy(proxyHost); String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ String password = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ boolean useProxyAuth = user != null && !user.isEmpty(); if (useProxyAuth) { // set the proxy credentials CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyAddress.getHostName(), proxyAddress.getPort()), new UsernamePasswordCredentials(user, password)); builder = builder.setDefaultCredentialsProvider(credsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } _log.trace("Set proxy to " + proxyAddress.getHostName() + ":" + //$NON-NLS-1$ //$NON-NLS-2$ proxyAddress.getPort() + ((useProxyAuth) ? (" as user " + user) : (""))); //$NON-NLS-1$ //$NON-NLS-2$ } return builder; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraClientFactory.java
public static Cassandra.Client getClientInternal(InetSocketAddress addr, boolean isSsl, int socketTimeoutMillis, int socketQueryTimeoutMillis) throws TTransportException { TSocket tSocket = new TSocket(addr.getHostString(), addr.getPort(), socketTimeoutMillis); tSocket.open();// w ww .ja v a2 s . c o m try { tSocket.getSocket().setKeepAlive(true); tSocket.getSocket().setSoTimeout(socketQueryTimeoutMillis); } catch (SocketException e) { log.error("Couldn't set socket keep alive for {}", addr); } if (isSsl) { boolean success = false; try { SSLSocketFactory factory = sslSocketFactories.getUnchecked(addr); SSLSocket socket = (SSLSocket) factory.createSocket(tSocket.getSocket(), addr.getHostString(), addr.getPort(), true); tSocket = new TSocket(socket); success = true; } catch (IOException e) { throw new TTransportException(e); } finally { if (!success) { tSocket.close(); } } } TTransport tFramedTransport = new TFramedTransport(tSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES); TProtocol protocol = new TBinaryProtocol(tFramedTransport); Cassandra.Client client = new Cassandra.Client(protocol); return client; }
From source file:org.elasticsearch.network.DirectBufferNetworkTests.java
private static HttpRequestBuilder httpClient() { HttpServerTransport httpServerTransport = internalCluster().getDataNodeInstance(HttpServerTransport.class); InetSocketAddress address = ((InetSocketTransportAddress) httpServerTransport.boundAddress() .publishAddress()).address(); return new HttpRequestBuilder(HttpClients.createDefault()).host(address.getHostName()) .port(address.getPort()); }