UnknkownHostException - java

Please help;
Am trying to deploy a web application.
The build is returning successful,and am not getting any errors on the sever.log
however am getting a http 503 error:the requested service() is not currently available
and also my
Java DB Database Process has this message
Warning: UnknkownHostException: intracare: intracare.
Could not listen on port 1527 on host localhost.
am using glassfish v3 prelude

Possibly you already have another application (perhaps another JavaDB instance?) listening on port 1527 - that could explain the "could not listen" message. Use netstat to check.

I think that UnknownHostException is related that intracare can't be resolved to an IP.
I would:
Ping that host.
Check C:\WINDOWS\system32\drivers\etc\hosts or /etc/hosts files.
Regards.

Check the DNS settings on the host. Your short names do not resolve correctly.

Mayby string you are typing as a host name is wrong? Maybe it is firewall problem?

Related

How to bind DatagramSocket to particular port in Openshift

I am running siple java jar service on openshift which tried to connect with DatagramSocket and Getting this Exception:
java.net.BindException: Permission denied
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:96)
at java.net.DatagramSocket.bind(DatagramSocket.java:397)
at java.net.DatagramSocket.<init>(DatagramSocket.java:251)
at java.net.DatagramSocket.<init>(DatagramSocket.java:304)
at java.net.DatagramSocket.<init>(DatagramSocket.java:276)
at com.gasmps.service.TerminationListener.run(EmailService.java:542)
at java.lang.Thread.run(Thread.java:745)
I know this is port permission problems but i tried with port like 8000,8443,15005,16005 but getting same how could i resolve this? How i can know all open port that can i use in my application.
Edit: My jboss server is already running in the same application and I don't want to create separate application for these jar service bcos I have to run this jar from my application from remote location.
Iv looked into this before after having the same issue and discovered the answer on stack-overflow before:
In Openshift, you may only bind to the port that the server allocates
for you. Typically that is the value of the environment variable
$OPENSHIFT_JBOSS_PORT (it varies between cartridges) and the value
differs between gears. Binding to any other port will be reported as
an SELinux policy violation and denied.
link
The port is usually 8080
you can bind your app to 8080 (not to 8000 or 8443), all traffic >received on 8000 and 8443 will be routed by the proxy to your app >listening on 8080.
This worked for me, but let me know how it goes and if it still doesn't work i'll try and help.

How do I connect to Derby which is included with WebLogic?

I'm trying to add the Derby included with WebLogic as a data source. I'm running WebLogic 10.3.5. I didn't see a Derby flag in the setDomainEnv.cmd, so I added the client driver to the CLASSPATH:
set CLASSPATH=%PRE_CLASSPATH%;%WEBLOGIC_CLASSPATH%;%POST_CLASSPATH%;%WLP_POST_CLASSPATH%;%WL_HOME%\common\derby\lib\derbyclient.jar
in setDomainEnv.cmd. Now when I try to activate my data source in WebLogic I get:
An error occurred during activation of changes, please see the log for
details. Message icon - Error weblogic.application.ModuleException:
Message icon - Error java.net.ConnectException : Error connecting to
server localhost on port 1527 with message Connection refused:
connect.
What else do I need to do to get this to work?
I believe your local derby is not up yet. To check this, issue:
netstat -an | findstr 1527.
See if it returns anything. If nothing is returned, try to start the Derby Network Service manually. Go to <WLS_HOME>\common\derby\bin and click the startNetworkServer.cmd.
Double check with netstat again. If it's there, you can try to add to the datasource.
Note: this only covers manually start the Derby network service (not automatially start it upon weblogic start, which a bit tricky).
Either whatever is supposed to be running on that port isn't running or there is a firewall issue.

dnsjava can't resolve "localhost" on Linux machine

