I'm migrating an app from jboss 4.2 to wildfly 13. The app exposes EJBs, successfully migrated and these EJBs are used by some standalone clients (wrapped as services with tanuki wrapper) running on the same machine as wildfly. These standalone clients are monitored using JMX.
The startup code tries to unbind the service name in case the client crashed in an earlier run using
Naming.unbind("//localhost:1099/myService");
On normal startup (not after a crash) a
java.rmi.NotBoundException
is expected.
My issue is I get the following stacktrace
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
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)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
port 1099 is the default "well known" port as stated by the Naming javadoc:
The Naming class provides methods for storing and obtaining references
to remote objects in a remote object registry. Each method of the
Naming class takes as one of its arguments a name that is a
java.lang.String in URL format (without the scheme component) of the
form:
//host:port/name
where host is the host (remote or local) where the registry is located, port is the port number on which the registry accepts calls,
and where name is a simple string uninterpreted by the registry. Both
host and port are optional. If host is omitted, the host defaults to
the local host. If port is omitted, then the port defaults to 1099,
the "well-known" port that RMI's registry, rmiregistry, uses.
I also tried with wildfly management port as it uses http port upgrade, I get
java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out
with the following root cause
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:246)
What am I missing and/or doing wrong?
I found that the rmiregistry is not started by wildfly. I was mislead by our old environment that starts rmiregistry on OS startup by init.d.
So starting the rmiregistry solved my problem.
Rmi and wildfly http upgrade feature are not related to each other since rmiregistry is an independent process.
Related
I'm trying to set up a RabbitMQ server (version 3.7.4, installed via homebrew on macOS 10.13.4) such that my colleagues can work with it via the internal network. We are using the official Java client (com.rabbitmq:amqp-client:5.2.0). Unfortunately, they only get a ConnectException with the message Connection refused:
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:134)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:997)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:956)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:914)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1068)
at my.own.private.RabbitMqConnector.connect(RabbitMqConnector.java:29)
We already set up another user account (not guest) which has admin privileges. With almost the same Java code I can connect locally (setting the host to localhost) but not if I use my IP address. According to the RabbitMQ docs, the RabbitMQ server binds to all network interfaces by default (otherwise I would have said that it's a problem with address binding). I disabled my firewall so that shouldn't be the problem.
Here's the respective code:
final ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setUsername("username");
connectionFactory.setPassword("password");
connectionFactory.setHost("10.10.33.12");
connectionFactory.setPort(5672);
connectionFactory.setVirtualHost("/");
try (final Connection connection = connectionFactory.newConnection()) {
// doo stuff with the connection
}
I finally found the actual problem and it's not related to Java or how I configured the ConnectionFactory. It was indeed a problem how the RabbitMQ package for homebrew is configured. In the rabbitmq-env.conf file, there was the following setting
NODE_IP_ADDRESS=127.0.0.1
This setting caused RabbitMQ to only listen on 127.0.0.1 for incoming connections. Once I removed the setting and restarted the service, I could connect from other machines as well.
Thank you all for your help!
The issue is not with your code. I would suggest you to check such things:
RabbitMQ Server is up and running
Your custom user can access virtual host "/"
Check firewall settings if any, probably it's refusing connection with remote host
One of these should be the cause, hope it helps!
Case 1. I installed mongo on my machine (Mac OS), and mongo is configured with bind-ip : 127.0.0.1. A remote machine in LAN can connect to my mongodb using my IP. (Wrong observation : See UPDATE section)
Case 2. I installed mongo on Azure Ubuntu VM, mongo configured with bind-ip:127.0.0.1. No remote machine from the same VNet can connect to that mongo using private vnet IP.
MongoDB Network Setting (both case 1 and case 2):
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
Exception (Case 2):
2018-04-03 06:35:29.948 INFO 44518 --- [72.17.1.4:27017]
org.mongodb.driver.cluster : Exception in monitor thread
while connecting to server 172.17.1.4:27017
com.mongodb.MongoSocketOpenException: Exception opening socket at
com.mongodb.connection.SocketStream.open(SocketStream.java:63)
~[mongodb-driver-core-3.4.1.jar!/:na] at
com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
~[mongodb-driver-core-3.4.1.jar!/:na] at
com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
~[mongodb-driver-core-3.4.1.jar!/:na] at
java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by:
java.net.ConnectException: Connection refused (Connection refused) at
java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_151]
at
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
~[na:1.8.0_151] at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
~[na:1.8.0_151] at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
~[na:1.8.0_151] at
java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
~[na:1.8.0_151] at java.net.Socket.connect(Socket.java:589)
~[na:1.8.0_151] at
com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57)
~[mongodb-driver-core-3.4.1.jar!/:na] at
com.mongodb.connection.SocketStream.open(SocketStream.java:58)
~[mongodb-driver-core-3.4.1.jar!/:na] ... 3 common frames omitted
Whats is different in Azure VM that it behaves differently from a Mac OS installation?
Note: Changing the bindIp to the IP (172.17.1.4) or 0.0.0.0 works.
UPDATE:
Case 1: The remote access on my local machine's mongo was because of the distribution I picked which was configured to allow remote connections.
Based on my knowledge, 127.0.0.1 only works inside machine. You could check this blog.
By default, MongoDB bind to local interface only, it will restrict the
remote connections. If you don’t care about security, just comment out
to accept any remote connections (NOT Recommend).
I suggest you could configure Mongodb like bind_ip = 127.0.0.1,172.17.1.4.
I am trying to send messages between two local PC (Windows OS). I have connected to these PC using LAN connection. The RabbitMQ server is installed on 10.100.94.25 PC. I am trying to create a connection from 10.100.94.28 PC. I have ping to my rabbit MQ server PC (10.100.94.25) from Client PC (10.100.94.28) using windows command prompt. It was successful. But, when I try to create a connection from code, it is not working. Please check my code and error log bellow. the error is telling me that "timeout error". what should I do?
I have successfully sent and received a message from the same PC. That means, when I use localhost as host, it works perfectly. Then what is the tiny touch I am missing here for remote access?
connectionFactory = new ConnectionFactory();
connectionFactory.setUsername("shoshi");
connectionFactory.setPassword("shoshi");
connectionFactory.setHost("10.100.94.25");
connectionFactory.setPort(5672);
connection = connectionFactory.newConnection(); // this is 451 number line
error:
May 01, 2016 6:00:35 PM com.chat.UI initRabbitMQ
SEVERE: null
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:714)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:760)
at com.chat.UI.initRabbitMQ(UI.java:451)
at com.chat.UI.<init>(UI.java:48)
at com.chat.UI$8.run(UI.java:405)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
I was guessing that the 5672 port is open or not. Or the firewall is blocking it or not. thanks to cantSleepNow and Thomas for their instruction.
So, what I have done? I just check the port number using telnet. the command is telnet IP_ADDRESS PORT_NUMBER. if telnet is not recognized as a command, then you have to enable it. follow the instruction bellow:
To install Telnet, please follow these instructions:
Click Start then select Control Panel.
Select Programs and Features.
Select Turn Windows features on or off.
Select the Telnet Client option.
Click OK.
or, follow this link
I was able to get a response by using telnet localhost 5672 command. but not with telnet 10.100.94.25 5672 command.
Also, from THIS POST I get that:
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access
And my error log says that java.net.ConnectException: Connection timed out: connect
So, now I am sure that it is a firewall issue.
Then I just open erlang for remote access by following THIS TUTORIAL. And now it is working.
To know your PC's IP adress just type ipconfig using CMD.
This is most probably a (Windows) firewall issue, make sure that connections to that port are allowed.
With my ActiveMQ setup, the way I usually check my connection is:
I have a tester EJB which subscribes to a topic on the ActiveMQ system. I start my ActiveMQ system, and then run the EJB on my own server on another system. If the connection is all fine, then this EJB shows up as a consumer on the ActiveMQ dashboard. This method ensures connection setup without any nitty gritty problems with setting up the connection. Since you ping is working, this test should ideally go through successfully.
If success, you need to make sure your producer is working fine.
If failure, you know for sure that the connection is not setup properly.
I'm trying to connect to a socket using JBoss EAP in Openshift. I'm getting this error:
ERROR (ServerService Thread Pool -- 70) Ping to [address.of.destination:10443] failed: Permission denied: java.net.SocketException: Permission denied
at sun.nio.ch.Net.connect0(Native Method) [rt.jar:1.7.0_51]
at sun.nio.ch.Net.connect(Net.java:465) [rt.jar:1.7.0_51]
at sun.nio.ch.Net.connect(Net.java:457) [rt.jar:1.7.0_51]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:670) [rt.jar:1.7.0_51]
I think the reason why is because Openshift blocks access to the port.
Also I'm under these conditions:
I can't change the port on the destination server, since it's not under my control.
the connection made to the server is made by the library I'm using, which means, it is writing the address and port by itself, so I cannot change the port on the code of the library because it's compiled code already.
Is there a work-around for this situation?
It is possible to bind to the internal IP with port range between 15000 and 35530 https://www.openshift.com/kb/kb-e1038-i-cant-bind-to-a-port. Also read http://blog-judcon.rhcloud.com/?p=97
java.rmi.ConnectException: Connection refused to host: IPSERVER0.0.0.0.0; nested exception is:
java.net.ConnectException: Connection timed out
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at StartRMI.go(StartRMI.java:14)
at StartRMI.main(StartRMI.java:6)
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 more
I get this exception when I try to connect a remote client to my server. My Server is running RMI Server fine, and there no firewall installed. How to fix that issue ?
Check all you network adapters ,some time a VM network adapter interferes in this way .
Which is you current localhost or 127.0.0.1 is not any more referring to you host name or current machine ,which then create a connection refused problem. My General Recommendation is:
1.To check or disable unwanted VM or Network Adapters
2.Ping 127.0.0.1
3.Disable Firewall and Test if all the above doesn't work
4.Add security Manager with a policy file on you server if you haven't done that.
You have not mentioned which OS you are using, if everything is correct in terms of code and firewall then you may need to check the host entries or ip table rules.
Is IPSERVER mapped in /etc/hosts file to the IP address you want?
Check what you get when you do a hostname -i or hostname.
Try putting your IP address instead of the domain name.
Try to start the RMI registry using
start rmiregistry
for default port or
rmiregistry <port_no>
for a specified port.