List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.netscape.cmstools.cli.MainCLI.java
public void createOptions() throws UnknownHostException { Option option = new Option("U", true, "Server URL"); option.setArgName("uri"); options.addOption(option);//ww w. j a v a2 s. co m option = new Option("P", true, "Protocol (default: http)"); option.setArgName("protocol"); options.addOption(option); option = new Option("h", true, "Hostname (default: " + InetAddress.getLocalHost().getCanonicalHostName() + ")"); option.setArgName("hostname"); options.addOption(option); option = new Option("p", true, "Port (default: 8080)"); option.setArgName("port"); options.addOption(option); option = new Option("t", true, "Subsystem type (deprecated)"); option.setArgName("type"); options.addOption(option); option = new Option("d", true, "NSS database location (default: ~/.dogtag/nssdb)"); option.setArgName("database"); options.addOption(option); option = new Option("c", true, "NSS database password (mutually exclusive to -C and -f options)"); option.setArgName("password"); options.addOption(option); option = new Option("C", true, "NSS database password file (mutually exclusive to -c and -f options)"); option.setArgName("password file"); options.addOption(option); option = new Option("f", true, "NSS database password configuration (mutually exclusive to -c and -C options)"); option.setArgName("password config"); options.addOption(option); option = new Option("n", true, "Nickname for client certificate authentication (mutually exclusive to -u option)"); option.setArgName("nickname"); options.addOption(option); option = new Option("u", true, "Username for basic authentication (mutually exclusive to -n option)"); option.setArgName("username"); options.addOption(option); option = new Option("w", true, "Password for basic authentication (mutually exclusive to -W option)"); option.setArgName("password"); options.addOption(option); option = new Option("W", true, "Password file for basic authentication (mutually exclusive to -w option)"); option.setArgName("passwordfile"); options.addOption(option); option = new Option(null, "token", true, "Security token name"); option.setArgName("token"); options.addOption(option); option = new Option(null, "output", true, "Folder to store HTTP messages"); option.setArgName("folder"); options.addOption(option); option = new Option(null, "reject-cert-status", true, "Comma-separated list of rejected certificate validity statuses"); option.setArgName("list"); options.addOption(option); option = new Option(null, "ignore-cert-status", true, "Comma-separated list of ignored certificate validity statuses"); option.setArgName("list"); options.addOption(option); option = new Option(null, "ignore-banner", false, "Ignore access banner"); options.addOption(option); option = new Option(null, "message-format", true, "Message format: xml (default), json"); option.setArgName("format"); options.addOption(option); options.addOption("v", "verbose", false, "Run in verbose mode."); options.addOption(null, "help", false, "Show help message."); options.addOption(null, "version", false, "Show version number."); }
From source file:esg.gateway.service.ESGGatewayServiceImpl.java
public void register(ESGRemoteEvent evt) { log.trace("Gateway service got \"register\" call from datanode with event: [" + evt + "]"); //Triage incoming revent... if (evt.getMessageType() != ESGRemoteEvent.REGISTER) { log.trace("Registration called with wrong event type... dropping on floor..."); return;/*w ww . j a v a 2s . c om*/ } //Create the string for *our* callback address... String myLocation = null; try { myLocation = "http://" + InetAddress.getLocalHost().getCanonicalHostName() + "/esg-node/gateway"; } catch (java.net.UnknownHostException ex) { log.error("Could not build proper location string for myself", ex); } //Create proxy endpoint for data node service that sent us this event. try { datanodeService = (ESGDataNodeService) factory.create(ESGDataNodeService.class, evt.getSource()); } catch (MalformedURLException ex) { log.warn("Could not connect to serviceURL [" + evt.getSource() + "]", ex); } //Assemble info to create an event and send it to data node in response to this 'register' call. try { ESGRemoteEvent registrationResponseEvent = new ESGRemoteEvent(myLocation, ESGRemoteEvent.REGISTER, Utils.nextSeq()); log.trace("Completing Registration By Making Remote Call to \"notify\" method, sending: " + registrationResponseEvent); //Since no longer as of 2011-04-25 supporting notify method on the datanode service... //if(datanodeService.notify(registrationResponseEvent)) //log.trace("Registration Request Successfully Submitted..."); //else log.trace("Registration Request Rejected"); } catch (HessianRuntimeException ex) { log.error("Problem calling \"register\" on [" + evt.getSource() + "] " + ex.getMessage()); } }
From source file:com.kylinolap.rest.service.BasicService.java
public JobManager getJobManager() throws JobException, UnknownHostException { KylinConfig config = KylinConfig.getInstanceFromEnv(); JobEngineConfig engineCntx = new JobEngineConfig(config); InetAddress ia = InetAddress.getLocalHost(); return new JobManager(ia.getCanonicalHostName(), engineCntx); }
From source file:it.unibo.arces.wot.sepa.engine.protocol.HTTPGate.java
@Override public void start() { this.setName("Starting..."); SEPABeans.registerMBean(mBeanName, this); try {/*from w w w .ja v a 2 s. c o m*/ updateServer = HttpServer.create(new InetSocketAddress(properties.getUpdatePort()), 0); if (properties.getQueryPort() != properties.getUpdatePort()) queryServer = HttpServer.create(new InetSocketAddress(properties.getQueryPort()), 0); else queryServer = updateServer; } catch (IOException e) { logger.fatal(e.getMessage()); System.exit(1); } updateServer.createContext(properties.getUpdatePath(), new SPARQLHandler()); updateServer.createContext("/echo", new EchoHandler()); updateServer.setExecutor(null); updateServer.start(); if (queryServer != updateServer) { queryServer.createContext(properties.getQueryPath(), new SPARQLHandler()); queryServer.createContext("/echo", new EchoHandler()); queryServer.setExecutor(null); queryServer.start(); } logger.info("HTTP gate started"); String host = "localhost"; try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { logger.warn(e.getMessage()); } logger.info("Listening for SPARQL UPDATES on https://" + host + ":" + properties.getUpdatePort() + properties.getUpdatePath()); logger.info("Listening for SPARQL QUERIES on https://" + host + ":" + properties.getQueryPort() + properties.getQueryPath()); }
From source file:ffx.Main.java
/** * Determine the host name, process ID, and FFX base directory. *//*from w w w.ja v a 2 s .c om*/ private static void environment() { try { InetAddress addr = InetAddress.getLocalHost(); hostName = addr.getHostName(); } catch (UnknownHostException e) { // Do nothing. } String procString = System.getProperty("app.pid"); if (procString != null) { procID = Integer.parseInt(procString); } else { procID = 0; } String dirString = System.getProperty("basedir"); if (dirString != null) { ffxDirectory = new File(dirString); } else { ffxDirectory = new File("."); } try { logger.fine(String.format(" Force Field X directory is %s", ffxDirectory.getCanonicalPath())); } catch (Exception e) { // Do Nothing. } }
From source file:se.crisp.codekvast.agent.daemon.worker.impl.ScpFileUploaderImpl.java
private void doValidateUploadConfig() throws IOException { String tmpFile = getUploadTargetFile( InetAddress.getLocalHost().getHostName() + "-" + UUID.randomUUID().toString() + ".tmp"); String remoteCommand = String.format("mkdir -p %1$s && touch %2$s && rm %2$s", config.getUploadToPath(), tmpFile);/*from www .j a v a 2 s . c o m*/ log.debug("Validating upload config by attempting to execute '{}' on {}:{}...", remoteCommand, config.getUploadToHost(), config.getUploadToPort()); SSHClient sshClient = createAuthenticatedSshClient(); try (Session session = sshClient.startSession()) { Session.Command command = session.exec(remoteCommand); command.join(10, TimeUnit.SECONDS); String errorMessage = ofNullable(command.getExitErrorMessage()).orElse(""); int exitStatus = ofNullable(command.getExitStatus()).orElse(0); if (exitStatus != 0 || !errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) { errorMessage = ": " + errorMessage; } throw new IOException(String.format("Failed to execute '%s': [exitCode=%d]%s", remoteCommand, exitStatus, errorMessage)); } } finally { sshClient.disconnect(); } }
From source file:com.edmunds.etm.agent.impl.AgentReporter.java
private static String getIpAddress() { try {// ww w . j av a 2 s . c o m return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { String message = "Could not get IP address for localhost"; logger.error(message, e); throw new RuntimeException(e); } }
From source file:de.codecentric.boot.admin.config.AdminClientProperties.java
private InetAddress getHostAddress() { try {//from w w w . j a v a 2s . c o m return InetAddress.getLocalHost(); } catch (UnknownHostException ex) { throw new IllegalArgumentException(ex.getMessage(), ex); } }
From source file:com.buaa.cfs.utils.SecurityUtil.java
static String getLocalHostName() throws UnknownHostException { return InetAddress.getLocalHost().getCanonicalHostName(); }
From source file:io.gravitee.gateway.services.monitoring.MonitoringService.java
private InstanceEventPayload createInstanceInfo() { InstanceEventPayload instanceInfo = new InstanceEventPayload(); instanceInfo.setId(node.id());//from w w w . ja v a 2s . c om instanceInfo.setVersion(Version.RUNTIME_VERSION.toString()); Optional<List<String>> shardingTags = gatewayConfiguration.shardingTags(); instanceInfo.setTags(shardingTags.isPresent() ? shardingTags.get() : null); instanceInfo.setPlugins(plugins()); instanceInfo.setSystemProperties(new HashMap<>((Map) System.getProperties())); instanceInfo.setPort(port); Optional<String> tenant = gatewayConfiguration.tenant(); instanceInfo.setTenant(tenant.isPresent() ? tenant.get() : null); try { instanceInfo.setHostname(InetAddress.getLocalHost().getHostName()); instanceInfo.setIp(InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException uhe) { LOGGER.warn("Could not get hostname / IP", uhe); } return instanceInfo; }