I have an issue with the following piece of java code running in Lotus Domino.
File filData = new File(domSapFilePath + "\\DOMSAP" + sdfDateTime.format((Calendar.getInstance()).getTime()) + ".csv");
FileOutputStream foData = new FileOutputStream(filData);
foData.write(DomSapGenerator.GenerateDomSapFile(con, dateFrom, dateTo).getBytes());
foData.close();
con.close();
The created file is in a UNC path but when it tries to write the file, it errors out saying that the file is in use by another process as can be seen below:
error message: java.io.FileNotFoundException: \\10.XX.XX.XX\xxxxxx\XXX\DOXXXXXX22230.csv (The process cannot access the file because it is being used by another process)
I've never programmed in Java before and I was hoping someone could point me in the right direction for a solution for this problem which is happening intermittently.
Thank you.
The most likely cause of this problem is that something else has the file open and is using it. The operating system is preventing you writing to the file because that could interfere with whatever it is that the "something else" is doing.
It is presumably happening intermittently because the "something else" is only using the file occasionally.
The solution is to figure out:
what is using the file,
why it is locking it, and
how to coordinate the different activities on the file to avoid the conflict.
As you are trying to open a UNC path, another cause for this error message could be that the code is running inside a scheduled agent.
In that case, the connection to the server \10.XX.XX.XX\ would be opened in the context of the OS account, that Domino is running under - usually "SYSTEM". As the "SYSTEM" user is not allowed to make a network connection to another server, the open call will fail.
Solution: Run the Domino service as another (AD) user that has the right to make network connections.
You didn't say what operating system, but I am going to take a guess at windows based on the UNC format.
Microsoft have a program called Process Monitor. You can use this to track what is touching the file.
http://technet.microsoft.com/en-us/sysinternals/bb896645
But I would also go with leyrers response first.
Related
I am currently working a scenario where we have to create a file in a shared directory in Linux as well as Windows.
I have gone through the following link to achieve it :
https://www.journaldev.com/878/java-write-to-file
https://it.toolbox.com/question/how-to-write-a-file-in-a-network-folder-without-using-ftp-031208
I was able to achieve it in windows network like giving the file name as (\\198.168.1.1\data\files)
But for the Linux first I used NFS to share a particular directory using below links :
https://alvinsim.wordpress.com/2012/06/21/mounting-nfs-from-linux-to-aix/
https://www.tecmint.com/how-to-setup-nfs-server-in-linux/
But got the following exception :
java.io.FileNotFoundException: /data/files (Read-only file system)
I found the following issue resolved in following thread, but I could not succeed :
https://askubuntu.com/questions/197459/how-to-fix-sudo-unable-to-open-read-only-file-system
Any advice is appreciated.
So finally I was able to figure what the problem was.
The entry which I made as per link in /etc/exports file is not sufficient.
We would need to use some options as well like (sync,rw,etc..) for allowing any manual modifications or modifications using any java program.
In my case, I should have used the options (rw,no_root_squash).
And it worked.
As very well explained in :
https://serverfault.com/questions/611007/unable-to-write-to-mount-point-nfs-server-getting-permission-denied/611013#611013?newreg=ce76e9417ca645da9487a5d9ccbf0371
From Docs on :
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-nfs-server-config-exports
root_squash — Prevents root users connected remotely from having root privileges and assigns them the user ID for the user nfsnobody. This effectively "squashes" the power of the remote root user to the lowest local user, preventing unauthorized alteration of files on the remote server. Alternatively, the no_root_squash option turns off root squashing. To squash every remote user, including root, use the all_squash option.
Every time a ftp connection is established I want a java program to get triggered.
I am not sure how to check the FTP connections. Is there a way to monitor the port so that I can acknowledge when FTP gets the new connection?
I've researched a bit and found the FTPClient class which basically suggests I need to do my own ftpclient, but I want to know if there is another way.
Even an external program could be an option.
it would be running on the server side, basically the program will be reading the files that the client put on it.
Consider using a file watcher. It doesn't seem that you really care that the file gets there using FTP (in fact, in the future it might get there by some other means), but just that the file is present and needs to be processed.
See Watching a Directory for Changes for details on how to write one.
I have a program that does a similar task server-side with java. It checks if files exist in a folder and launches the rest of the code if so. Like this:
public static boolean needToConvert(){
//get list of companies
List<String> companies = getCompanyNames();
//check whether a file exists in folder of company
for(String company: companies){
if (new File(INPUT_LOCATION + company).list().length > 0){
return true;
}
}
return false;
}
This is a rather in-expensive task, so you could just set the server to "check"; say, every minute or so.
There are a variety of approaches:
Have the FTP service itself launch the java app (sounds expensive) or notify a running Java app / service. This will be the simplest approach ...
Use some kind of external monitoring; e.g.
A generic packet packet sniffing tool (like wireshark or tcpdump) might be able to trigger an external application. If not, you may be able to get it to log info to a file that you scan for connection events.
You could possible implement something using jpcap to do your own packet sniffing in Java
There is a Linux utility called tcpspy that logs TCP/IP connection details to syslog. You could configure it log to a specific file and monitor that file, alternatively, you could modify tcpspy to launch or notify a Java app directly.
When I am trying to process a file in Camel and it fails I try to move the file to an error directory but get the following error message:
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot delete file:....
I don't know if Windows is locking the file, but I have closed any streams that may cause this to occur on my side. If this is Windows what could I do to release this lock?
The route is a simple from()... process().. to() and there are some headers set after the process() It is the to() where this fails and the file does not move into the error directory as expected.
Thanks.
Maybe it has something to do with this:
Cannot move/delete file after processing on Windows
There is a potential issue on Windows platform with Camel 1.5.x. That
it cannot move or delete the file after processing. You should get an
exception thrown.
The workaround is to convert the body to a String after consuming
using convertBodyTo: eg
from("file://inbox").convertBodyTo(String.class).to("file://outbox");.
There should be a fix in Camel 1.6.0 to remedy this, but we would like
to get feedback on this issue. So if you are on Windows please give it
a go.
It seems there was a rogue stream that needed changing. I found this out using Process Explorer as it identified the same file twice. One lock was removed and another was not and from this I found an open stream that wasn't handled in the catch block.
I have a program that I've created that is meant to poll an html internal page with different IPs that update and then will run a telnet session to those IPs to see if the device still has a connection... I'm attempting to challenge myself in creating something further with a dynamic webpage instead of my program spitting out console output...
My Issue:
I dont know what technologies / libraries Java has to execute such things
I want:
A Local Server, to upload a page LOCALLY only (no security is needed as this will be strictly intranet)
My program to implement: A database of sorts to save "logs" essentially that a certain IP / device has had successful connections
in the past....maybe stored to an external file is fine i presume (my
program currently has to re-poll everytime i run it.. i want some kind
of "remembering"..
Is it possible this can all be done in one file? so if i want my computer to run this as soon as it starts up... it will run... grab
its current state of the database of IPs... poll them (periodically)
and then persist and save and update the HTML page dynamically....
I hope i'm being as descriptive as possible... Its a bit of an abstract.. I really just want some introduction to different libraries ... a friend recommended stuff like MongoDB or something but I want to stay strictly to Java programming
I want to make an Applet write to a text file. I think have overcome the security problem with my own certificate, but the text file isn't receiving the output.
My Applet can be seen at tomrenn.com/fallball, and should ask if you trust the certificate.
I'm not sure an Applet can write to a text file within the web hosted contents, so I'm asking if this is possible; and if not, at least be able to do it on the local machine. I had been using a FileOutputStream, but my teacher recommended this very basic output method.
public void writeToFile()
{
try {
java.io.File file = new java.io.File("highscores.txt");
java.io.PrintWriter output = new java.io.PrintWriter(file);
output.print(name + " " +score);
output.close();
} catch (IOException e) {
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
This is not what I would be implementing, just trying to see if I get any output. Thanks for looking over my question!
From an Applet, you cannot directly write to the server's file system. You can issue a request to the server that causes the server to write to its own file system, but an Applet does not have a way to write to a file system on a remote machine. (Of course, unless it's mounted NFS or otherwise.) To issue such a request, you could use Apache HttpClient to issue HTTP requests, for example. This may be more heavyweight than you are looking for. You can also have the client issue a POST to the server to say, "This is my high score," and let the server manage high scores.
A signed Applet has every right to write to the local file system of the person running the Applet. If you are writing to the "current directory" (rather than an absolute full path), then make sure you know what directory the Applet is running in. Otherwise you may indeed create a file, but not be able to find it!
If you want an applet to store data on the local machine, from 6u10 the javax.jnlp.PersistenceService is available. Creating a secure "signed applet" is difficult, and I wouldn't recommend it to anyone.
Applets run on the client so cannot access the servers disk.
The code you posted will write to the clients local disk. I'd suggest changing it though to specify the directory you want to place the file. The users home directory would seem a good place for it
java.io.File file = new java.io.File(System.getProperty("user.home"), "highscores.txt");
just sign your applet.
it is easy using netbeans.
open the project in netbeans.
right click on your project and select properties now you will have new window.
go to > application > webstart on that window.
check enable webstart.
press customize button at signing and choose "self signed by a generated key".
check "applet descriptor" and target your applet.
press ok.
rebuild the project (now netbeans will create certificates with all privileges )
use "launch.html" at your projects dist dir to run the applet via jnlp.
That's all.
** used netbeans version = 7.0
** used JDK = 1.6
** certificates will expire in 6 months.
Thanks