List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:org.springframework.cloud.gateway.handler.predicate.RemoteAddrRoutePredicateFactory.java
@Override public Predicate<ServerWebExchange> apply(Config config) { List<IpSubnetFilterRule> sources = convert(config.sources); return exchange -> { InetSocketAddress remoteAddress = config.remoteAddressResolver.resolve(exchange); if (remoteAddress != null && remoteAddress.getAddress() != null) { String hostAddress = remoteAddress.getAddress().getHostAddress(); String host = exchange.getRequest().getURI().getHost(); if (log.isDebugEnabled() && !hostAddress.equals(host)) { log.debug("Remote addresses didn't match " + hostAddress + " != " + host); }// w ww . j a va 2s.c o m for (IpSubnetFilterRule source : sources) { if (source.matches(remoteAddress)) { return true; } } } return false; }; }
From source file:org.elasticsearch.example.SiteContentsIT.java
public void test() throws Exception { TestCluster cluster = cluster();/*from w w w . ja v a2s . c o m*/ assumeTrue( "this test will not work from an IDE unless you pass tests.cluster pointing to a running instance", cluster instanceof ExternalTestCluster); ExternalTestCluster externalCluster = (ExternalTestCluster) cluster; try (CloseableHttpClient httpClient = HttpClients .createMinimal(new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS))) { for (InetSocketAddress address : externalCluster.httpAddresses()) { RestResponse restResponse = new RestResponse( new HttpRequestBuilder(httpClient).host(NetworkAddress.format(address.getAddress())) .port(address.getPort()).path("/_plugin/site-example/").method("GET").execute()); assertEquals(200, restResponse.getStatusCode()); String body = restResponse.getBodyAsString(); assertTrue("unexpected body contents: " + body, body.contains("<body>Page body</body>")); } } }
From source file:com.hortonworks.hbase.replication.bridge.ReplicationBridgeServer.java
/** * Starts a HRegionServer at the default location * * @param conf//ww w. j a va2 s. c om * @throws IOException * @throws InterruptedException * @throws KeeperException * @throws ZkConnectException */ public ReplicationBridgeServer(Configuration conf) throws IOException, InterruptedException, KeeperException { this.conf = conf; // Set how many times to retry talking to another server over HConnection. HConnectionManager.setServerSideHConnectionRetries(this.conf, LOG); // Server to handle client requests. String hostname = conf.get("hbase.regionserver.ipc.address", Strings.domainNamePointerToHostName( DNS.getDefaultHost(conf.get("hbase.regionserver.dns.interface", "default"), conf.get("hbase.regionserver.dns.nameserver", "default")))); port = conf.getInt("hbase.bridge.server.port", BRIDGE_SERVER_PORT); // Creation of a HSA will force a resolve. InetSocketAddress initialIsa = new InetSocketAddress(hostname, port); if (initialIsa.getAddress() == null) { throw new IllegalArgumentException("Failed resolve of " + initialIsa); } this.rpcServer = HBaseRPC.getServer(this, new Class<?>[] { HRegionInterface.class }, initialIsa.getHostName(), // BindAddress is IP we got for this server. initialIsa.getPort(), conf.getInt("hbase.regionserver.handler.count", 10), conf.getInt("hbase.regionserver.metahandler.count", 10), conf.getBoolean("hbase.rpc.verbose", false), conf, HConstants.QOS_THRESHOLD); }
From source file:org.apache.hadoop.mapred.JTAddress.java
/** * Construct an instance from an {@link InetSocketAddress}. * @param address InetSocketAddress of server *//*from www.ja v a2 s.c o m*/ public JTAddress(InetSocketAddress address) { this.address = address; this.stringValue = address.getAddress().getHostName() + ":" + address.getPort(); checkBindAddressCanBeResolved(); }
From source file:org.openspaces.pu.container.jee.jetty.JettyProcessingUnitContainer.java
public JeeServiceDetails getJeeDetails() { String hostAddress = null;/*from w ww. j a v a 2 s . c o m*/ int port = -1; int sslPort = -1; Connector connector = jettyHolder.getServer().getConnectors()[0]; if (connector instanceof NetworkConnector) { NetworkConnector networkConnector = (NetworkConnector) connector; port = networkConnector.getPort(); sslPort = JettyHolder.getConfidentialPort(connector); String host = networkConnector.getHost(); if (host == null) host = SystemInfo.singleton().network().getHostId(); InetSocketAddress addr = host == null ? new InetSocketAddress(port) : new InetSocketAddress(host, port); hostAddress = addr.getAddress().getHostAddress(); } JeeServiceDetails details = new JeeServiceDetails(hostAddress, port, sslPort, webAppContext.getContextPath(), jettyHolder.isSingleInstance(), "jetty", JeeType.JETTY); return details; }
From source file:org.bgp4j.management.web.WebManagementServerTest.java
@Test public void testStartServer() throws Exception { server.setConfiguration(httpServerConfiguration); server.startServer();//from w w w . j a va 2 s.c o m Thread.sleep(1000); InetSocketAddress serverAddress = httpServerConfiguration.getServerConfiguration().getListenAddress(); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://" + serverAddress.getAddress().getHostAddress() + ":" + serverAddress.getPort() + "/rest/ping"); Assert.assertEquals(HttpServletResponse.SC_OK, client.executeMethod(method)); Assert.assertTrue(method.getResponseBodyAsString().startsWith("{ \"Time\":")); server.stopServer(); }
From source file:SyslogHandler.java
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { InetSocketAddress socketAddress = (InetSocketAddress) e.getRemoteAddress(); LogEntry entry = SyslogParser.decode(socketAddress.getAddress().getHostAddress(), (String) e.getMessage()); try {// w w w . j av a 2s .co m index.append(entry); } catch (IOException e1) { e1.printStackTrace(); return; } if (index.channels.size() == 0) { return; } Set<String> tokens = new HashSet<String>(); addTokens(tokens, entry.host); addTokens(tokens, entry.message); JSONObject json = entry.toJSON(); // for (Channel c: index.channels) { // if (c.isWritable()) { // // String queryString = index.queries.get(c); // Set<String> queryTokens = new HashSet<String>(); // addTokens(queryTokens, queryString); // queryTokens.retainAll(tokens); // intersection // // if (queryTokens.size() > 0) { // ChannelFuture future = c.write(ChannelBuffers.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); // future.addListener(ChannelFutureListener.CLOSE); // } // } // } for (Channel c : index.channels) { if (c.isWritable()) { String queryString = index.queries.get(c); ArrayList<LogEntry> result; try { result = index.search(queryString, 1, -1, -1, entry.id, entry.id); } catch (IOException e1) { e1.printStackTrace(); return; } if (result.size() > 0) { ChannelFuture future = c.write(ChannelBuffers.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); future.addListener(ChannelFutureListener.CLOSE); } } } }
From source file:org.bgp4j.management.web.WebManagementServerTest.java
@Test public void testInjectedTestBean() throws Exception { ManagementApplication.addRegisteredSingleton(testResource); server.setConfiguration(httpServerConfiguration); server.startServer();// w w w .j a v a 2 s .co m Thread.sleep(1000); InetSocketAddress serverAddress = httpServerConfiguration.getServerConfiguration().getListenAddress(); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://" + serverAddress.getAddress().getHostAddress() + ":" + serverAddress.getPort() + "/rest/test/bean"); Assert.assertEquals(HttpServletResponse.SC_OK, client.executeMethod(method)); Assert.assertEquals("found", method.getResponseBodyAsString()); server.stopServer(); }
From source file:backup.datanode.DataNodeBackupServicePlugin.java
@Override public void start(Object service) { DataNode datanode = (DataNode) service; Configuration conf = getConf(); RPC.setProtocolEngine(conf, DataNodeBackupRPC.class, WritableRpcEngine.class); // This object is created here so that it's lifecycle follows the datanode try {//from w ww .ja v a2 s . c o m backupProcessor = SingletonManager.getManager(DataNodeBackupProcessor.class).getInstance(datanode, () -> new DataNodeBackupProcessor(conf, datanode)); restoreProcessor = SingletonManager.getManager(DataNodeRestoreProcessor.class).getInstance(datanode, () -> new DataNodeRestoreProcessor(conf, datanode)); DataNodeBackupRPCImpl backupRPCImpl = new DataNodeBackupRPCImpl(backupProcessor, restoreProcessor); InetSocketAddress listenerAddress = datanode.ipcServer.getListenerAddress(); int ipcPort = listenerAddress.getPort(); String bindAddress = listenerAddress.getAddress().getHostAddress(); int port = conf.getInt(DFS_BACKUP_DATANODE_RPC_PORT_KEY, DFS_BACKUP_DATANODE_RPC_PORT_DEFAULT); if (port == 0) { port = ipcPort + 1; } server = new RPC.Builder(conf).setBindAddress(bindAddress).setPort(port).setInstance(backupRPCImpl) .setProtocol(DataNodeBackupRPC.class).build(); ServiceAuthorizationManager serviceAuthorizationManager = server.getServiceAuthorizationManager(); serviceAuthorizationManager.refresh(conf, new BackupPolicyProvider()); server.start(); LOG.info("DataNode Backup RPC listening on {}", port); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.game.cs.core.condenser.steam.servers.SourceServer.java
/** * @author Krisztian_Horvath //from ww w .j a v a 2s. co m * @param inetSocketAddress * @throws SteamCondenserException */ public SourceServer(InetSocketAddress inetSocketAddress) throws SteamCondenserException { super(inetSocketAddress.getAddress(), inetSocketAddress.getPort()); this.inetSocketAddress = inetSocketAddress; }