List of usage examples for java.net InetAddress getLoopbackAddress
public static InetAddress getLoopbackAddress()
From source file:org.sonar.application.config.JdbcSettingsTest.java
@Test public void resolve_H2_provider_when_props_is_empty_and_set_URL_to_default_H2() { Props props = newProps();/* w w w.j av a2 s . c o m*/ assertThat(underTest.resolveProviderAndEnforceNonnullJdbcUrl(props)).isEqualTo(Provider.H2); assertThat(props.nonNullValue(JDBC_URL)).isEqualTo( String.format("jdbc:h2:tcp://%s:9092/sonar", InetAddress.getLoopbackAddress().getHostAddress())); }
From source file:com.uber.tchannel.ping.PingServer.java
public void run() throws Exception { TChannel tchannel = new TChannel.Builder("ping-server").setServerHost(InetAddress.getLoopbackAddress()) .setServerPort(port).build(); tchannel.makeSubChannel("ping-server").register("ping", new PingRequestHandler()); tchannel.listen().channel().closeFuture().sync(); }
From source file:org.keycloak.testsuite.authorization.AttributeTest.java
@Test public void testManageAttributes() throws ParseException { Map<String, Collection<String>> map = new HashedMap(); map.put("integer", asList("1")); map.put("long", asList("" + Long.MAX_VALUE)); map.put("string", asList("some string")); map.put("date", asList("12/12/2016")); map.put("ip_network_address", asList("127.0.0.1")); map.put("host_network_address", asList("localhost")); map.put("multi_valued", asList("1", "2", "3", "4")); Attributes attributes = Attributes.from(map); map.keySet().forEach(new Consumer<String>() { @Override//from w w w . j av a 2s . c o m public void accept(String name) { assertTrue(attributes.exists(name)); } }); assertFalse(attributes.exists("not_found")); assertTrue(attributes.containsValue("integer", "1")); assertTrue(attributes.containsValue("multi_valued", "3")); assertEquals(1, attributes.getValue("multi_valued").asInt(0)); assertEquals(4, attributes.getValue("multi_valued").asInt(3)); assertEquals(new SimpleDateFormat("dd/MM/yyyy").parse("12/12/2016"), attributes.getValue("date").asDate(0, "dd/MM/yyyy")); assertEquals(InetAddress.getLoopbackAddress(), attributes.getValue("ip_network_address").asInetAddress(0)); assertEquals(InetAddress.getLoopbackAddress(), attributes.getValue("host_network_address").asInetAddress(0)); }
From source file:org.elasticsearch.client.RestClientMultipleHostsIntegTests.java
private static HttpServer createHttpServer() throws Exception { HttpServer httpServer = MockHttpServer .createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); httpServer.start();//from w w w . ja va2 s. co m //returns a different status code depending on the path for (int statusCode : getAllStatusCodes()) { httpServer.createContext(pathPrefix + "/" + statusCode, new ResponseHandler(statusCode)); } return httpServer; }
From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java
@Test(expected = java.io.IOException.class) public void shouldFailCreatingSocketForUnknownHost() throws Exception { // Given/*from w w w .j a v a 2 s. co m*/ String unknownHost = "localhorst"; InetAddress localAddress = InetAddress.getLoopbackAddress(); int localPort = 28080; HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(60000); // When socketFactory.createSocket(unknownHost, 18080, localAddress, localPort, params); // Then = IOException }
From source file:org.sonar.server.platform.db.EmbeddedDatabase.java
private void startServer(File dbHome) { String url = getRequiredSetting(PROP_URL); String port = getRequiredSetting(PROP_EMBEDDED_PORT); String user = getSetting(PROP_USER, PROP_USER_DEFAULT_VALUE); String password = getSetting(PROP_PASSWORD, PROP_PASSWORD_DEFAULT_VALUE); try {/* w w w . jav a 2 s . co m*/ // Db is used only by web server and compute engine. No need // to make it accessible from outside. system2.setProperty("h2.bindAddress", InetAddress.getLoopbackAddress().getHostAddress()); if (url.contains("/mem:")) { server = Server.createTcpServer("-tcpPort", port, "-baseDir", dbHome.getAbsolutePath()); } else { createDatabase(dbHome, user, password); server = Server.createTcpServer("-tcpPort", port, "-ifExists", "-baseDir", dbHome.getAbsolutePath()); } LOG.info("Starting embedded database on port " + server.getPort() + " with url " + url); server.start(); LOG.info("Embedded database started. Data stored in: " + dbHome.getAbsolutePath()); } catch (SQLException e) { throw new IllegalStateException("Unable to start database", e); } }
From source file:org.opendaylight.infrautils.diagstatus.ClusterMemberInfoProvider.java
public static boolean isLocalIPAddress(String ipAddress) { return ipAddress.equals(InetAddress.getLoopbackAddress().getHostAddress()); }
From source file:org.sonar.ce.container.ComputeEngineContainerImplTest.java
@Test public void real_start_with_cluster() throws IOException { int port = NetworkUtils.getNextAvailablePort(InetAddress.getLoopbackAddress()); HazelcastInstance hzInstance = HazelcastTestHelper.createHazelcastCluster(CLUSTER_NAME, port); Properties properties = getProperties(); properties.setProperty(ProcessProperties.CLUSTER_ENABLED, "true"); properties.setProperty(ProcessProperties.CLUSTER_LOCALENDPOINT, String.format("%s:%d", hzInstance.getCluster().getLocalMember().getAddress().getHost(), port)); properties.setProperty(ProcessProperties.CLUSTER_NAME, CLUSTER_NAME); // required persisted properties insertProperty(CoreProperties.SERVER_ID, "a_startup_id"); insertProperty(CoreProperties.SERVER_STARTTIME, DateUtils.formatDateTime(new Date())); underTest.start(new Props(properties)); MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer(); assertThat(picoContainer.getComponentAdapters().stream().map(ComponentAdapter::getComponentImplementation) .collect(Collectors.toList())).contains((Class) HazelcastClientWrapperImpl.class, (Class) CeDistributedInformationImpl.class); underTest.stop();/* w w w . j av a 2s. com*/ }
From source file:org.elasticsearch.discovery.ec2.Ec2DiscoveryClusterFormationTests.java
/** * Creates mock EC2 endpoint providing the list of started nodes to the DescribeInstances API call *//* ww w . jav a2s. c om*/ @BeforeClass public static void startHttpd() throws Exception { logDir = createTempDir(); httpServer = MockHttpServer .createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0), 0); httpServer.createContext("/", (s) -> { Headers headers = s.getResponseHeaders(); headers.add("Content-Type", "text/xml; charset=UTF-8"); String action = null; for (NameValuePair parse : URLEncodedUtils.parse(IOUtils.toString(s.getRequestBody()), StandardCharsets.UTF_8)) { if ("Action".equals(parse.getName())) { action = parse.getValue(); break; } } assertThat(action, equalTo("DescribeInstances")); XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory(); xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); StringWriter out = new StringWriter(); XMLStreamWriter sw; try { sw = xmlOutputFactory.createXMLStreamWriter(out); sw.writeStartDocument(); String namespace = "http://ec2.amazonaws.com/doc/2013-02-01/"; sw.setDefaultNamespace(namespace); sw.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "DescribeInstancesResponse", namespace); { sw.writeStartElement("requestId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("reservationSet"); { Path[] files = FileSystemUtils.files(logDir); for (int i = 0; i < files.length; i++) { Path resolve = files[i].resolve("transport.ports"); if (Files.exists(resolve)) { List<String> addresses = Files.readAllLines(resolve); Collections.shuffle(addresses, random()); sw.writeStartElement("item"); { sw.writeStartElement("reservationId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instancesSet"); { sw.writeStartElement("item"); { sw.writeStartElement("instanceId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("imageId"); sw.writeCharacters(UUID.randomUUID().toString()); sw.writeEndElement(); sw.writeStartElement("instanceState"); { sw.writeStartElement("code"); sw.writeCharacters("16"); sw.writeEndElement(); sw.writeStartElement("name"); sw.writeCharacters("running"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateDnsName"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("dnsName"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("instanceType"); sw.writeCharacters("m1.medium"); sw.writeEndElement(); sw.writeStartElement("placement"); { sw.writeStartElement("availabilityZone"); sw.writeCharacters("use-east-1e"); sw.writeEndElement(); sw.writeEmptyElement("groupName"); sw.writeStartElement("tenancy"); sw.writeCharacters("default"); sw.writeEndElement(); } sw.writeEndElement(); sw.writeStartElement("privateIpAddress"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); sw.writeStartElement("ipAddress"); sw.writeCharacters(addresses.get(0)); sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); } } } sw.writeEndElement(); } sw.writeEndElement(); sw.writeEndDocument(); sw.flush(); final byte[] responseAsBytes = out.toString().getBytes(StandardCharsets.UTF_8); s.sendResponseHeaders(200, responseAsBytes.length); OutputStream responseBody = s.getResponseBody(); responseBody.write(responseAsBytes); responseBody.close(); } catch (XMLStreamException e) { Loggers.getLogger(Ec2DiscoveryClusterFormationTests.class).error("Failed serializing XML", e); throw new RuntimeException(e); } }); httpServer.start(); }
From source file:org.apache.bookkeeper.util.LocalBookKeeper.java
/** * @param args/* w w w .ja va2 s . c om*/ */ private void runZookeeper(int maxCC) throws IOException { // create a ZooKeeper server(dataDir, dataLogDir, port) LOG.info("Starting ZK server"); //ServerStats.registerAsConcrete(); //ClientBase.setupTestEnv(); ZkTmpDir = IOUtils.createTempDir("zookeeper", "localbookkeeper"); InetAddress loopbackIP = InetAddress.getLoopbackAddress(); try { zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME); serverFactory = new NIOServerCnxnFactory(); LOG.info("Starting Zookeeper server at " + loopbackIP.getHostAddress() + " port:" + ZooKeeperDefaultPort); serverFactory.configure(new InetSocketAddress(loopbackIP, ZooKeeperDefaultPort), maxCC); serverFactory.startup(zks); } catch (Exception e) { // TODO Auto-generated catch block LOG.error("Exception while instantiating ZooKeeper", e); } boolean b = waitForServerUp(loopbackIP.getHostAddress() + ":" + ZooKeeperDefaultPort, CONNECTION_TIMEOUT); LOG.debug("ZooKeeper server up: {}", b); }