Example usage for java.net InetAddress getLocalHost

List of usage examples for java.net InetAddress getLocalHost

Introduction

In this page you can find the example usage for java.net InetAddress getLocalHost.

Prototype

public static InetAddress getLocalHost() throws UnknownHostException 

Source Link

Document

Returns the address of the local host.

Usage

From source file:com.huateng.ebank.business.pageqryexp.action.FileDownloadAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    File file = null;//from  www . j a v  a2  s  . c  om
    try {
        //?GlobalInfo
        this.init(request);
        String downloadInfo = request.getParameter("downloadinfo");
        downloadInfo = Code.decode(downloadInfo);
        String[] filedesc = downloadInfo.split("[|]");
        String displayName = filedesc[0];
        String absoluteFile = filedesc[1];
        String ext = absoluteFile.substring(absoluteFile.lastIndexOf("."));

        file = new File(absoluteFile);
        //mod by zhaozhiguo ?,Ftp? begin
        String ftpFlag = null;
        try {
            ftpFlag = ConfigReader.getProperty("PageQryExp_FTP");
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!file.exists() && "ON".equalsIgnoreCase(ftpFlag)) {
            log.info("FileDownload [" + absoluteFile + "] not exist");
            log.info("Ftp recevie from another machine begin");
            String[] ftpurl = ConfigReader.getProperty("PageQryExp_" + InetAddress.getLocalHost().getHostName())
                    .split(":");
            FtpUtil ftp = new FtpUtil(ftpurl[2], Integer.valueOf(ftpurl[3]), ftpurl[0], ftpurl[1]);
            ftp.connectServer(ext.toUpperCase().endsWith("CSV") ? FTP.ASCII_FILE_TYPE : FTP.BINARY_FILE_TYPE);
            ftp.downloadFile(absoluteFile, absoluteFile);
            ftp.closeServer();
            log.info("Ftp recevie from another machine end");
        }
        //mod by zhaozhiguo ?,Ftp? end
        WebDownloadFile.downloadFile(response, file, displayName + ext);
    } catch (Exception e) {
        log.error(e);
        String errmsg = Code.encode("!");
        response.getWriter().write("<script>alert('download failed!');</script>");
    } finally {

    }
    return null;
}

From source file:com.noterik.bart.fs.fscommand.dynamic.presentation.playout.cache.java

public static void init() {

    readCacheConfig();//from www  .  j  ava  2s . c om

    if (receiver == null) {
        started = true;
        receiver = new CacheMulticastReceiver("receiver");
        receiver.start();
        cachereader = new CacheTableReader("cachereader");
        cachereader.start();
        cachewriter = new CacheTableWriter("cachewriter", cachereader);
        cachewriter.start();
    }
    try {
        InetAddress mip = InetAddress.getLocalHost();
        String myip = "" + mip.getHostAddress();
        String sends = myip + ":" + LazyHomer.getSmithersPort() + ":" + LazyHomer.getPort() + ":"
                + LazyHomer.getRole();
        CacheMulticastSender.send(sends, "INFO", "ALIVE");
    } catch (Exception e) {
        System.out.println("Exception =" + e.getMessage());
    }
}

From source file:com.netflix.genie.web.configs.aws.AwsMvcConfig.java

/**
 * Create an instance of {@link GenieHostInfo} using the EC2 metadata service as we're deployed in an AWS cloud
 * environment./*from  ww  w .  j av a 2s .  c o m*/
 *
 * @return The {@link GenieHostInfo} instance
 * @throws UnknownHostException If all EC2 host instance calculation AND local resolution can't determine a hostname
 * @throws IllegalStateException If an instance can't be created
 */
@Bean
public GenieHostInfo genieHostInfo() throws UnknownHostException {
    final String ec2LocalHostName = EC2MetadataUtils.getLocalHostName();
    if (StringUtils.isNotBlank(ec2LocalHostName)) {
        return new GenieHostInfo(ec2LocalHostName);
    }

    final String ec2Ipv4Address = EC2MetadataUtils.getPrivateIpAddress();
    if (StringUtils.isNotBlank(ec2Ipv4Address)) {
        return new GenieHostInfo(ec2Ipv4Address);
    }

    final String localHostname = InetAddress.getLocalHost().getCanonicalHostName();
    if (StringUtils.isNotBlank(localHostname)) {
        return new GenieHostInfo(localHostname);
    }

    throw new IllegalStateException("Unable to resolve Genie host info");
}

From source file:com.paxxis.cornerstone.service.spring.CornerstoneService.java

/**
 * Initializes the main service object.//from w w w .  j a v  a2s.c om
 */
