Please note that I am very new to Ubuntu server and linux in general.
I have a java script that downloads an xml file from a url and imports it into my database. It works fine on my local machine, but after uploading it to my vps (which uses ubuntu 18.04 and Tomcat), I get the following error when running the script:
java.nio.file.AccessDeniedException: f1e4485c8f9fed7e4af0672c5f8bd0d0.xml
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[na:na]
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[na:na]
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[na:na]
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219) ~[na:na]
at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478) ~[na:na]
at java.base/java.nio.file.Files.newOutputStream(Files.java:219) ~[na:na]
at java.base/java.nio.file.Files.copy(Files.java:3066) ~[na:na]
at com.keuzestress.api.keuzestressapi.resource.xml.CoolblueImport.doImport(CoolblueImport.java:53) ~[classes/:0.0.1-SNAPSHOT]
at com.keuzestress.api.keuzestressapi.resource.xml.CoolblueImport$$FastClassBySpringCGLIB$$de9a1a6.invoke(<generated>) ~[classes/:0.0.1-SNAPSHOT]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
...
It is clear to me that there is some kind of permissions issue. What I don't know is where the file is saved. I tried checking the tomcat subfolders but I couldn't find out what folder I should give the appropriate permissions.
The java import script:
@Component
public class CoolblueImport implements importInterface{
public List<CoolblueProduct> coolblueProductList = new ArrayList<>();
public List<Product> productList = new ArrayList<>();
String url = "http://feeds.performancehorizon.com/.../f1e4485c8f9fed7e4af0672c5f8bd0d0.xml";
Logger logger = LoggerFactory.getLogger(CoolblueImport.class);
@Autowired
ProductRepository productRepository;
@Transactional
public List<Product> doImport() throws ParserConfigurationException, IOException, SAXException {
coolblueProductList.clear();
InputStream in = new URL(url).openStream();
Files.copy(in, Paths.get("f1e4485c8f9fed7e4af0672c5f8bd0d0.xml"), StandardCopyOption.REPLACE_EXISTING);
File file = new File("f1e4485c8f9fed7e4af0672c5f8bd0d0.xml");
...
Thanks in advance! Any help is welcome :)