List of usage examples for java.net InetSocketAddress getHostString
public final String getHostString()
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 w w . jav a2 s . c om*/ 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:com.vmware.photon.controller.common.thrift.ClientPoolUtils.java
public static <C extends TAsyncClient> C createNewClient(InetSocketAddress address, TProtocolFactory protocolFactory, ClientPoolOptions options, ThriftFactory thriftFactory, TAsyncClientFactory<C> clientFactory, Map<C, TTransport> clientTransportMap) throws IOException, TTransportException { TTransport socket = null;// ww w . ja v a 2 s. c om if (!isKeyStoreUsed(options.getKeyStorePath())) { // Auth is not enabled socket = new TNonblockingSocket(address.getHostString(), address.getPort()); } else { TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters(); params.setTrustStore(options.getKeyStorePath(), options.getKeyStorePassword()); socket = TSSLTransportFactory.getClientSocket(address.getHostString(), address.getPort(), (options.getTimeoutMs() == 0L) ? 10000 : (int) options.getTimeoutMs(), params); } if (StringUtils.isNotBlank(options.getServiceName())) { protocolFactory = thriftFactory.create(options.getServiceName()); } C client = clientFactory.create(protocolFactory, socket); clientTransportMap.put(client, socket); logger.debug("created new client {} for {}", client, address); return client; }
From source file:com.datatorrent.stram.client.StramClientUtils.java
public static String getSocketConnectString(InetSocketAddress socketAddress) { String host;//from w w w.j a v a2 s . c om InetAddress address = socketAddress.getAddress(); if (address == null) { host = socketAddress.getHostString(); } else if (address.isAnyLocalAddress() || address.isLoopbackAddress()) { host = address.getCanonicalHostName(); } else { host = address.getHostName(); } return host + ":" + socketAddress.getPort(); }
From source file:natalia.dymnikova.cluster.scheduler.impl.ConverterAddresses.java
public Address toAkkaAddress(final InetSocketAddress address) { return Address.apply("akka.tcp", actorSystemName, address.getHostString(), address.getPort()); }
From source file:org.elasticsearch.client.RestClientBuilderIntegTests.java
private RestClient buildRestClient() { InetSocketAddress address = httpsServer.getAddress(); return RestClient.builder(new HttpHost(address.getHostString(), address.getPort(), "https")).build(); }
From source file:org.apache.flink.client.CliFrontend.java
/** * Writes the given job manager address to the associated configuration object * * @param address Address to write to the configuration * @param config The config to write to/*from www . java 2s . c o m*/ */ public static void setJobManagerAddressInConfig(Configuration config, InetSocketAddress address) { config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, address.getHostString()); config.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, address.getPort()); }
From source file:nl.esciencecenter.osmium.mac.MacITCase.java
public URI getServerURI() throws URISyntaxException { InetSocketAddress address = server.getServiceAddress(); return new URI("http", null, address.getHostString(), address.getPort(), "/status", null, null); }
From source file:org.apache.flink.client.cli.CliFrontend.java
/** * Writes the given job manager address to the associated configuration object. * * @param address Address to write to the configuration * @param config The configuration to write to *//*from w w w . jav a2 s. c o m*/ static void setJobManagerAddressInConfig(Configuration config, InetSocketAddress address) { config.setString(JobManagerOptions.ADDRESS, address.getHostString()); config.setInteger(JobManagerOptions.PORT, address.getPort()); config.setString(RestOptions.ADDRESS, address.getHostString()); config.setInteger(RestOptions.PORT, address.getPort()); }
From source file:cpcc.com.services.CommunicationServiceTest.java
@BeforeMethod public void setUp() throws Exception { content = null;// ww w . jav a 2 s.c o m throwHttpException = false; handler = mock(HttpRequestHandler.class); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); request = (BasicHttpEntityEnclosingRequest) args[0]; HttpResponse response = (HttpResponse) args[1]; // HttpContext context = (HttpContext) args[2]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(request.getEntity().getContent(), baos); content = baos.toByteArray(); if (throwHttpException) { throw new HttpException("HttpException thrown on purpose!"); } final int statusCode = response.getStatusLine().getStatusCode(); final String reasonPhrase = response.getStatusLine().getReasonPhrase(); final ProtocolVersion protocolVersion = response.getProtocolVersion(); response.setStatusLine(new MyStatusLine(protocolVersion, statusCode, reasonPhrase)); HttpEntity entity = EntityBuilder.create().setContentType(ContentType.TEXT_PLAIN) .setText(REASON_PHRASE).build(); response.setEntity(entity); return null; } }).when(handler).handle(any(HttpRequest.class), any(HttpResponse.class), any(HttpContext.class)); server = new LocalTestServer(null, null); server.register("/*", handler); server.start(); InetSocketAddress addr = server.getServiceAddress(); String serverUrl = "http://" + addr.getHostString() + ":" + addr.getPort(); realVehicle = mock(RealVehicle.class); when(realVehicle.getUrl()).thenReturn(serverUrl + "/rv001"); com = new CommunicationServiceImpl(); }
From source file:org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory.java
private AbstractConnector createConnector(InetSocketAddress address, Server server) { ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors); connector.setHost(address.getHostString()); connector.setPort(address.getPort()); for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) { if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { ((HttpConfiguration.ConnectionFactory) connectionFactory).getHttpConfiguration() .setSendServerVersion(false); }//from www. ja v a 2s .co m } return connector; }