I have a java program Read which reads file from an URL looks like this:
file://myhost/system.log
On Windows I use this command:
java Read "file://myhost/system.log"
and it works flawlessly.
But on Linux when I try to use the same command it gives me this error:
Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.ftp.impl.FtpClient.doConnect(Unknown Source)
at sun.net.ftp.impl.FtpClient.tryConnect(Unknown Source)
at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
at sun.net.ftp.impl.FtpClient.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at read.readInput(ReadHTML.java:53)
at read.readInput.main(ReadHTML.java:76)
Any ideas?
UPDATE:
I think I found the problem:
myhost is not mounted on the Linux machine so that it cannot connect to it by using file://...
Thanks for all the answers, guys!
This is because your program (by virtue of using a file URL on a Linux OS) is attempting to open an FTP connection to the host specified in the URL. The establishment of the FTP connection fails.
This could be due to a variety of issues. Try connecting with ftp directly:
ftp myhost
And I'm guessing it'd fail as well. Do you have an FTP server installed & running?
One of the possible reason can be that hosts.allow does not have entry of your machine.
I suspect you just need a third /. The correct syntax for file uris is file://[path] but [path] should begin with a /.
Related
i want to establish a connection between my Java Program and my Database created with MariaDB on a different server (not localhost). Everything is fine with the ServerIP, Databasename, User and Password.
But i get this error:
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=MY_SERVER_IP)(port=3306)(type=master) : Connection timed out: connect
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.Driver.connect(Driver.java:106)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MySQL_Tester.LoadDriver.main(LoadDriver.java:11)
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not connect to address= (host=MY_SERVER_IP)(port=3306)(type=master) : Connection timed out: connect
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connectWithoutProxy(MySQLProtocol.java:629)
at org.mariadb.jdbc.internal.common.Utils.retrieveProxy(Utils.java:541)
at org.mariadb.jdbc.Driver.connect(Driver.java:101)
... 3 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:288)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connectWithoutProxy(MySQLProtocol.java:624)
... 5 more
My Code:
package MySQL_Tester;
import java.sql.*;
public class LoadDriver {
static Connection sqlHandler = null;
public static void main(String[]args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
Class.forName("org.mariadb.jdbc.Driver").newInstance();
sqlHandler=DriverManager.getConnection("jdbc:mysql://MY_SERVER_IP/DATABASENAME?user=USERNAME&password=PASSWORD");
}}
All the versions i use:
MariaDB: 10.1.44
MariaDB-Java-Connector: mariadb-java-client.1.2.0.jar
Java Version: Version 8 Update 161
Eclipse Version: 2019-03 (4.11.0)
You must update your connection string with the real values.
Thank you for your answer davidbuzatto but the problem was easier to solve than i expected.
Here is a Guide how i solved this problem for me:
Step 1: Check your MySQL-Config File with (nano /etc/mysql/my.cnf in Ubuntu)
replacing bind-adress: 172.0.0.1 with bind-adress: 0.0.0.0
When this doesnt help... For me it didnt help....
Step 2: Check the Firewall Settings on your Server and allow the access to the MySQL Server
When this also doesnt help... For me it didnt....
Step 3: Grant Access to your MySQL-Database
Use this MySQL-Query: GRANT ALL ON yourDatabasename.* to yourUser#yourIP identified by 'passwordOfTheUser';
I'm trying to connect a client and remote server through RMI and I get this error message:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.net.MalformedURLException: unknown protocol: c
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at RmiClient.getMessage(RmiClient.java:11)
at RmiClient.main(RmiClient.java:26)
Caused by: java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at sun.rmi.server.LoaderHandler.pathToURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.getDefaultCodebaseURLs(Unknown Source)
at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 4 more
The following may be the cause of the problem:
The server has this line:
Naming.rebind("rmi://172.31.24.66:1099/RmiServer", obj);
which refers to the private IP address of an EC2 instance. The client on the other hand has this line - which is line 11 from above:
RmiServerIntf obj = (RmiServerIntf)Naming.lookup("rmi://54.229.66.114:1099/RmiServer");
which is the public IP of that instance. Also, on the client side I set the codebase property as:
System.setProperty("java.rmi.server.codebase", "C:\\Users\\spacitron\\Projects\\RMIClient\\bin");
If I try to add the same line on the server I get a "permission denied" error.
A codebase is a list of URLs. What you have specified is a file name, not a URL.
It is also a rather useless filename, unless the client is on the same host as the server, in which case it is difficult to see why you're using the codebase feature at all. Even if you have a shared drive it is just as easy to specify directories in the client's CLASSPATH as it is to use java.rmi.server.codebase. A codebase URL needs to be usable by the recipient. That's why they are almost always HTTP URLs, or maybe FTP URLs.
try down grading your jdk7 below update 21/jdk6 below update 45.
compile and test again of this work problem is java.rmi.server.useCodebaseOnly system property
please check below link for solution for both version of jdk's
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/relnotes.html
I am just following a tutorial on how to send files using RMI.
Tutorial: Link
I encounter an error when i try to run my server. The only change i have made different from the tutorial is i have changed my port to 1097 instead of the default 1099.
How can i resolve this error?
This is the error i receive:
C:\Program Files\Java\jdk1.7.0_09\bin\FT_RMI>java -Djava.security.policy=policy.
txt FileServer
FileServer: access denied ("java.net.SocketPermission" "127.0.0.1:1097" "connect
,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission"
"127.0.0.1:1097" "connect,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown S
ource)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at FileServer.main(FileServer.java:11)
Line 11 is Naming.rebind().
Here:
FileInterface fi = new FileImpl("FileServer");
Naming.rebind("//127.0.0.1:1097/FileServer", fi);
I have tried changing the address to localhost, but the same error occurs.
SOLUTION
Point to the specific java policy file, either in JRE folder or a specific policy file.
java -Djava.security.policy="C:\\FT_RMI\\java.policy" FileServer
You have to allow the socket connect on your security properties under JRE. You can see this under jre/lib/security/java.policy
You are running your server under a SecurityManager. Unless you are using the RMI codebase feature or you have another specific security requirement that dictates its use in the server, just remove it.
I am trying to run my Java application in debug mode in Eclipse, but it's not working. It was fine until yesterday when I could properly debug my application. I am able to run my application on the server ( Oracle OC4J Standalone Server 10.1.3) properly. Only while debugging, it continues for a long time and then shows a server time out error. I tried increasing the Server time out, but was of no use.
I also tried removing the Server and creating it again and restarting Eclipse. Is there something I could do about this?
Edit: Strack trace on trying to Run it as Remote Java Application
Exception Stack tace:
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.eclipse.jdi.internal.connect.SocketTransportService$2.run(SocketTransportService.java:136)
at java.lang.Thread.run(Unknown Source)
There is an issue with OC4J's debug mode enabling. Sometimes I've noticed that after enabling it (via opmn.xml) it will work for a while then stop working. What I've found to actually work all the time is editing the /bin/oc4j.cmd file and adding the line:
set JVMARGS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=9009,suspend=y,server=y
then start a Remote debugging session from Eclipse on the port 9009
I'm trying to implement Sun Tutorials RMI application that calculates Pi. I'm having some serious problems and I cant find the solution eventhough I've been searching the entire web and several javaskilled people.
I'm hoping you can put an end to my frustrations.
The crazy thing is that I can run the application from the cmd on my desktop computer. Trying the exact same thing with the exact same code in the exact same directories on my laptop produces the following errors. The problem occures when I try to connect the client to the server.
I don't believe that the error is due to my policyfile as I can run it on the desktop. It must be elsewhere. Have anyone tried the same and can you give me a hint as to where my problem is, please?
POLICYFILE SERVER:
grant
{
permission java.security.AllPermissions;
permission java.net.SocketPermission"*", "connect, resolve";
};
POLICYFILE CLIENT:
grant
{
permission java.security.AllPermissions;
permission java.net.SocketPermission"*", "connect, resolve";
};
______________________________________________
SERVERSIDE ERRORS:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\STUDENT>cd\
C:\>start rmiregistry
C:\>java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:/c:/jav
a/compute.jar -Djava.rmi.server.hostname=localhost -Djava.security.policy=c:/jav
a/servertest.policy engine.ComputeEngine
ComputeEngine bound
Exception in thread "RMI TCP Connection(idle)" java.security.AccessControlExcept
ion: access denied (java.net.SocketPermission 127.0.0.1:1440 accept,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkAccept(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.checkAcceptPermi
ssion(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.checkAcceptPermission(Unknown Sour
ce)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Sou
rce)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
ce)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
_______________________________
CLIENTSIDE ERRORS:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\STUDENT>cd\
C:\>java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:\C:\jav
a\files\ -Djava.security.policy=c:/java/clienttest.policy client.ComputePi local
host 45
ComputePi exception:
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception
is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn
own Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.executeTask(Unknown Source)
at client.ComputePi.main(ComputePi.java:18)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
... 6 more
C:\>
Thanks in advance
Perry
Your server didn't have permission to accept a connection from that client.
Ergo your policy file wasn't where you said it was, or wasn't loaded for some other reason.
Run it with -Djava.security.debug=access,failure and you will see what protection domain you were in when the security exception occurred, and what permissions it had.
java -cp c:\java;c:\java\compute.jar -Djava.rmi.server.codebase=file:/c:/java/compute.jar -Djava.rmi.server.hostname=localhost -Djava.security.policy=c:/java/servertest.policy engine.ComputeEngine
NB a file: codebase cannot work if it refers to a local filesystem, unless the client is also in the same machine, which makes RMI fairly pointless. Codebase URLs need to refer to locations that are accessible by the client. You can use shared file systems but you must provide a URL that is usable by the client. The server doesn't use its own codebase URL at all.
I tried the same and I found that Java simply ignored the policy file, no matter where I put it or what I put into it or which option I used to make the VM pick it up.
In the end, I create my own SecurityManager in the code and did everything manually.