List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:org.qi4j.library.shiro.AbstractServletTestSupport.java
@Before public void before() throws Exception { InetAddress loopback = InetAddress.getLocalHost(); int port = findFreePortOnIfaceWithPreference(loopback, 8989); httpHost = new HttpHost(loopback.getHostAddress(), port); jetty = new Server(port); configureJetty(jetty);/* w w w . j a v a 2 s . c o m*/ ServletContextHandler sch = new ServletContextHandler(jetty, "/", ServletContextHandler.SESSIONS | ServletContextHandler.NO_SECURITY); sch.addEventListener(new AbstractQi4jServletBootstrap() { public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException { ApplicationAssembly app = applicationFactory.newApplicationAssembly(); ModuleAssembly module = app.layer(TEST_LAYER).module(TEST_MODULE); AbstractServletTestSupport.this.assemble(module); return app; } }); sch.addServlet(ServletUsingSecuredService.class, SECURED_SERVLET_PATH); configureServletContext(sch); jetty.start(); }
From source file:UuidUtil.java
/** * Method initInetAddr/* w ww . j a va2 s .c o m*/ * * * @return * * @audience */ private static String initInetAddr() { try { byte[] bytes = InetAddress.getLocalHost().getAddress(); StringBuffer b = new StringBuffer(); String s = null; for (int i = 0; i < bytes.length; i++) { s = Integer.toHexString(bytes[i]); if (bytes[i] < 0) { b.append(s.substring(s.length() - 2)); } else { b.append(s); } } return b.toString(); } catch (Exception ex) { // must return a value return "a48eb993"; // return null; } }
From source file:com.jaspersoft.jasperserver.war.xmla.XmlaServletImpl.java
public void init(ServletConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); // TODO it is meaningless to generate URLs here, but the XMLServlet requires it // Looks like XML/A clients ignore the URL try {//from w w w .ja v a 2s . co m InetAddress local = InetAddress.getLocalHost(); // We can override the default protocol and port with servlet init parameters String defaultProtocol = servletContext.getInitParameter("defaultProtocol"); if (defaultProtocol == null || defaultProtocol.trim().length() == 0) { defaultProtocol = "http"; } String defaultPort = servletContext.getInitParameter("defaultPort"); if (defaultPort == null || defaultPort.trim().length() == 0) { defaultPort = "-1"; } int port = Integer.parseInt(defaultPort); URL root = servletContext.getResource("/"); // Looks like the path will be /localhost/webapp int pastHost = root.getPath().indexOf("/", 1); String path = root.getPath().substring(pastHost, root.getPath().length()); SERVER_URL = (new URL(defaultProtocol, local.getCanonicalHostName(), port, path)).toString() + "xmla"; } catch (Exception e) { throw new RuntimeException(e); } super.init(config); }
From source file:org.alfresco.encryption.DefaultEncryptionUtils.java
public DefaultEncryptionUtils() { try {// w ww .j a va2s . c o m this.localIP = InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { throw new AlfrescoRuntimeException("Unable to initialise EncryptionUtils", e); } }
From source file:me.huzorro.gateway.telnet.TelnetServerHandler.java
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { // Send greeting for a new connection. e.getChannel().write("Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n"); e.getChannel().write("It is " + new Date() + " now.\r\n"); e.getChannel().write("login:"); }
From source file:mitm.common.mail.MessageIDCreator.java
private String getHostname() { String hostname = null;/* w ww .j ava 2 s . c o m*/ InetAddress localHost = null; try { localHost = InetAddress.getLocalHost(); if (localHost != null) { hostname = StringUtils.trimToNull(localHost.getHostName()); } } catch (Exception e) { /* * Can happen if the name of the host is invalid */ logger.debug("Error getting localhost", e); } if (hostname == null) { hostname = "localhost"; } return hostname; }
From source file:com.ikanow.aleph2.logging.utils.LoggingUtils.java
/** Returns the hostname * @return/*from ww w .jav a 2 s . c o m*/ */ public static String getHostname() { try { return InetAddress.getLocalHost().getHostName(); } catch (Exception e) { return "UNKNOWN"; } }
From source file:edu.umd.cs.marmoset.utilities.UptimeDaemon.java
public UptimeDaemon(File outputDir, int port) throws IOException { this.port = port; this.outputDir = outputDir; this.serverSocket = new ServerSocket(this.port); this.hostname = InetAddress.getLocalHost().getHostAddress(); }
From source file:com.cloudera.sqoop.util.DirectImportUtils.java
/** @return true if someHost refers to localhost. *///w ww . j a v a 2 s . com public static boolean isLocalhost(String someHost) { if (null == someHost) { return false; } try { InetAddress localHostAddr = InetAddress.getLocalHost(); InetAddress someAddr = InetAddress.getByName(someHost); return localHostAddr.equals(someAddr); } catch (UnknownHostException uhe) { return false; } }
From source file:com.eternity.common.communication.servlet.AsyncDispatch.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); try {//from w w w . j a va2 s. c o m InetAddress addr = InetAddress.getLocalHost(); hostName = addr.getHostName(); } catch (UnknownHostException e) { log.error("", e); } }