com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:/// - java

Hi Stackoverflow community, i am having an issue about reading a file from my java webapp. I want to get a file from a directory in my webapp, then converting it to PDF. Everything works just fine in my developpement environement ( Windows) but when i am puting this on sever ( LINUX), when the server reach the code to read my doc file to convert it, java throw this exception :
com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:///
Here is the code :
fileDocToConvert = new File(GET_REAL_PATH()+repo_Name+slash+fileName);
fileDocToConvert path become then : /usr/share/tomcat7/webapps/myapp/repo_name/exemple.doc
the exception fired up when i try to convert :
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
//HERE...=> // converter.convert(docFile, pdfFile);
I am using :
jodConverter 2.2.1, openOffice 3, Java7, Tomcat 7
I start the openOffice service this way :
soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard
I can't get a way to follow to solve this issue.
Thank you in advance

I resolved the problem, by installing some missing components of OpenOffice ( Calc, Writer ). The problem was that OpenOffice can't understand the path of the file given to it.
Thank's for your help millimoose.

Have got java.lang.Exception: Unsupported URL <file:////... error message when started multiple libreoffice instances from different users and with conflicting same port setting.

The problem for me was that OpenOffice or another program that uses components of OpenOffice in it cannot understand the path of the file given to it as a place to save the file. Save the file that you are trying to save somewhere else on your computer and see if that works.

Related

Java error while running maxent in biomod2

I am running maxent from R, in the package biomod2 and the following error appeared. I do not come from a technical background and wasn't sure why is this error happening. Is it a memory problem or someone said the java path is not set. But I followed the instructions to set maxent to run in R and also downloaded Java Platform, Standard Edition Development Kit and set a path for it as explained in this pdf: http://modata.ceoe.udel.edu/dev/dhaulsee/class_rcode/r_pkgmanuals/MAXENT4R_directions.pdf
I would be really grateful if you could help me understand this problem and any solution to it.
Thanks a lot
Error in file(file, "rt") : cannot open the connection
In addition: Warning messages:
1: running command 'java' had status 1
2: running command 'java -mx512m -jar E:\bioclim_2.5min\model/maxent.jar environmentallayers
="rainfed/models/1432733200/m_47203134/Back_swd.csv"
samplesfile="rainfed/models/1432733200/m_47203134/Sp_swd.csv"
projectionlayers="rainfed/models/1432733200/m_47203134/Predictions/Pred_swd.csv"
outputdirectory="rainfed/models/1432733200/rainfed_PA1_Full_MAXENT_outputs"
outputformat=logistic redoifexists visible=FALSE linear=TRUE quadratic=TRUE
product=TRUE threshold=TRUE hinge=TRUE lq2lqptthreshold=80 l2lqthreshold=10
hingethreshold=15 beta_threshold=-1 beta_categorical=-1 beta_lqp=-1
beta_hinge=-1 defaultprevalence=0.5 autorun nowarnings notooltips
noaddsamplestobackground' had status 1
3: In file(file, "rt") :
cannot open file 'rainfed/models/1432733200/rainfed_PA1_Full_MAXENT_outputs/rainfed_PA1_
Full_Pred_swd.csv': No such file or directory
I've just manage to solve this problem - it is a problem with the file path specified. For me, I had a space in one of the folder names which was not accepted in the path to the maxent.jar file. From looking at your error, it looks like it might be the two backslashes.
E:\bioclim_2.5min\model/maxent.jar
should probably read
E:/bioclim_2.5min/model/maxent.jar

R xlsx package error

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.util.zip.ZipException: invalid code -- missing end-of-block
Does anyone have this error when you try to use
dat <- read.xlsx("data.xlsx", sheetIndex=1, colIndex=colIndex, rowIndex=rowIndex)?
I had this problem with a file downloaded from the internet using R command line, for an online course. Found that apparently the download mode needs to be set properly as write-binary (wb) since xlsx is basically a binary file (zip). Who knew?
If that's what you did too, re-download the file with the mode set properly; like:
download.file(fileUrl, destfile='./data/sample.xlsx', mode='wb')
The version of java you have installed is likely incompatible with the xslx package. Try replacing your default java with the 64 bit version: https://www.java.com/en/download/faq/java_win64bit.xml.

java.io.IOException: Permission denied on network folder