After I registered dnsjava as default Java DNS provider I get a problem. It can't resolve local addresses which described in /etc/hosts file on my Linux machine. This file look something like this:
127.0.0.1 localhost
127.0.1.1 servername
So if I try to resolve one of such names UnknownHostException happens:
org.xbill.DNS.Address.getByName("localhost");
org.xbill.DNS.Address.getByName("servername");
It's not a problem when you're using dnsjava along with default dns provider. Being a sole provider, dnsjava causes lots of errors in default libraries, which turn out to be highly dependent on localhost resolution capability. So, the question is: how to change behavior of dnsjava to resolve local hostnames?
Edit. Next code works fine:
java.net.InetAddress.getByName("localhost");
But java.net.InetAddress.getLocalHost() method throws:
java.net.UnknownHostException: servername
dnsjava is a DNS client library; it talks to DNS servers. /etc/hosts is not part of the DNS protocol nor does dnsjava know anything about it.
See this old post on a the dnsjava users mailing list from the guy who wrote it: http://old.nabble.com/DNS-Resolve-from-hosts-file-first-then-DNS-Server-td15431381.html
Nothing has changed in that regard.
If java.net.InetAddress.getByName() is working, then your DNS server is configured to respond to queries for localhost.

Issue while connecting to remote weblogic server over proxy

I have configured a proxy in my java source code as:
systemSettings.put("http.proxyHost", "www.proxyserver.com");
systemSettings.put("http.proxyPort", "8080");
systemSettings.put("http.nonProxyHosts", "10.x.y.z");
Here 10.x.y.z is the actual IP of my weblogic server.
But whenever code tried to connect to weblogic server, I receive error as:
Caused by: java.net.ConnectException: t3://10.x.y.z:7001: Destination
unreachable; nested exception is: java.net.ProtocolException:
unrecognized response from proxy: 'HTTP/1.0 403 Forbidden'; No
available router to destination at
weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:216) at
weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:170) at
weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:153) at
weblogic.jndi.WLInitialContextFactoryDelegate$1.run(WLInitialContextFactoryDelegate.java:345)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at
weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:340)
It seems that setting http.nonProxyHosts is not working as expected. I tried to find solution over the Internet, but most of them says remove proxy settings. I can not remove proxy, as my code tries to connect to some of the Internet URLs. Also note that, weblogic server is on remote machine.
Can you please give me a hint, what must be the issue here?
Have a look at this OTN thread.
From 3rd comment :
You are setting nonProxyHosts, which doesn't exist as a system property, via System.setProperties().
I haven't read all so far, but it seems the system.properties is not the convenient way to set
nonProxyHosts.
Did you tried to set it from command line ?
-Dhttp.nonProxyHosts="*.foo.com|localhost".
I resolved the issue. I had setup the proxy initially when connection with weblogic was setup. So due to some network restrictions I believe it didnt work. In modified code, I used the same 3 lines to setup proxy:
System.setProperty("java.net.useSystemProxies", "false");
System.setProperty("http.proxyHost", "www.proxyserver.com");
System.setProperty("http.proxyPort", "8080");
The only difference is, I did it at exact place where I needed. So for initial connection setup with weblogic proxy wont be used. I also did not have to bypass, weblogic server URL to not to use proxy.
#Arcadien: I appreciate your efforts to help me. Thanks.

java.net.UnknownHostException: Invalid hostname for server: local

