List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:ch.cyberduck.core.bonjour.LimitedRendezvousListener.java
@Override public void serviceResolved(final String identifier, final Host host) { if (log.isInfoEnabled()) { log.info(String.format("Service resolved with identifier %s with %s", identifier, host)); }/*w w w . j av a2s . co m*/ if (PreferencesFactory.get().getBoolean("rendezvous.loopback.suppress")) { try { if (InetAddress.getByName(host.getHostname()).equals(InetAddress.getLocalHost())) { if (log.isInfoEnabled()) { log.info(String.format("Suppressed Rendezvous notification for %s", host)); } return; } } catch (UnknownHostException e) { //Ignore } } if (this.acquire()) { for (RendezvousListener listener : listeners) { listener.serviceResolved(identifier, host); } } }
From source file:net.dfs.server.main.ServerServicesStarter.java
public static String serverName() { String name = null;//from w w w . ja v a 2s . com try { name = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } return name; }
From source file:io.gravitee.gateway.platforms.jetty.node.JettyNode.java
@Override public String name() { try {// w w w. jav a 2 s . com return InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException e) { LOGGER.info("The local host name could not be resolved into an address", e); return "localhost"; } }
From source file:com.turn.sorcerer.util.email.Emailer.java
private void sendEmail() throws EmailException, UnknownHostException { List<String> addresses = Lists .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins())); logger.info("Sending email to {}", addresses.toString()); Email email = new HtmlEmail(); email.setHostName(ADMIN_EMAIL.getHost()); email.setSocketTimeout(30000); // 30 seconds email.setSocketConnectionTimeout(30000); // 30 seconds for (String address : addresses) { email.addTo(address);//from ww w .j av a 2 s.co m } email.setFrom( SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName()); email.setSubject(title); email.setMsg(body); email.send(); }
From source file:de.hybris.platform.b2b.punchout.services.CXMLBuilder.java
/** * @return the host name or just 'localhost' if not able to determine it *//*from ww w .jav a 2 s. c o m*/ private String findHostName() { try { return InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException e) { return "localhost"; } }
From source file:com.google.api.server.spi.auth.EndpointsPeerAuthenticatorTest.java
@Test public void testAuthenticate_localHost() throws Exception { request.setRemoteAddr(InetAddress.getLocalHost().getHostAddress()); assertTrue(authenticator.authenticate(request)); }
From source file:com.floragunn.searchguard.config.EvaluatorTest.java
@Test public void testEval2() throws IOException, MalformedConfigurationException { final TokenEvaluator te = new TokenEvaluator(new BytesArray(loadFile("ac_rules_1.json"))); Evaluator eval = te.getEvaluator(Lists.<String>newArrayList("public"), Lists.<String>newArrayList(), Lists.<String>newArrayList(), InetAddress.getLocalHost(), new User("test")); Assert.assertTrue(eval.getBypassAll()); Assert.assertFalse(eval.getExecuteAll()); Assert.assertEquals(FilterAction.BYPASS, eval.evaluateFilter("XX", "XX")); try {/*from w w w. j a v a2 s. co m*/ eval = te.getEvaluator(Lists.<String>newArrayList("xxx"), Lists.<String>newArrayList("internal"), Lists.<String>newArrayList(), InetAddress.getLocalHost(), new User("test")); Assert.fail(); } catch (final MalformedConfigurationException e) { //expected } final User user = new User("jacksonm"); user.addRole("ceo"); eval = te.getEvaluator(Lists.<String>newArrayList("xxx"), Lists.<String>newArrayList("internal"), Lists.<String>newArrayList(), InetAddress.getLocalHost(), user); Assert.assertFalse(eval.getBypassAll()); Assert.assertTrue(eval.getExecuteAll()); Assert.assertEquals(FilterAction.EXECUTE, eval.evaluateFilter("XX", "XX")); }
From source file:com.od.jtimeseries.component.AbstractJTimeSeriesComponent.java
private static String getHostname(Class logClass) { String result = "(Unknown Host)"; try {/*from w w w. j a v a 2s.c om*/ result = InetAddress.getLocalHost().getHostName(); int lastPeriod = result.indexOf("."); if (lastPeriod > 0) { result = result.substring(0, lastPeriod); } } catch (UnknownHostException e) { LogUtils.getLogMethods(logClass).error("Failed to find hostname", e); } return result; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.ExceptionHandlingAction.java
private static String getHostName() { try {//w w w. ja va 2 s . co m return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "<Host name unknown>"; } }