Writing files to a user directory temporary folder using Java in Websphere 9 - java-8

I have an application which has multipart file attachment module. In this, I have created a logic which writes the files to the local application server(Tomcat in my case) temp folder and gets deleted once it has been uploaded.
I used this logic for creating files,
File tmpFile = new File(System.getProperty("user.install.root") + File.separator + file.getOriginalFilename());
file.transferTo(tmpFile);
This works as expected in Tomcat, but deploying the same in Websphere 9 environment, throws the below exception,
[11/13/17 20:20:45:946 IST] 000000f2 SystemErr R Caused by:
java.io.FileNotFoundException: C:\Program
Files\IBM\WebSphere\AppServer_1\profiles\AppSrv01\temp\WIN7VSNode04\server1\project name\project name.war\null\tmpfiles\uploaded file.extension
(The system cannot find the path specified.)
What might be the issue here?
Thanks in advance.

A variable is null when you're concatenating the path:
...\project name.war\null\tmpfiles\...
^^^^
Fix that and it should probably work.

Related

MapProxy + GeoServer

On our Client's environment we setup a MapProxy+GeoServer for maps needed for their application. During the MapProxy seeding process which calls the Layers on GeoServer, the following exception is thrown :
[2019-12-31 14:23:20,179] mapproxy.source.wms - WARNING - no image returned from source WMS: http://localhost:8080/geoserver/spin/wms?styles=&format=image%2Fpng&height=224&bbox=-24178.5164836,627512.999999,-4570.27472539,629467.0&transparent=True&layers=Grotere_Steden&service=WMS&width=2248&request=GetMap&srs=EPSG%3A28992&version=1.1.1, response was: <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE ServiceExceptionReport SYSTEM "http://localhost:8080/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1" > <ServiceException>
java.lang.RuntimeException: java.io.FileNotFoundException: /usr/share/tomcat/webapps/geoserver/data/usr/share/tomcat/webapps/geoserver/data/data/spin/Grotere_Steden.shp (No such file or directory)
java.io.FileNotFoundException: /usr/share/tomcat/webapps/geoserver/data/usr/share/tomcat/webapps/geoserver/data/data/spin/Grotere_Steden.shp (No such file or directory)
/usr/share/tomcat/webapps/geoserver/data/usr/share/tomcat/webapps/geoserver/data/data/spin/Grotere_Steden.shp (No such file or directory)
</ServiceException></ServiceExceptionReport>
The fix needed seems to be on GeoServer side.
The path that needs to be constructed is : "usr/share/tomcat/webapps/geoserver/data/data/spin/Grotere_Steden.shp" (which was the case earlier. )
But on a new installation in a new machine the path generated is : "/usr/share/tomcat/webapps/geoserver/data/usr/share/tomcat/webapps/geoserver/data/data/spin/Grotere_Steden.shp"
I dont understand the change in the construction of the path to the layer file. Please could someone help me with this?

Pig register jar, file does not exist error

I'm using Hortonworks sandbox and trying to run a simple pig script. There appear to be annoying error related to "file does not exist".
Below is the script:
REGISTER '/piggybank.jar';
inp = load '/my.csv' USING org.apache.pig.piggybank.storage.CSVExcelStorage..
ERROR 2997: Encountered IOException. File does not exist:
hdfs://sandbox.hortonworks.com:8020/tmp/udfs/ '/piggybank.jar'
However, my jar is present at the root(/) and I have given proper permission as well. Don't know why the path is pointing to /tmp/udfs....
Can anyone provide some suggestion?
Do not place the path within quotes. Also provide full URI of the Jar file location.
REGISTER hdfs://sandbox.hortonworks.com:8020/piggybank.jar;
Refer REGISTER (a jar/script).

"Could not open the ID file" in Websphere

