List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:de.avanux.livetracker.mobile.ConfigurationProvider.java
private Properties buildConfiguration() { Properties configuration = new Properties(); configuration.put(ConfigurationConstants.ID, "" + TrackingManager.createTracking().getTrackingID()); configuration.put(ConfigurationConstants.SERVER_API_VERSION, "1"); configuration.put(ConfigurationConstants.MIN_TIME_INTERVAL, "" + Configuration.getInstance().getMinTimeInterval()); configuration.put(ConfigurationConstants.MESSAGE_TO_USERS, Configuration.getInstance().getMessageToUsers()); // FIXME: this is a hack during main development phase to switch easily between development server and deployment server String hostname = null;/*from w w w. j av a 2 s . c o m*/ try { InetAddress addr = InetAddress.getLocalHost(); hostname = addr.getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } if ((hostname != null) && hostname.equals("miraculix")) { configuration.put(ConfigurationConstants.LOCATION_RECEIVER_URL, "http://miraculix.localnet:8080/LiveTrackerServer/LocationReceiver"); } else { configuration.put(ConfigurationConstants.LOCATION_RECEIVER_URL, "http://livetracker.dyndns.org/LocationReceiver"); } return configuration; }
From source file:at.alladin.rmbt.qos.testserver.plugin.rest.RestService.java
@Override public void start() throws UnknownHostException { if (isEnabled) { final boolean isRunning = this.isRunning.getAndSet(true); if (!isRunning) { if (isEnabled && port <= 0) { this.isEnabled = false; TestServerConsole.log(/*from w w w . j av a2 s. c om*/ "Could not start RestService. Parameter missing: 'server.service.rest.port'", 1, TestServerServiceEnum.TEST_SERVER); } Component component = new Component(); Server s = component.getServers().add(isSsl ? Protocol.HTTPS : Protocol.HTTP, InetAddress.getLocalHost().getHostAddress(), port); if (isSsl) { Series<Parameter> parameters = s.getContext().getParameters(); parameters.add("keystorePath", QOS_KEY_FILE_ABSOLUTE); parameters.add("keystorePassword", TestServer.QOS_KEY_PASSWORD); parameters.add("keyPassword", TestServer.QOS_KEY_PASSWORD); parameters.add("keystoreType", TestServer.QOS_KEY_TYPE); } component.getDefaultHost().attach("", new RestletApplication()); try { component.start(); TestServerConsole.log("[" + getName() + "] started: " + toString(), 1, TestServerServiceEnum.TEST_SERVER); } catch (Exception e) { TestServerConsole.error(getName(), e, 0, TestServerServiceEnum.TEST_SERVER); } } } }
From source file:com.vip.saturn.job.console.utils.LocalHostService.java
private static InetAddress getLocalHost() throws UnknownHostException { return InetAddress.getLocalHost(); }
From source file:org.obp.Configuration.java
public String getShortHostInfo() { try {/*from ww w . j a v a 2 s. c om*/ return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "unable to determine host name"; } }
From source file:net.dfs.server.filespace.accessor.impl.WriteSpaceAccessorImpl.java
/** * writeToSPace will write a File object to the newly created local Space. It * makes sure the Space is not null before the File objects are been written to the * Space./*from ww w. j av a 2 s. c om*/ * <p> * It returns no value and throws RemoteException or TransactionException on a failure. * * @param file is an object of the type {@link FileStorageModel} */ public void writeToSpace(FileToken token) { if (space == null) { try { if (space == null) { space = spaceCreator.getSpace(InetAddress.getByName(serverIP), InetAddress.getLocalHost()); } } catch (UnknownHostException e) { e.printStackTrace(); } } try { space.write((FileToken) token, null, Long.MAX_VALUE); log.info("Chunk " + token.fileName + " with Chunk No " + token.CHUNK_NO + " Written to the Space"); } catch (RemoteException e) { e.printStackTrace(); } catch (TransactionException e) { e.printStackTrace(); } }
From source file:BotlistUniqueId.java
public String getUniqueId() { String digest = ""; try {/*w ww.j a v a 2s.co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); String timeVal = "" + (System.currentTimeMillis() + 1); String localHost = ""; ; try { localHost = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e) { // If an error, we can use other values. } String randVal = "" + new Random().nextInt(); String val = timeVal + localHost + randVal; md.reset(); md.update(val.getBytes()); // Generate the digest. digest = toHexString(md.digest()); } catch (NoSuchAlgorithmException e) { } // End of the Try - Catch return digest; }
From source file:ch.qos.logback.audit.client.ImprovedAuditorFactory.java
public static void setApplicationName(String name) throws AuditException { if (clientApplication != null && clientApplication.getName().equals(name)) { // don't configure again return;//from w w w . ja va 2 s . co m } if (clientApplication != null && !clientApplication.getName().equals(name)) { throw new IllegalStateException( "Application name " + clientApplication.getName() + " once set cannot be renamed."); } if (OptionHelper.isEmpty(name)) { throw new IllegalArgumentException("Application name cannot be null or empty"); } else { // logger.info("Naming client application as [" + name + "]"); } try { InetAddress address = InetAddress.getLocalHost(); String fqdn = address.getCanonicalHostName(); // logger("Client application host is ["+fqdn+"]."); Application aplication = new Application(name, fqdn); // all is nice and dandy clientApplication = aplication; } catch (UnknownHostException e) { throw new IllegalStateException("Failed to determine the hostname for this host", e); } // defaultAuditor.close(); defaultAuditor = new Auditor(); defaultAuditor.setClientApplication(clientApplication); defaultAuditor.setName(DEFAULT_AUDITOR_NAME); autoConfig(defaultAuditor); checkSanity(defaultAuditor); AuditorFactory.defaultAuditor = defaultAuditor; }
From source file:se.vgregion.delegation.server.Server.java
private void start() { String path = "classpath:/spring/conf.xml"; ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(path); propertiesBean = (PropertiesBean) ctx.getBean("propertiesBean"); String hostname = "localhost"; try {//from w w w. j a v a2 s . co m hostname = InetAddress.getLocalHost().getHostName(); LOGGER.info("Host namne = " + hostname); } catch (UnknownHostException e) { LOGGER.error("Host namne error ", e); } startServer(ctx, hostname, propertiesBean.getServerPort()); }
From source file:at.ac.tuwien.infosys.Balancer.java
@RequestMapping(value = "/ip", method = RequestMethod.GET) public String getIp() { InetAddress ip;//from w ww.j a v a 2s.c om String hostname; try { ip = InetAddress.getLocalHost(); hostname = ip.getHostName(); return "{\"ip\":\"" + ip + "\", \"hostname\":\"" + hostname + "\"}"; } catch (UnknownHostException e) { e.printStackTrace(); return "Error: " + e.getMessage(); } }