InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ...
with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config :
cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ACTION03
any help ?
There was similar bug fired in JDK.
What I understand is that they changed default resolution process.
They honor configuration in /etc/nsswitch.conf where hosts are configured for /etc/hosts that gives it main priority for name resolution.
Usually /etc/hosts has record for 127.0.0.1 localhost that provide name for host localhost
Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05.
public class HostName {
public static void main(String[] args) throws Exception {
System.out.println(java.net.InetAddress.getLocalHost().getHostName());
}
}
robert#habanero:~$ javac HostName.java && java HostName
habanero
Related
I am using given below java code to get the Hostname from RHEL Using IBM JDK 1.8
import java.net.InetAddress;
public class Hostname {
public static void main(String[] args) {
try{
String hostname = InetAddress.getLocalHost().getHostName();
System.out.println("Hostname is :"+hostname);
}
catch(Exception e){
System.out.println(" Exception :"+e);
System.out.println(" Exception Msg :"+e.getMessage());
}
}
}
Hostname from RHEL 6.9 /IBM JDK 1.8 = vas2cxn00001122.
Fully qualified hostname from RHEL 7.6 / IBM JDK 1.8 = vas2cxn00003344.cloud.vd.org.
Why is there a difference between 6.9 vs 7.6? Where we have to update or modify the hostname in RHEL 7.6, in order to get only hostname, instead of fully qualified hostname.
I could not able to find out the root cause of RHEL 7.6 . So i have changed my java logic
from
InetAddress.getLocalHost().getHostName()
to
Runtime.getRuntime().exec("hostname")
I'm trying to run my web app tests using selenium on iE on a remorte machine. My tests run successfully locally but when I try to run them on a remorte XP OS using IE8, I get this log error : org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Help please ! Thanks !
Possible causes are
Selenium Server Standalone is NOT started on the remote machine
Selenium Server Standalone is started BUT inside code wrong IP address is written
Follow the steps written below in order to get things work:
1) Download Selenium Server Standalone JAR file : http://selenium-release.storage.googleapis.com/2.40/selenium-server-standalone-2.40.0.jar in the remote machine (IP address of remote machine let say: 192.168.10.100)
2) From remote machine, run the following command to start Server Standalone:
java -jar selenium-server-standalone-2.40.0.jar
3) Ensure IEDriverServer path is also set in that machine. Information is avialble here: https://code.google.com/p/selenium/wiki/InternetExplorerDriver
4) After all the above setting done write following sample code to open IE in remote machine:
public class IERemoteWebDriver {
public static void main(String[] args) throws IOException {
// Assuming Remote machine IP address '192.168.10.100'
String remote_address = "http://192.168.10.100:4444/wd/hub";
URL remote_url = new URL(remote_address);
DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
WebDriver wbdv = new RemoteWebDriver(remote_url, dc);
wbdv.navigate().to("https://www.google.com/");
}
}
This should work!
One possibly issue could be that your IE8 browser does not have Protected Enabled.
Open a new browser and then go to Tools->Internet Options->Security,
make sure all the zones have Enable Protected Mode selected.
We are using Ubuntu machienes as our servers, such we got 14 servers.
The command ifconfig works on all terminals it gives specific IP address.
When I ran the following java program through a script, on one of the 14 servers I get the host ip as standard 127.0.0.1 (I uploaded this file and script on only 2 machines as of now)
package com;
import java.net.Inet4Address;
public class IpAddressTest {
public static void main(String args[]) throws Exception {
String ipaddress = Inet4Address.getLocalHost().getHostAddress();
String hostname = Inet4Address.getLocalHost().getHostName();
System.out.println("THE IP ADDRESS IS" + ipaddress);
System.out.println("THE HOST NAME IS" + hostname);
}
}
To test this program as which server will give me IP as 127.0.0.1, I need to upload this java class file and related script to execute that on all of the 14 servers.
Is there any other alternate way of finding that? I want to check if i can get the IP THROUGH java , but for this i need to upload these java file and script file to all 14 servers .so asking is there any alternate way
First, if you want to use Java, then you have to upload the classes and the script to every server.To find all the IP addresses: Get local IP-Address without connecting to the internet
I create web service
#WebService(serviceName = "DynamipsService2")
#Stateless()
public class DynamipsService2 {
#WebMethod(operationName = "StartSession")
public static String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}
}
I want to test but on the page
http://localhost:8080/DynamipsService2/DynamipsService2?Tester crash bug
Error generating artifacts for the
following WSDL
http://localhost:8080/DynamipsService2/DynamipsService2?WSDL
Possible causes can be invoking https
when the application is not configured
for security
I created other Web services in the same assembly and it works.
I just experienced this problem as well. The solution for me was to use my hostname rather than localhost in the URL for the Tester.
So in my case, the following, which is what NetBeans/Glassfish did by default when I clicked Test Web Service in the NetBeans UI, did not work:
http://localhost:8080/Calculator/Calculator?Tester
However, when I paste the following into a browser, it does work:
http://david-pc:8080/Calculator/Calculator?Tester
I couldn't figure out how to change the hostname that NetBeans uses for the built-in Test dialog (nor could I cut+paste the URL from the error dialog). So I had to visually copy the URL from the error message into a browser, replacing the hostname along the way.
I had the same problem and the reason apeared in the Server's log. I'm useing Glassfish 3.1 with netBeans 7. And the error I got in the Glassfish output was:
INFO: [ERROR] com.sun.tools.javac.Main is not available in the classpath, requires Suns JDK version 5.0 or latter.
I googled a bit and it appeared to be because the glassfish server was working with the openjdk that came with ubuntu. If your problem is the same the solution I found was to remove the openjdk jre, like this:
sudo apt-get remove openjdk-6-jre
sudo apt-get autoremove
Hope this is useful.
PS: I assigned /usr/lib/jvm/java-6-sun/bin/java in the java tab at the servers configuration wizard in netBeans but don't know if that was part of the solution (I'm afraid to change it back :p)
I had the same problem with Glassfish
but it was more compilcated because of the NAT
I have GF in NAT - do MYDOMAIN and port is redirected to internal machine
the problem in GF is that it tries to connect to itself by the domain name which again redirects to inside network
(the ?wsdl works properly)
I have made temp solution adding to /etc/hosts (127.0.0.1 domainname)
be aware that it's only a temp solution
try to check if you have "localhost" in your hosts file (in windows c:/windows/system32/drivers/etc/hosts )
and ping localhost
I will add GF log - maybe someone in future will search it by google :) :)
moreover I looked GF logs there was something like ->
Connection timed out
Failed to read the WSDL document: http://MYDOMAIN:8080/MYSERVICE?WSDL, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>.
failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
Which web server do you use? If you use glassfish you can open server admin page and select Configurations===>server-config===>Security
and make Security Manager enabled
Check your domains/{YOUR_DOMAIN}/config/domain.xml
If you setup Glassfish using Eclipse, all will be done for you automatically.
Now I am surprised if I start the domain from the command line, it gave me that error, but starting Glassfish 4 from Eclipse, it is not showing any problem.
One cause could be that you don't have correctly configured the environment variable JAVA_HOME (with the correct path) and the JAVA_HOME/bin directory added to global PATH environment variable as well. For some processes the glassfish look for the classpath of the JDK installed.
Hope this help.
I had the exact same problem and it is because you have a static method, I realised after debugging for some while. Just remove static from the method and it should work.
#WebMethod(operationName = "StartSession")
public String StartSession(#WebParam(name = "key") String key) {
try {
return "100-Session started";
} catch (Exception ex) {
return null;
}
}
I'm having this strange error.
On AIX, if I can reach my server from the command line ( using ping / telnet )
But If I try using java I've got UnkownHostException
This is due to Java cannot somehow "use" the DNS but I don't know why. If I use the IP address it works fine.
This is my test program.
import java.net.*;
public class Test {
public static void main( String [] args ) throws Exception {
String host = args[0];
int port = Integer.parseInt( args[1] );
System.out.println("Connecting to: " + host + " at port: " + port );
Socket socket = new Socket( host, port );
System.out.println("Connected!");
socket.close();
System.out.println("Closed!");
}
}
Is anyone aware of some kind of configuration under AIX that forbids programs ( like java ) to access DNS information?
I ( well the sysadm ) have added my address in /etc/hosts but it doesn't work either.
Thanks in advance
Java version:
Java(TM) 2 Runtime Environment, Standard Edition (build pap32dev-20080315 (SR7))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc-32 j9vmap3223-20080315 (JIT enabled)
I am having this problem as well. I have an number of java programs installed on Ubuntu64, and none of them can resolve domain names (there are multiple JRE's too - some of them are IBM products). If I put the domain name in the hosts file with the IP address, then it works for those domains only. Every other non java program works just fine with domain resolution. WEIRD!
If I find the answer, I will post it here. If you have the answer, help us please!
Java doesn't seem to respect the ordering of DNS lookups specified on the system. For example, on my Solaris system in /etc/nsswitch.conf I have defined:
hosts: files nis dns
Java want to go to dns first, which I don't understand. It seems like it's possible to change the ordering, by setting sun.net.spi.nameservice.provider.n properties.
One workaround I've found is to append a '.' at the end of a host name. For example, if in /etc/hosts, I have
192.168.1.1 mailhost
In my java app, I would specify InetAddress.getAllByName("mailhost.").
Setting the System property
sun.net.spi.nameservice.provider.1=dns,sun
fixed this problem for me on Ubuntu
Check if you need to use a proxy and if so specify its details on the command line
http://helpdesk.objects.com.au/java/how-to-tell-a-java-application-to-use-a-proxy-server
You have to check in the /etc/services files.
I had the same error and it was because the service:
domain ..........
was commented.