The following code I can run without problem within Tomcat,
Session session = NotesFactory.createSession((String)null, (String)null, "password");
but in Websphere, I got exception below:
SystemErr R NotesException: Could not open the ID file
SystemErr R at lotus.domino.local.Session.NCreateSessionWithPasswd(Native Method)
SystemErr R at lotus.domino.local.Session.createSession(Unknown Source)
SystemErr R at lotus.domino.NotesFactory.createSessionUP(Unknown Source)
SystemErr R at lotus.domino.NotesFactory.createSession(Unknown Source)
It is so wired, I did check the ID file existence, at the same computer, I can also execute Lutos Notes client without problem. I really have no idea now what I can do now? Please advise.
Check the credentials under which Websphere is running. It may not be the same as Tomcat and may not have access to the file.
Another typical problem is that the lotus.domino classes may not be able to find the path to the notes.ini file. The Notes client typically avoids this problem by putting the path into the command line in the desktop shortcut. Try adding the folder containing the notes.ini file to the PATH environment variable.
Check your imports. You should import classes from lotus.domino package. Your problem is in using wrong classes (from lotus.domino.local packages), which require instalation of Notes client on machine where code runs. That's why it works on your Tomcat (local, I assume) and fails on deployment.
What you need is to use CORBA/DIIOP to access Domino from your code. Alter your code to get session accordingly.
http://www.ibm.com/developerworks/lotus/library/ls-Java_access_pt1/
http://www.ibm.com/developerworks/lotus/library/ls-Java_access_2/
Please asign the mail id with network path like '\xxxxx\xxx\xxx.id', and make sure your service account can access the location.

Error while working with Informatica Design SDK for creating mapping

I have found the mapping sdk code samples, however without any documentation whatsoever.
Currently working with 9.0, I am looking for more info.
For one of the current issues, when I try to save the mapping to repository, (with pcconfig.properties lying in the same folder where the xml file is being generated), I am getting the following error:
Written the file..
Caught an exception in run() method
java.io.IOException: Cannot run program ""C:\Informatica\pmrep"" (in directory "C:\Informatica"): CreateProcess error=2, The system cannot find the file specified
java.io.IOException: Cannot run program ""C:\Informatica\pmrep"" (in directory "C:\Informatica"): CreateProcess error=2, The system cannot find the file specified
com.informatica.powercenter.sdk.mapfwk.exception.MapFwkOutputException: Error saving to repository : Failed to connect to repository
at com.informatica.powercenter.sdk.mapfwk.xml.XMLWriter.save(Unknown Source)
at com.informatica.powercenter.sdk.mapfwk.repository.Repository.save(Unknown Source)
at TestRaghavExample.generateOutput(TestRaghavExample.java:259)
at TestRaghavExample.create(TestRaghavExample.java:64)
at TestRaghavExample.main(TestRaghavExample.java:272)
Caught an exception in run() method
This is my initial example.. trying to find my way through the API..
The path to the pmrep utility doesn't look correct. It is normally found at the path C:\Informatica\<version>\server\bin on Windows.
Check the value of PC_CLIENT_INSTALL_PATH within pcconfig.properties is correct.

Uploading files with Spring

I'm uploading multiple Excel files to a server. For files, I use the CommonsMultiPartFile class. My problem is that when I try to handle file uploaded like
File KUStiedosto = new File(form.getKUS().getOriginalFilename());
form.getKUS().transferTo(KUStiedosto);
Workbook KUStk = Workbook.getWorkbook(KUStiedosto);
Sheet KUSl = KUStk.getSheet(0);
for (int r = 7; r < KUSl.getRows() - 1; r++) {
I get
java.io.FileNotFoundException: 2601401KUS1007.xls (Access is denied)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:179)
java.io.FileOutputStream.<init>(FileOutputStream.java:131)
org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:423)
org.springframework.web.multipart.commons.CommonsMultipartFile.transferTo(CommonsMultipartFile.java:137)
fi.utu.seurantaraporttisuodatin.service.Kustannusraportti.calculateKUS(Kustannusraportti.java:27)
fi.utu.seurantaraporttisuodatin.service.Raportti.createReportContext(Raportti.java:424)
fi.utu.seurantaraporttisuodatin.controller.FormController.onSubmit(FormController.java:68)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:174)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
What do I have to do with my server's rights or is there something else too? I'm using Netbeans and a Tomcat server attached to it.
You'd have to give the write permission to the user running the server (tomcat?) for the folder where you are placing the file.
When you call CommonsMultipartFile.transferTo(), you're passing a reference to a File location to which it should write the uploaded file. However, your tomcat server does not have write permission to that file.
You need to find out which user Tomcat is running as, and make sure that user has write access to that file location.
I had this issue in my Windows 7 box. Its mainly because of the access restrictions.
You have 2 options:
I could able to write the file to my
Desktop though. Try writing the file
to your desktop to check whether
your code works.
Run the Tomcat as Administrator. Copy the War to your tomcat's
webapps folder. Type Windows Key
and Search for cmd. Right click on
the cmd.exe and run it as
Administrator. Now navigate to the
Tomcat's bin folder and run
startup.bat. Now you could able to save the file in any location.

Resources