public void initialize() {
    super.initialize();

    // we must have a display name
    if (serviceInstance.getDisplayName() == null) {
        throw new RuntimeException("displayName cannot be null.");
    }

    try {
        serviceInstance.setHostName(InetAddress.getLocalHost().getCanonicalHostName());
    } catch (UnknownHostException e) {
        serviceInstance.setHostName("UNKNOWN");
    }

    serviceInstance.setInstanceId(InstanceId.create(UUID.randomUUID().toString()));
    serviceInstance.setStartTime(new Date());

    _logger.info("Initializing " + toString());

}

From source file:com.fusesource.forge.jmstest.executor.BenchmarkClient.java

public BenchmarkClientInfoCommand getClientInfo() {
    if (clientInfo == null) {
        clientInfo = new BenchmarkClientInfoCommand();
        try {//w  w  w . j av a2 s  .  co  m
            clientInfo.setClientName("bmClient-" + InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException e) {
            clientInfo.setClientName("bmClient-UnknownHost");
        }
    }
    return clientInfo;
}

From source file:com.collabnet.tracker.common.httpClient.TrackerHttpSender.java

public static void setupHttpClient(HttpClient client, String repositoryUrl, String user, String password) {

    setupHttpClientParams(client, null);

    if (user != null && password != null) {
        AuthScope authScope = new AuthScope(getDomain(repositoryUrl), getPort(repositoryUrl),
                AuthScope.ANY_REALM);//from   w w w  .j a v a  2 s.c o  m
        try {
            client.getState().setCredentials(authScope,
                    getCredentials(user, password, InetAddress.getLocalHost()));
        } catch (UnknownHostException e) {
            client.getState().setCredentials(authScope, getCredentials(user, password, null));
        }
    }

    if (isRepositoryHttps(repositoryUrl)) {
        Protocol acceptAllSsl = new Protocol("https",
                (ProtocolSocketFactory) SslProtocolSocketFactory.getInstance(), getPort(repositoryUrl));
        client.getHostConfiguration().setHost(getDomain(repositoryUrl), getPort(repositoryUrl), acceptAllSsl);
        Protocol.registerProtocol("https", acceptAllSsl);
    } else {
        client.getHostConfiguration().setHost(getDomain(repositoryUrl), getPort(repositoryUrl));
    }
}

From source file:info.debatty.jinu.CaseResult.java

/**
 * Initialize the case result./*from   w  ww  .  ja v  a2s.  c  o  m*/
 */
public CaseResult() {
    try {
        this.hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ex) {
        this.hostname = "Unknown";
    }

    this.processors = Runtime.getRuntime().availableProcessors();
    this.memory = Runtime.getRuntime().maxMemory();
    this.time = System.currentTimeMillis();
    this.sources = new HashMap<TestInterface, String>();

    String classpath_string = ManagementFactory.getRuntimeMXBean().getSystemProperties().get(CLASSPATH_KEY);
    this.classpath = classpath_string.split(":");
}

From source file:io.cloudslang.worker.management.WorkerRegistration.java

protected String getLocalHostName() {
    String hostName = StringUtils.EMPTY;
    try {/*from w w w.  ja v a2 s  .  c  om*/
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        // on Mac OS X with Java 7 calling 'getLocalHost()' can throw UnknownHostException
        // see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7180557
    }
    return hostName;
}

From source file:org.pentaho.reporting.designer.core.auth.AuthenticationHelper.java

public static Credentials getCredentials(final String url, final AuthenticationStore store) {
    final String user = store.getUsername(url);
    if (user == null) {
        return null;
    }//from ww w  .  ja va2s.co  m

    final String password = store.getPassword(url);

    final Configuration config = ReportDesignerBoot.getInstance().getGlobalConfig();
    if ("true".equals(config.getConfigProperty(NT_AUTH_CONFIGKEY, "false")) == false) {
        return new UsernamePasswordCredentials(user, password);
    }

    final int domainIdx = user.indexOf(DOMAIN_SEPARATOR);
    if (domainIdx == -1) {
        return new UsernamePasswordCredentials(user, password);
    }
    try {
        final String domain = user.substring(0, domainIdx);
        final String username = user.substring(domainIdx + 1);
        final String host = InetAddress.getLocalHost().getHostName();
        return new NTCredentials(username, password, host, domain);
    } catch (UnknownHostException uhe) {
        return new UsernamePasswordCredentials(user, password);
    }
}

From source file:com.bleum.canton.loadpage.LoadPage.java

private void logLocalIp(PrintWriter writer) {
    InetAddress addr;/*from w ww  . ja  va 2  s.co  m*/
    try {
        addr = InetAddress.getLocalHost();
        String ip = addr.getHostAddress();
        LOGGER.info("IP address of localhost is: " + ip);
        ip = getWebIp("http://checkip.amazonaws.com/");
        LOGGER.info("External ip address of " + ip);
        writer.print(ip + CSV_SEPERATOR);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
    }

}