use of java.net.BindException in project GNS by MobilityFirst.
the class GNSApp method startDNS.
private void startDNS() throws SecurityException, SocketException, UnknownHostException {
try {
if (Config.getGlobalBoolean(GNSConfig.GNSC.DNS_GNS_ONLY)) {
dnsTranslator = new DnsTranslator(Inet4Address.getByName("0.0.0.0"), 53, requestHandler);
dnsTranslator.start();
} else if (Config.getGlobalBoolean(GNSConfig.GNSC.DNS_ONLY)) {
if (Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP) == GNSConfig.NONE) {
GNSConfig.getLogger().severe("FAILED TO START DNS SERVER: GNS Server IP must be specified");
return;
}
GNSConfig.getLogger().info("GNS Server IP" + Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP));
udpDnsServer = new UdpDnsServer(Inet4Address.getByName("0.0.0.0"), 53, Config.getGlobalString(GNSConfig.GNSC.DNS_UPSTREAM_SERVER_IP), Config.getGlobalString(GNSConfig.GNSC.GNS_SERVER_IP), requestHandler);
udpDnsServer.start();
} else {
udpDnsServer = new UdpDnsServer(Inet4Address.getByName("0.0.0.0"), 53, Config.getGlobalString(GNSConfig.GNSC.DNS_UPSTREAM_SERVER_IP), null, requestHandler);
udpDnsServer.start();
}
} catch (BindException e) {
GNSConfig.getLogger().warning("Not running DNS Service because it needs root permission! " + "If you want DNS run the server using sudo.");
}
}
use of java.net.BindException in project GNS by MobilityFirst.
the class GNSHttpsServer method tryPort.
/**
* Try to start the http server at the port.
*
* @param port
* @return true if it was started
*/
@Override
public boolean tryPort(int port) {
try {
InetSocketAddress addr = new InetSocketAddress(port);
httpsServer = HttpsServer.create(addr, 0);
SSLContext sslContext = createSSLContext();
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
@Override
public void configure(HttpsParameters parameters) {
// initialise the SSL context
SSLContext context = getSSLContext();
SSLEngine engine = context.createSSLEngine();
//parameters.setNeedClientAuth(false);
parameters.setCipherSuites(engine.getEnabledCipherSuites());
parameters.setProtocols(engine.getEnabledProtocols());
// get the default parameters
SSLParameters sslParameters = context.getDefaultSSLParameters();
sslParameters.setNeedClientAuth(true);
parameters.setNeedClientAuth(true);
parameters.setSSLParameters(sslParameters);
}
});
httpsServer.createContext("/", new EchoHttpHandler());
httpsServer.createContext("/" + GNS_PATH, new DefaultHttpHandler());
httpsServer.setExecutor(Executors.newCachedThreadPool());
httpsServer.start();
// Need to do this for the places where we expose the secure http service to the user
requestHandler.setHttpsServerPort(port);
LOG.log(Level.INFO, "HTTPS server is listening on port {0}", port);
return true;
} catch (BindException e) {
LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
return false;
} catch (IOException | NoSuchAlgorithmException | KeyStoreException | CertificateException | UnrecoverableKeyException | KeyManagementException e) {
LOG.log(Level.FINE, "HTTPS server failed to start on port {0} due to {1}", new Object[] { port, e.getMessage() });
e.printStackTrace();
return false;
}
}
use of java.net.BindException in project hadoop by apache.
the class DatanodeHttpServer method start.
public void start() throws IOException {
if (httpServer != null) {
InetSocketAddress infoAddr = DataNode.getInfoAddr(conf);
ChannelFuture f = httpServer.bind(infoAddr);
try {
f.syncUninterruptibly();
} catch (Throwable e) {
if (e instanceof BindException) {
throw NetUtils.wrapException(null, 0, infoAddr.getHostName(), infoAddr.getPort(), (SocketException) e);
} else {
throw e;
}
}
httpAddress = (InetSocketAddress) f.channel().localAddress();
LOG.info("Listening HTTP traffic on " + httpAddress);
}
if (httpsServer != null) {
InetSocketAddress secInfoSocAddr = NetUtils.createSocketAddr(conf.getTrimmed(DFS_DATANODE_HTTPS_ADDRESS_KEY, DFS_DATANODE_HTTPS_ADDRESS_DEFAULT));
ChannelFuture f = httpsServer.bind(secInfoSocAddr);
try {
f.syncUninterruptibly();
} catch (Throwable e) {
if (e instanceof BindException) {
throw NetUtils.wrapException(null, 0, secInfoSocAddr.getHostName(), secInfoSocAddr.getPort(), (SocketException) e);
} else {
throw e;
}
}
httpsAddress = (InetSocketAddress) f.channel().localAddress();
LOG.info("Listening HTTPS traffic on " + httpsAddress);
}
}
use of java.net.BindException in project hadoop by apache.
the class TestRefreshCallQueue method setUp.
@Before
public void setUp() throws Exception {
// We want to count additional events, so we reset here
mockQueueConstructions = 0;
mockQueuePuts = 0;
int portRetries = 5;
int nnPort;
for (; portRetries > 0; --portRetries) {
// Pick a random port in the range [30000,60000).
nnPort = 30000 + rand.nextInt(30000);
config = new Configuration();
callQueueConfigKey = "ipc." + nnPort + ".callqueue.impl";
config.setClass(callQueueConfigKey, MockCallQueue.class, BlockingQueue.class);
config.set("hadoop.security.authorization", "true");
FileSystem.setDefaultUri(config, "hdfs://localhost:" + nnPort);
fs = FileSystem.get(config);
try {
cluster = new MiniDFSCluster.Builder(config).nameNodePort(nnPort).build();
cluster.waitActive();
break;
} catch (BindException be) {
// Retry with a different port number.
}
}
if (portRetries == 0) {
// Bail if we get very unlucky with our choice of ports.
fail("Failed to pick an ephemeral port for the NameNode RPC server.");
}
}
use of java.net.BindException in project robovm by robovm.
the class OldSocketTest method test_ConstructorLjava_lang_StringILjava_net_InetAddressI2.
public void test_ConstructorLjava_lang_StringILjava_net_InetAddressI2() throws IOException {
Socket s1 = new Socket("www.google.com", 80, null, 0);
try {
Socket s2 = new Socket("www.google.com", 80, null, s1.getLocalPort());
try {
s2.close();
} catch (IOException ignored) {
}
fail("second connect should have failed with EADDRINUSE");
} catch (BindException expected) {
// success!
} finally {
try {
s1.close();
} catch (IOException ignored) {
}
}
}
Aggregations