UnknownHostException from Java but host resolves with Ping/nslookup/curl - java

We are getting the following exception when a Java EE server tries to resolve a host name from one of the services. We were able to resolve that host name on the box manually with ping/nslookup command. We were also able to fire that external service using curl with same parameters what server is trying to use. So it seems like this issue happens only when we try to make a request to a external host from a Java/Java EE application.
To resolve this issue, we manually added an entry in /etc/hosts file and it solved the problem but we want a permanent solution so we don't have to keep changing the IP. It was working before without adding that entry but all of a sudden it stopped working.
Detail of our environment:
OS: Cent OS 6.3
Java : JDK 1.6.0_24
Java EE Server : JBoss AS 7.1.1
Http Client library : httpclient-4.0.jar
Thanks in advance for the help!!
Error while checking salesforce license|:
java.net.UnknownHostException: na15.salesforce.com at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175)
[rt.jar:1.6.0_24] at
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
[rt.jar:1.6.0_24] at java.net.Socket.connect(Socket.java:546)
[rt.jar:1.6.0_24] at
sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:584)
[jsse.jar:1.6.0_24] at
org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:333)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
[httpclient-4.0.jar:4.0] at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
[httpclient-4.0.jar:4.0]

This is most likely a network management, change / configuration management or general system administration problem rather than a programming problem.
It was working before without adding that entry but all of a sudden it stopped working.
One approach is to try to figure out what changed to cause it to stop working. This is not the kind of thing that would happen spontaneously. Someone or something has changed some software or configurations to make this happen. Start with when it stopped (or when you noticed) and work back through your change logs.
It sounds like it is an issue with the Java DNS resolution procedure. It appears that the resolver is either not trying to talk to the normal DNS servers, or it is trying and failing.
We can't debug it for you, but I found these resources that help to explain what should be happening when you do a name lookup in Java, and offer some ideas on trouble-shooting.
Resources:
DNS and Java
Java doesn't pick up system's DNS settings change until restarted
Java and /etc/resolv.conf DNS server failover
Java networking properties

I found that these same symptoms can happen when IPv6 is disabled on your networking. You can see this by running a simple Java program:
import java.net.InetAddress;
public class NameTest
{
public static void main(String[] args) throws Exception
{
System.out.println(InetAddress.getByName("google.com"));
}
}
If IPv6 is an issue, then running the program with java -cp . NameTest will fail with a line like "at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)" in the stack trace (notice the Inet6 in the class name), and running the program with java -cp . -Djava.net.preferIPv4Stack=true NameTest will succeed (this is from the above answer Java networking properties reference).
To work past this, I followed suggestions from this question.
An OS-wide disabling of IPv6 works well, as the system doesn't have IPv6. On some Linux varieties, this can be disabled by first adding this line to the end of the file /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
followed by running sudo sysctl -p to immediately disable IPv6.

Related

How to connect to a Grakn Server running on a GCP VM instance

I'm trying to connect to a Grakn Server running on a GCP VM instance. I have read the related post in the discussion forum. One of the replies suggests to do the following on the server side:
Edit ./conf/main/grakn.properties:
storage.hostname=EXTERNAL.ip.v4.address
Edit ./conf/cassandra/cassandra.yaml:
seeds: "EXTERNAL.ip.v4.address"
broadcast_address: EXTERNAL.ip.v4.address
listen_address: INTERNAL.ip.v4.address
rpc_address: INTERNAL.ip.v4.address
Access it from the Java API:
GraknSession session = Grakn.session(“EXTERNAL.ip.v4.address”, keySpaceName);
What i have interpreted from this, for my specific case, is the following:
-Replace EXTERNAL.ip.v4.address with the External IP of my VM instance
-Replace INTERNAL.ip.v4.address with the Internal IP of my VM instance
When i start the server i get this exception cause (I think this is the root cause):
Caused by:
com.netflix.astyanax.connectionpool.exceptions.PoolTimeoutException:
PoolTimeoutException: [host=104.197.131.17(104.197.131.17):9160,
latency=10000(10000), attempts=1]Timed out waiting for connection
at com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool.waitForConnection(SimpleHostConnectionPool.java:231)
What am i missing?
Do i have to add firewall rules?
Thanks for the help.
To access Grakn remotely using the Java API, you need to open the following ports on the GCP and Linux VM firewall (eg. iptables):
4567
9160
Make sure you are able to access those from the client machine.

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/Linux cert exception

I'm running an osgi-application locally in Eclipse. When I did it using windows it worked fine, it'a server/client setup.
I later installed Fedora 17 and tried doing the same thing, the server seems to be working fine but when I try to connect using the client I get the following error:
java.security.cert.certpathvalidatorexception no subject alternative dns name matching localhost found
I have tried googling the problem but I didn't find any silver bullets.
Has anyone got any ideas?