What are the steps I should take to solve the error:
java.net.UnknownHostException: Invalid hostname for server: local
I added the new virtual host name at Android emulator but the result returns to
java.net.UnknownHostException virtualhostname at
java.net.InetAddress.lookUpHostByName(InetAddress.java:506)
When I type my virtualhost URL on my PC, it works on display. Then again, when I ran on Emulator and check on Logcat, I couldn't be able to read or check the HTTP status if 200, 202, or an error code number. It simply returned to UnknownHostException
I was having the same issue on my mac. I found the issue when I pinged my $HOSTNAME from terminal and it returned ping: cannot resolve myHostName: Unknown host.
To resolve:
Do echo $HOSTNAME on your terminal.
Whatever hostname it shows (lets say myHostName), try to ping it : ping myHostName. If it returns ping: cannot resolve myHostName: Unknown host then add an entry into your /etc/hosts file.
For that edit /etc/hosts file and add following:
127.0.0.1 myHostName
What the exception is really saying is that there is no known server with the name "local". My guess is that you're trying to connect to your local computer. Try with the hostname "localhost" instead, or perhaps 127.0.0.1 or ::1 (the last one is IPv6).
From the javadocs:
Thrown to indicate that the IP address
of a host could not be determined.
127.0.0.1or ::1 or "localhost" should always be the loopback interface, so if that doesn't work I'd be really surprised.
If there really is a server called "local" on your network - examine your DNS settings or add it to your hosts file.
java.net.UnknownHostException: Host is unresolved:
Thrown to indicate that the IP address of a host could not be determined.
This exception is also raised when you are connected to a valid wifi but router does not receive the internet. Its very easy to reproduce this:
Connect to a valid wifi
Now remove the cable from the router while router is pluged-in
You will observe this error!!
You can't really solve this, You can only notify the user gracefully. (something like - "Unable to make a connection")
This is not specific to the question, but this question showed up when I was Googling for the mentioned UnknownHostException, and the fix is not found anywhere else so I thought I'd add an answer here.
The exception that was continuously received was:
java.net.UnknownHostException: google.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
...
No matter how I tried to connect to any valid host, printing it in the terminal would not help either. Everything was right.
The Solution
Not calling trim() for the host string which contained whitespace. In writing a proxy server the host was obtained from HTTP headers with the use of split(":") by semicolons for the HOST header. This left whitespace, and causes the UnknownHostException as a host with whitespace is not a valid host. Doing a host = host.trim() on the String host solved the ambiguous issue.
Your hostname is missing. JBoss uses this environment variable ($HOSTNAME) when it connects to the server.
[root#xyz ~]# echo $HOSTNAME
xyz
[root#xyz ~]# ping $HOSTNAME
ping: unknown host xyz
[root#xyz ~]# hostname -f
hostname: Unknown host
There are dozens of things that can cause this. Please comment if you discover a new reason.
For a hack until you can permanently resolve this issue on your server, you can add a line to the end of your /etc/hosts file:
127.0.0.1 xyz.xxx.xxx.edu xyz
This might happen due to various reasons
1) Check if you have VPN connected, you might get this error sometimes if yes
"Your hostname, localhost resolves to a loopback address: 127.0.0.1; using 10.xxx.1.193 instead (on interface cscotun0)"
2) Check your $HOSTNAME
3) try to ping $HOSTNAME on commandline and if it doesnt work, tweak the system settings to make your local host respond to pings
Try the following :
String url = "http://www.google.com/search?q=java";
URL urlObj = (URL)new URL(url.trim());
HttpURLConnection httpConn =
(HttpURLConnection)urlObj.openConnection();
httpConn.setRequestMethod("GET");
Integer rescode = httpConn.getResponseCode();
System.out.println(rescode);
Trim() the URL
Trying to connect to your local computer.try with the hostname "localhost" instead or perhaps ::/ - the last one is ipv6
Please try to set SPARK_LOCAL_IP environment variable to the ip address(can be localhost i.e. your own ip address) you want to connect. E.g.
$ export SPARK_LOCAL_IP=182.95.208.152
This way you will not be required to alter existing linux settings.
Worked for me, hope helps you too.
Connect your mobile with different wifi connection with different service provider.
I don't know the exact issue but i could not connect to server with a specific service provider but it work when i connected to other service provider. So try it!
I had this issue in my android app when grabbing an xml file the format of my link was not valid, I reformatted with the full url and it worked.
If you are here because your emulator gives you that Exception, Go to Tools > AVD Manager in your android emulator and Cold boot your Emulator.
I had the same issue.
Restart docker was the fix for me. For some reason it needed a restart, I donĀ“t know why, but it worked.
If your /etc/localhosts file has entry as below:
Add hostname entry as below:
127.0.0.1 local host (add your hostname here)
::1 (add hostname here) (the last one is IPv6).
This should resolve the issue.

Categories