i'm having the the post's title error when trying to write a file on a window folder , mounted on unix system. I've developed a web service which runs inside a Tomcat 6 on a linux os and need to write on a windows network folder. System administrators have mounted it on the Linux sever and have no problem to create and modify a file on it.
When i try to execute the posted code i get the following exception :
Permission denied
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
The weird thing is that it seems to be related to the File.createNewFile method on a network folder , in fact the service can write on local file system without problems, both on debug (the pc i use to develop the service) and a tomcat folder system administrators have provided me on the linux server. The file gets created but is empty and the log entry following the create method doesn't get printed. Moreover if i use a plain outputstream to create and write the file i've no problems.
I cannot find any explanation about the exception on the web. Since i'm not very experienced with java , i'd like to understand why i'm getting this error. Am i using it in the wrong way ? Is it a bug of the library ? Do i miss to pass some parameter ?
As stated , i've solved the problem using a plain outputstream, this is a question to improve my understanding of java.
FileOutputStream fos = null;
try{
log.info(String.format("file length: %s",streamAttach.length));
log.info(String.format("check File : %s",filename));
File f = new File(filename);
if(f.exists())
...
boolean done= f.createNewFile();//here comes the exception
//nothing of the following happens
if(!done)
throw new NWSException("error creating file");
log.info(String.format("file %s creato", nomeFile));
thank you in advance for any answer
I ran into this problem recently and found that java.io.File.createNewFile() actually requires the "Change Permissions" permission (you can find this entry under Security->Advanced when checking folder permissions). Without this it will create the file and then subsequently throw an IOException.
It's deceptive because you will still be able to create files on the folder when manually testing, however createNewFile() will still fail if it doesn't have this particular permission (presumably such that it can change the permissions on the file its creating).
If you are using Netapp that shares an NTFS (CIFS) style filesystem to Unix you could be experience "NFS is not allowed to change permissions on a file in an NTFS-style security volume." (TR-3490 page 16)
Options here are to change to a unix filesystem or set the cifs.ntfs_ignore_unix_security_ops flag to on for the file system which quiches the NFS permission error.
java.io.UnixFileSystem.createFileExclusively(Native Method) opens the file with the O_EXCL and 0666 umask so I would get a EACCES, which really was a NFS3RR_ACCES
open("/net/storage01-a/filer/myfile", O_RDWR|O_CREAT|O_EXCL, 0666) Err#13 EACCES
Also you can use OutputStream to create the file, that does not use O_EXCL it seemes
It definitely not Java specific problem. If this Unix folder is mapped to your windows try to open file explorer and create file in this directory. I believe that you will get permission denied too. In this case fix this problem or ask your system administrator to help you.
Good luck!

what is the URL equivalent of an absolute path in non-windows system?

I am getting following exception while running BIRT from a Linux OS.
Caused by: org.eclipse.datatools.connectivity.oda.OdaException: no protocol: /home/lsingh/reporting/tmp/execution1279514184559/TDReport.xml
where "/home/lsingh/reporting/tmp/execution1279514184559/TDReport.xml" is my XML data file.
When i looked into the code of "org.eclipse.birt.report.data.oda.xml.util.XMLDataInputStreamCreator" class in the BIRT, I saw that the exeception is coming from following piece of code.
catch (MalformedURLException e)
{
throw new OdaException(e.getLocalizedMessage());
}
It means the code is trying to convert file path specified above into a URL and it fails.
So my question is how a non-windows path is converted into a URL?
should it be prefixed with file:/// ?
Windows or not, all URLs to local files start with file://. That's the protocol prefix.
So your file would be:
file:// + /home/lsingh/reporting/tmp/execution1279514184559/TDReport.xml = file:///home/lsingh/reporting/tmp/execution1279514184559/TDReport.xml
You can try using the file URL:
file:///home/lsingh/reporting/tmp/execution1279514184559/TDReport.xml
If you can post the code than invokes BIRT, it will be easier to analyse the problem.

How to launch a file protocol URL with an anchor from Java?

From a Java program, I need to launch the default browser on a local HTML file, pointed to an anchor inside the file. In Java SE 6, the java.awt.Desktop.browse method will open the file, but will not honor the anchor, so something like the following opens the file at the top, but does not page the browser to the anchor:
Desktop.getDesktop("file:///C:/foo/bar.html#anchor");
Sun says here http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6477862 that anchors are not supported in the file URI protocol.
Does anyone have a better answer?
I can use Java SE 6. I would be OK with a Windows only solution.
I just solved this another way, because no amount of quoting or spaces in any of these examples worked for me.
1 Detect if the file URI has a anchor or query string
2 If so, create a temp file File tmpfile = File.createTempFile("apphelp", ".html") with a meta-redirect to the actual file URI I desire:
<html><head>
<meta http-equiv="refresh" content="0;url=help.html#set_filter" />
</head></html>
3 Execute the local rundll command using new temporary URI:
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler \""
+tmpfile.toURI().toString()+ "\"");
I hope this works for you!
Solution on Windows is:
rundll32 URL.dll, FileProtocolHandler "file:///x:/temp/fragtest.htm#frag"
Mind the quotes!!!
rundll32 URL.dll, FileProtocolHandler file:///x:/temp/fragtest.htm#frag does work as expected.
For Windows only, you could try
System.exec("cmd.exe start file:///C:/foo/bar.html#anchor")
You could try using BrowserLauncher2. It's a small and self-contained cross-platform library to open the default browser. It handles anchors perfectly.
I've done some investigation on this item here - note that opening cmd and typing start file:///c:/temp/test.html#anchor also doesn't work.
I think the only thing that actually works is to call a browser manually (or use a third-party tool that does this).
On Windows, you always have Internet Explorer, so you could call Runtime.getRuntime().exec("cmd.exe start iexplore " + myURL) if you really don't want to find iexplore.exe yourself - but this doesn't always work either.

Categories

Resources