Error HTTP: 500 when uploading/sharing file in openmeetings

I have error HTTP: 500 when I try to upload a file or to share one in the white board.
I install openmeetings on windows 7 64 bits and I configured all things perfectly with compatible versions:
C:\ffmpeg\bin
C:\ImageMagick-6.6.4
C:\Program Files (x86)\SWFTools
C:\sox-14.4.0
C:\jodconverter-core-3.0-beta-4\lib
recording and video conference works perfectly.
How can I solve this problem ? Is there a problem with the SWFTools version 0.9.1 ?
When you import a document you should have a look at the error message / convertion message.
OpenMeetings has mailing lists where those problems are discussed:
http://incubator.apache.org/openmeetings/mail-lists.html
Were you running it in proxied mode on port 8080 (The default port of OpenLaszlo proxied mode)? If so, some routers/firewalls block this port. I encountered a similar problem myself when my boss and I were at a conference and that was the cause of the problem.
We have since changed our demo application to SOLO (no-proxied mode) which has solved our problem.

java.rmi.UnmarshalException: unable to pull client classes by server

I have an RMI client/server set-up on two machines that works fine in a simple situation when the server doesn't require a client-side defned class. However, when I need to use a class defined on the client side I am unable to have the server unmarshall those classes. I suspect this is an issue with my java.rmi.server.codebase property that I pass in as argument to the client app. I followed Sun's RMI Tutorial trail and I think I have followed the steps exactly except that I don't specify a classpath argument when executing client and server because they execute in the directory right above the root package directory (however I tried that too with no effect).
The exceptions I get when attempting to execute the different client-side combinations described in detail below are all the same:
RmiServer exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.MyTask
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:353)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.execute(Unknown Source)
at test.myClient.main(myClient.java:32)
The details are:
My client/server rmi is set up over a home network behind a router. The router is assigned to a static ip address I will call myhostname. Appropriate port-mapping is set-up in the router that points to the right machines.
role, machine, os, ip-address:
server, venice, linux ubuntu 9.10, 10.0.1.2
client, naples, mac os x leopard, 10.0.1.4
I startup the server side as follows inside /home/andrews/workspace/epsilon/bin:
1 starting registry on the default port 1099:
venice% rmiregistry &
2 starting web-server on port 2001 pointing to code base for common interfaces:
venice% java webserver/ClassFileServer 2001 /home/andrew/workspace/epsilon/bin
3 starting server app (main class in test/myServer) which registers the server object:
venice% java -Djava.rmi.server.codebase="http://myhostname:2001/" -Djava.security.policy=server.policy -Djava.rmi.server.hostname=myhostname test/myServer &
Now the client side inside /Users/andrews/Development/Java/workspace/epsilon/bin:
1 start a local web server that can server client-side classes to the server (not sure if this is needed, but I added I tried it, and still no success; I have added port-mapping to the router for 2001 to venice, for 2002 to naples)
naples$ java webserver/ClassFileServer 2002 /Users/andrews/Development/Java/workspace/epsilon/bin/
Trying to run the client (note: I don't specify the -cp argument because client executes right above the root package directory):
1 try #1 using an http hostname
naples$ java -Djava.rmi.server.codebase=http://10.0.1.4:2002/ -Djava.security.policy=client.policy test.myClient myhostname
Note 1: the myhostname argument at the end is passed-in to the client so that it resolves to server's rmi hostname.
Note 2: I tried using localhost:2002 instead of 10.0.1.4:2002 too.
Note 3: I tried using myhostname:2002 since myhostname is assigned to the router and I have proper port-mapping set-up, this address should resolve to naples and not venice
2 try #2:
naples$ java -Djava.rmi.server.codebase=file:/Users/andrews/Development/Java/workspace/epsilon/bin/ -Djava.security.policy=client.policy test.myClient myhostname
Note 1: the code base url format is correct, I created a small program to convert current file directory path into a url and used that. using file:///Users... has same effect.
Other notes:
1 my server and client policy files correctly specify the path, as I've tested this setup with good and bad paths, and getting a security exception for bad path
2 this setup works if I don't use client-side defined objects, the client connects correctly to the server and the server executes.
3 when I place the client-side class on the server in the server's classpath, all executes fine.
All help is appreciated.
Do you really need to use RMI? Me and a friend tried it once in school and it was way slow, much slower then the simple ObjectOutputStream networking we had been doing earlier.
I strong agree with Chad Okere's said, RMI is really very slow and consuming-resouces. sometimes directly use Sockets maybe is simple and useful chooice, regarding your exception Could you confirm your rmi server work correctly? http://www.javarmi.com/2010/05/java-rmi-error-unmarshalling-arguments/ maybe be can help you

Categories