• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

Java Issues-Permissions Denied-Plesk12.0

SamirM

Basic Pleskian
Hi,
i run a VPS with CentOS 7.1 and Plesk 12.0.18 and tomcat 7.0, am having issues with permissions even though all permissions have been enabled. The site runs a page for sellers to add their profile and product images, and when they upload the images, the following error is reported:

type Exception report

message java.io.FileNotFoundException: /var/www/vhosts/domain.com/httpdocs/uploads (Permission denied)

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.io.IOException: java.io.FileNotFoundException: /var/www/vhosts/perkmart.com/httpdocs/uploads (Permission denied)
Upload.doPost(Upload.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.io.FileNotFoundException: /var/www/vhosts/domain.com/httpdocs/uploads (Permission denied)
java.io.FileOutputStream.open(Native Method)
java.io.FileOutputStream.<init>(FileOutputStream.java:221)
java.io.FileOutputStream.<init>(FileOutputStream.java:171)
org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:377)
Upload.doPost(Upload.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.


the uploads folder has the following permissions : rwx-rwx-rw
the java code for the uploads is :

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@WebServlet("/upload")
@MultipartConfig(fileSizeThreshold = 1024 * 1024 * 2, // 2MB
maxFileSize = 1024 * 1024 * 10, // 10MB
maxRequestSize = 1024 * 1024 * 50) // 50MB
public class Upload extends HttpServlet {

/**
* Name of the directory where uploaded files will be saved, relative to the
* web application directory.
*/
private static final String SAVE_DIR = "domain.com/uploads/buyer_profile_photos/";

/**
* handles file upload
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// gets absolute path of the web application
// constructs path of the directory to save uploaded file

File fileSaveDir = new File(SAVE_DIR);
if (!fileSaveDir.exists()) {
fileSaveDir.mkdir();
}

for (Part part : request.getParts()) {
String fileName = extractFileName(part);
part.write(savePath + File.separator + fileName);
}
PrintWriter printWriter = response.getWriter();
printWriter.print(request.getServletContext().getRealPath(""));

}

/**
* Extracts file name from HTTP header content-disposition
*/
private String extractFileName(Part part) {
String contentDisp = part.getHeader("content-disposition");
String[] items = contentDisp.split(";");
for (String s : items) {
if (s.trim().startsWith("filename")) {
return s.substring(s.indexOf("=") + 2, s.length() - 1);
}
}
return "";
}
}


can anyone help in identifying the cause of this error

thanks\
samir
 
Thnx UFHH01, i have enabled "777" permissions to the folder, but i still get the same error.....any suggestions
 
i got this one sorted, apparently it was a SELINUX issue which was enabled, made it permissive and it started working, thnx UFHH01
 
Back
Top