List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.comcast.viper.flume2storm.connection.KryoNetConnectionParametersTest.java
/** * Test {@link KryoNetConnectionParameters} with empty configuration * //from w ww. j a va 2s .c o m * @throws F2SConfigurationException * If the configuration is invalid */ @Test public void testEmpty() throws F2SConfigurationException { KryoNetConnectionParameters params = KryoNetConnectionParameters.from(new BaseConfiguration()); String localAddress; try { localAddress = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { localAddress = KryoNetConnectionParameters.ADDRESS_DEFAULT; } Assert.assertEquals(localAddress, params.getAddress()); Assert.assertEquals(KryoNetConnectionParameters.PORT_DEFAULT, params.getPort()); Assert.assertEquals(KryoNetConnectionParameters.OBJECT_BUFFER_SIZE_DEFAULT, params.getObjectBufferSize()); Assert.assertEquals(KryoNetConnectionParameters.WRITE_BUFFER_SIZE_DEFAULT, params.getWriteBufferSize()); }
From source file:com.jaeksoft.searchlib.util.NetworksUtils.java
public static final String getFirstHardwareAddress() throws URISyntaxException, UnknownHostException, SocketException { InetAddress localhost = InetAddress.getLocalHost(); String hardwareAddress = null; if (localhost != null) hardwareAddress = getHardwareAddress(NetworkInterface.getByInetAddress(localhost)); if (hardwareAddress != null) return hardwareAddress; Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { hardwareAddress = getHardwareAddress(networkInterfaces.nextElement()); if (hardwareAddress != null) return hardwareAddress; }/*www . j ava2 s.com*/ return null; }
From source file:net.dfs.user.connect.impl.StorageConnectionHandlerImpl.java
/** * {@inheritDoc}/*from ww w . ja v a 2 s . c o m*/ * @throws UnknownHostException */ public String storeFile(long FILE_SIZE, String fileName, String ext, String user) throws UnknownHostException { log.debug("The File " + fileName + ext + " With " + FILE_SIZE + " received by " + user); userRegistration.registerUserIP(fileName, user); tokenService.createToken(FILE_SIZE, fileName, ext); return InetAddress.getLocalHost().getHostName(); }
From source file:com.jivesoftware.os.jive.utils.http.client.CustomSecureProtocolSocketFactoryTest.java
@Test public void testCreateSocketWithLocal() throws Exception { customSecureProtocolSocketFactory.createSocket("host", 333, InetAddress.getLocalHost(), 8765); verify(sslSocketFactory).createSocket("host", 333, InetAddress.getLocalHost(), 8765); }
From source file:psiprobe.controllers.DecoratorController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w ww .j ava 2 s .c om*/ request.setAttribute("hostname", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { request.setAttribute("hostname", "unknown"); logger.trace("", e); } Properties version = (Properties) getApplicationContext().getBean("version"); request.setAttribute("version", version.getProperty("probe.version")); long uptimeStartValue = ManagementFactory.getRuntimeMXBean().getStartTime(); long uptime = System.currentTimeMillis() - uptimeStartValue; long uptimeDays = uptime / (1000 * 60 * 60 * 24); uptime = uptime % (1000 * 60 * 60 * 24); long uptimeHours = uptime / (1000 * 60 * 60); uptime = uptime % (1000 * 60 * 60); long uptimeMins = uptime / (1000 * 60); request.setAttribute("uptime_days", uptimeDays); request.setAttribute("uptime_hours", uptimeHours); request.setAttribute("uptime_mins", uptimeMins); // // Work out the language of the interface by matching resource files that we have // to the request locale. // String lang = "en"; for (String fileName : getMessageFileNamesForLocale(request.getLocale())) { if (getServletContext().getResource(fileName + ".properties") != null) { lang = fileName.substring(messagesBasename.length() + 1); break; } } request.setAttribute("lang", lang); return super.handleRequestInternal(request, response); }
From source file:de.grobox.blitzmail.AsyncMailTask.java
@Override protected Boolean doInBackground(Void... params) { // try to get proper hostname and set fake one if failed if (props.getProperty("mail.smtp.localhost", "").equals("android.com")) { String hostname = ""; try {// ww w. j a va 2 s . c o m hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { // do nothing } if (!hostname.equals("localhost")) { props.setProperty("mail.smtp.localhost", hostname); } } MailSender sender = new MailSender(props); try { sender.sendMail(mail.optString("subject"), mail.optString("body"), mail.optString("cc", null), mail.optString("bcc", null)); } catch (Exception e) { Log.d("AsyncMailTask", "ERROR: " + e.getMessage()); // remember exception for when task is finished this.e = e; return false; } return true; }
From source file:net.dfs.user.test.Store.java
public static void store(String file) throws UnknownHostException { File f = new File(file); FILE_SIZE = f.length();// w w w . j ava2s . c o m fileNameAnalyzer(file); StorageConnectionHandler storageHandler = (StorageConnectionHandler) context.getBean("storageHandler"); String serverName = storageHandler.storeFile(FILE_SIZE, fileName, extention, InetAddress.getLocalHost().getHostAddress()); Store.serverName(serverName); log.debug("The File " + fileName + extention + " With " + FILE_SIZE + " size send to the Server"); }
From source file:com.ibm.watson.movieapp.dialog.fvt.config.SetupMethod.java
/** * serverUnderTest() - Check to see if automation is being run via Maven * @return - String containing baseURL to use for testing *///w ww . ja v a 2 s .co m public static String serverUnderTest() { String ipAddress = ""; String baseURL = ""; String server = System.getProperty("app.url"); if (server == null) { baseURL = Utils.readConfigProperty("serverUnderTest"); } else { InetAddress localMachine = null; try { localMachine = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } ipAddress = localMachine.getHostAddress(); baseURL = server.replace("localhost", ipAddress); } return baseURL; }
From source file:com.uber.stream.kafka.mirrormaker.controller.TestControllerConf.java
@Test public void testDefaultControllerConf() throws UnknownHostException { ControllerConf defaultConf = ControllerStarter.getDefaultConf(); Assert.assertEquals(defaultConf.getAutoRebalanceDelayInSeconds().intValue(), 120); Assert.assertEquals(defaultConf.getBackUpToGit().booleanValue(), false); Assert.assertEquals(defaultConf.getLocalBackupFilePath(), "/var/log/kafka-mirror-maker-controller"); Assert.assertEquals(defaultConf.getControllerPort(), "9000"); Assert.assertEquals(defaultConf.getHelixClusterName(), "testMirrorMaker"); Assert.assertEquals(defaultConf.getZkStr(), "localhost:2181"); Assert.assertEquals(defaultConf.getInstanceId(), InetAddress.getLocalHost().getHostName()); Assert.assertEquals(defaultConf.getEnableAutoWhitelist(), false); Assert.assertEquals(defaultConf.getEnableSrcKafkaValidation(), false); }
From source file:com.tesora.dve.common.PatternLayoutWithHeader.java
@Override public String getHeader() { Runtime runtime = Runtime.getRuntime(); StringBuffer header = new StringBuffer(); header.append(StringUtils.repeat("-", 80)); header.append("\nLog Started : ").append(new Date().toString()); header.append("\nBuild Info : ").append(PELogUtils.getBuildVersionString(true)); header.append("\nMemory : max=").append(String.format("%,d", runtime.maxMemory())).append(" total=") .append(String.format("%,d", runtime.totalMemory())).append(" free=") .append(String.format("%,d", runtime.freeMemory())); header.append("\nProcessors : ").append(runtime.availableProcessors()); try {/*w ww . j ava2 s . c o m*/ header.append("\nHost : ").append(InetAddress.getLocalHost()); } catch (UnknownHostException e) { header.append("\nHost : unknown"); } header.append("\n"); return header.toString(); }