List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.apress.progwt.server.util.HostPrecedingPropertyPlaceholderConfigurer.java
public String resolvePlaceholder(String placeholder, Properties props) { try {/*from ww w.j a va 2 s . c o m*/ if (placeholder.startsWith("HOST.")) { log.debug("Host: " + InetAddress.getLocalHost().getHostName() + " for property " + placeholder); String replace = placeholder.replaceFirst("HOST", InetAddress.getLocalHost().getHostName()); String prop = props.getProperty(replace); if (prop == null) { log.warn("Please define property: " + replace); } return prop; } else { log.debug("reg"); return props.getProperty(placeholder); } } catch (UnknownHostException e) { log.warn(e); return null; } }
From source file:com.ts.pm.PmDatabase.java
private String resolveServerNameToIp(String server) { if (SystemUtils.IS_OS_WINDOWS) { try {/* w w w .j ava 2 s . com*/ String hostAddress = InetAddress.getLocalHost().getHostAddress(); NbtAddress[] addresses = NbtAddress.getAllByAddress(hostAddress); for (NbtAddress nbtAddr : addresses) { if (nbtAddr.firstCalledName().equals(server)) { return "localhost"; } } return NbtAddress.getByName(server).getInetAddress().getHostAddress(); } catch (UnknownHostException e) { throw new RuntimeException(e); } } return ""; }
From source file:io.gravitee.management.service.impl.EventServiceImpl.java
@Override public EventEntity create(NewEventEntity newEventEntity) { String hostAddress = ""; try {// www .jav a2s . c o m hostAddress = InetAddress.getLocalHost().getHostAddress(); LOGGER.debug("Create {} for server {}", newEventEntity, hostAddress); Event event = convert(newEventEntity); // Set origin event.getProperties().put(Event.EventProperties.ORIGIN.getValue(), hostAddress); // Set date fields event.setCreatedAt(new Date()); event.setUpdatedAt(event.getCreatedAt()); Event createdEvent = eventRepository.create(event); return convert(createdEvent); } catch (UnknownHostException e) { LOGGER.error("An error occurs while getting the server IP address", e); throw new TechnicalManagementException("An error occurs while getting the server IP address", e); } catch (TechnicalException ex) { LOGGER.error("An error occurs while trying to create {} for server {}", newEventEntity, hostAddress, ex); throw new TechnicalManagementException( "An error occurs while trying create " + newEventEntity + " for server " + hostAddress, ex); } }
From source file:com.comcast.viper.flume2storm.connection.parameters.KryoNetConnectionParameters.java
/** * @param config//from ww w. ja v a2 s .c o m * The configuration to use * @return The newly constructed {@link KryoNetConnectionParameters} based on * the {@link Configuration} specified * @throws F2SConfigurationException * If the configuration specified is invalid */ public static KryoNetConnectionParameters from(Configuration config) throws F2SConfigurationException { KryoNetConnectionParameters result = new KryoNetConnectionParameters(); try { String hostname = config.getString(ADDRESS); if (hostname == null) { try { hostname = InetAddress.getLocalHost().getHostAddress(); } catch (final UnknownHostException e) { hostname = ADDRESS_DEFAULT; } } assert hostname != null; result.setAddress(hostname); } catch (Exception e) { throw F2SConfigurationException.with(config, ADDRESS, e); } try { result.setServerPort(config.getInt(PORT, PORT_DEFAULT)); } catch (Exception e) { throw F2SConfigurationException.with(config, PORT, e); } try { result.setObjectBufferSize(config.getInt(OBJECT_BUFFER_SZ, OBJECT_BUFFER_SIZE_DEFAULT)); } catch (Exception e) { throw F2SConfigurationException.with(config, OBJECT_BUFFER_SZ, e); } try { result.setWriteBufferSize(config.getInt(WRITE_BUFFER_SZ, WRITE_BUFFER_SIZE_DEFAULT)); } catch (Exception e) { throw F2SConfigurationException.with(config, WRITE_BUFFER_SZ, e); } return result; }
From source file:edu.duke.cabig.c3pr.webservice.integration.SubjectRegistryWebServicePerformanceTest.java
@Override protected void setUp() throws Exception { if (noEmbeddedTomcat) { endpointURL = new URL("https://localhost:8443/c3pr/services/services/SubjectRegistry"); controller = new Controller("localhost", 10001); initDataSourceFile();/* www.ja v a 2s . c o m*/ } else { super.setUp(); endpointURL = new URL("https://" + InetAddress.getLocalHost().getHostName() + ":" + sslPort + C3PR_CONTEXT + WS_ENDPOINT_SERVLET_PATH); controller = new Controller(InetAddress.getLocalHost().getHostName(), 10001); } wsdlLocation = new URL(endpointURL.toString() + "?wsdl"); logger.info("endpointURL: " + endpointURL); logger.info("wsdlLocation: " + wsdlLocation); }
From source file:com.groupon.deployment.fleet.Sequential.java
/** * Public constructor./*w w w .j av a2s . c o m*/ * * @param hostDeploymentFactory a factory to create a host deployment * @param dcf deployment client factory * @param sshFactory ssh session factory * @param deployment deployment to run */ @AssistedInject public Sequential(final HostDeploymentFactory hostDeploymentFactory, final DeploymentClientFactory dcf, final SshSessionFactory sshFactory, @Assisted final Deployment deployment) { _hostDeploymentFactory = hostDeploymentFactory; _dcf = dcf; _sshFactory = sshFactory; _deployment = Deployment.getById(deployment.getId()); // Refresh the deployment final String myName; try { myName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (final UnknownHostException e) { throw Throwables.propagate(e); } // If this host no longer owns the deployment, die if (!myName.equals(_deployment.getDeploymentOwner())) { Logger.warn(String.format( "Current server does not own the deployment, aborting deploy on this server; owner=%s", _deployment.getDeploymentOwner())); self().tell(PoisonPill.getInstance(), self()); } Logger.info("Sequential fleet deployment actor started up"); final List<HostDeployment> hosts = Lists.newArrayList(); deployment.getHostStates().forEach(host -> { final DeploymentState hostState = host.getState(); if (host.getFinished() == null || hostState == null || (hostState != DeploymentState.FAILED && hostState != DeploymentState.SUCCEEDED)) { hosts.add(host); } }); // Sort the hosts with the following rules: // TODO(barp): 1) hosts that are "down" should be deployed first [Artemis-?] // 2) if the current machine is in the list, it should be last hosts.sort((a, b) -> { if (a.getHost().getName().equals(myName)) { return 1; } if (b.getHost().getName().equals(myName)) { return -1; } return a.getHost().getName().compareTo(b.getHost().getName()); }); _hostQueue = Queues.newArrayDeque(hosts); self().tell("start", self()); }
From source file:de.is24.infrastructure.gridfs.http.security.SecurityIT.java
private String getMyShortHostName() throws UnknownHostException { String myHostName;// w w w . j a v a 2 s . c om // local integration tests use localhost access, thus need other hostname in package if (deploymentURL.getHost().equals("localhost")) { myHostName = "localhost"; } else { myHostName = InetAddress.getLocalHost().getHostName(); } int dotIndex = myHostName.indexOf("."); if (dotIndex >= 0) { myHostName = myHostName.substring(0, dotIndex); } return myHostName; }
From source file:com.walmart.gatling.commons.AgentConfig.java
public String getGenericUrl(String path, String queryStringKey, String queryStringValue) { String host = logServer.getHostName(); if (StringUtils.isEmpty(logServer.getHostName())) { try {/*from w ww .j a va 2 s . c o m*/ host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { ; } } String result = StringUtils.EMPTY; final String ENCODING = "UTF-8"; try { result = String.format("http://%s:%s/%s?%s=%s", host, Integer.toString(logServer.getPort()), path, queryStringKey, URLEncoder.encode(queryStringValue, ENCODING)); } catch (UnsupportedEncodingException e) { ; } return result; }
From source file:com.bitran.services.BitcoinService.java
private void fetchTransactions() { try {//from w w w . j av a 2s .c o m System.out.println("post"); BlockStore blockStore = new MemoryBlockStore(netParams); BlockChain blockChain = new BlockChain(netParams, blockStore); peerGroup = new PeerGroup(netParams, blockChain); listener = new AbstractPeerEventListener() { @Override public void onTransaction(Peer p, Transaction t) { broadCastTransaction(t); p = null; t = null; } }; PeerEventListener listenConnected = new AbstractPeerEventListener() { @Override public void onPeerConnected(Peer p, int peerCount) { System.out.println("new peer, peers: " + peerCount); p.addEventListener(listener); } }; peerGroup.addEventListener(listenConnected); com.google.common.util.concurrent.Service service = peerGroup.startAsync(); peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost())); Thread.sleep(10000); System.out.println("fin"); } catch (BlockStoreException | InterruptedException | UnknownHostException ex) { Logger.getLogger(BitcoinService.class.getName()).log(Level.SEVERE, null, ex); } }