I have a java program that use PKCS11 and read digital certificates from e-token. This program uses libpkcs11wrapper.dll file. Program runs perfectly fine on local machine. But when I access it via server it gave me error that libpkcs11wrapper.dll file not found. So my question is how I can load the dll file on client machine from server? I have signed the applet. And here is the code which is giving error
File jarPath = new File(applicationPath);
if (!jarPath.isDirectory()) {
jarPath = jarPath.getParentFile();
}
File pkcs11wrapperFile = new File(jarPath, "libpkcs11wrapper" + arch + ".dll");
System.out.println("Absolute path is "+pkcs11wrapperFile.getAbsolutePath());
Pkcs11Shell pkcs11Shell = new Pkcs11Shell(pkcs11wrapperFile.getAbsolutePath());
Related
I'm using IntelliJ and Spring and Java to locally develop an app on a Mac, and then deploy to a tomcat server on AWS, using Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-1048-aws x86_64).
I'm having trouble specifying the file path so that it works in both environments.
My code is
InputStream fileStream = new FileInputStream("src/main/resources/static/web/data/ReportDates.json");
JsonReader reader = Json.createReader(fileStream);
JsonObject reportDates = reader.readObject();
reader.close();
When I run locally, the file is read in correctly. It is located in:
src/main/resources/static/web/data/ReportDates.json
But when I deploy, that code results in the error message:
java.io.FileNotFoundException: src/main/resources/static/web/data/ReportDates.json (No such file or directory)
The actual location of the file on that machine turns out to be:
/opt/tomcat/webapps/automentor/WEB-INF/classes/static/web/data/ReportDates.json
How can I specify the file path so that it works correctly in both environments?
I have given up on using a single path. #Nicholas Pesa got me thinking -- since I use IDEA, I don't have a fixed WEB-INF folder, so it's easier for me to change the path that should be used than to move the file to a fixed location.
My code now uses:
String filepath = (new File("src/main/resources/static/web/data/ReportDates.json").exists()) ? "src/main/resources/static/web/data/ReportDates.json" : "/opt/tomcat/webapps/automentor/WEB-INF/classes/static/web/data/ReportDates.json";
I have a file on S3 which I am downloading using a s3 handler. It gets downloaded to the cloud desktop (where my code is located). I have used the following to get the path:
String home = System.getProperty("user.home");
File file = new File(home+"/Downloads/" + fileName + ".txt");
I want the file to be downloaded to the local machine instead of the cloud desktop. Is there a way to route the file from cloud desktop to local? What can be done to get the file on the local machine instead? Any ideas?
I have installed wkhtmltopdf utility and its accessible via mac terminal. But when I'm trying to access it via java code, I get the following error
Cannot run program "wkhtmltopdf": error=2, No such file or directory
I am using this wrapper of wkhtmltopdf https://github.com/jhonnymertz/java-wkhtmltopdf-wrapper
Same code is perfectly running fine in windows system. So i believe issue is something related to tomcat not able to access the wkhtmltopdf utility.
Here is the code that i am using,
Pdf pdf = new Pdf();
pdf.addPage(serverBasePath + "/htmlview", PageType.url);
// Save the PDF
pdf.saveAs(filePath + "\\" + filename);
You need to tell java-wkhtmltopdf-wrapper were the actual program is on the disk. Try this:
WrapperConfig wc = new WrapperConfig("C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe");
Pdf pdf = new Pdf(wc);
...
pdf.saveAs(...);
I am uploading image file to S3 via the AWS java SDK,
Here is my code:
AmazonS3 s3 = new AmazonS3Client(basicAWSCredentials)
PutObjectRequest putObj = new PutObjectRequest(bucketName, folderPath, getFile(fileName,fileContentToUpload));
putObj.setCannedAcl(CannedAccessControlList.PublicRead);
s3.putObject(putObj);
on windows system its working fine, but on linux its giving following error:
Error Message: Unable to calculate MD5 hash: Chrysanthemum.jpg (No such file or directory)
linux is case sensitive. windows is not.
try to an "ls" and note the case.
use the same case in your program.
File dir = new File(System.getProperty("user.home")+"\\Desktop\\" + svc);
dir.mkdir();
File f;
f = new File(System.getProperty("user.home")+"\\Desktop\\" + svc
+ "\\" + logFile + "_" + System.currentTimeMillis()
+ ".txt");
I am using this code to store the files in the user(client) machine.But it is storing the files in the server machine.Can anyone help me on this? I have deployed my war file in unix server.
Saving a file on a client machine from software running on a server is not as simple as that.
Servers do not have direct access to the file system of any client - it would be very insecure if that were the case.
The simplest way to do this is by making the server return a web page with a link which the user can click to download the file.
You could also do something more complicated, for example write an applet that downloads the file (using some file transfer protocol) and saves it in the local file system. The applet would need to have the appropriate permissions (by default, applets cannot access the local file system).
Seems like this code is part of a Web Application Server Side. In this case System.getProperty("user.home") will return Server's home directory.