diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-07-06 09:09:56 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2015-11-19 09:02:31 +0100 |
commit | 6e0b7b794a0f2e01478fd7a757eee07bae42dad9 (patch) | |
tree | f71f52ec35c64f2b184fc0194ce9dee3fe230d41 /pdf-as-web/src/main/java/at | |
parent | 19dbeeaaaee8ea7d702b7c44ad9dc526923d69e1 (diff) | |
download | pdf-as-4-6e0b7b794a0f2e01478fd7a757eee07bae42dad9.tar.gz pdf-as-4-6e0b7b794a0f2e01478fd7a757eee07bae42dad9.tar.bz2 pdf-as-4-6e0b7b794a0f2e01478fd7a757eee07bae42dad9.zip |
Upload Sizes configurable
Diffstat (limited to 'pdf-as-web/src/main/java/at')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java | 47 | ||||
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java | 9 |
2 files changed, 50 insertions, 6 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java index 2a4b2d39..0ad96b04 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java @@ -89,6 +89,14 @@ public class WebConfiguration implements IConfigurationConstants { public static final String DB_REQUEST_TIMEOUT = "request.db.timeout"; public static final String HIBERNATE_PREFIX = "hibernate.props."; + public static final String UPLOAD_FILESIZE_THRESHOLD = "web.upload.filesizeThreshold"; + public static final String UPLOAD_MAX_FILESIZE = "web.upload.filesizeMax"; + public static final String UPLOAD_MAX_REQUESTSIZE = "web.upload.RequestsizeMax"; + + private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; // 3MB + private static final int MAX_FILE_SIZE = 1024 * 1024 * 40; // 40MB + private static final int MAX_REQUEST_SIZE = 1024 * 1024 * 50; // 50MB + private static Properties properties = new Properties(); private static Properties hibernateProps = new Properties(); @@ -505,4 +513,43 @@ public class WebConfiguration implements IConfigurationConstants { } return false; } + + public static int getFilesizeThreshold() { + String value = properties.getProperty(UPLOAD_FILESIZE_THRESHOLD); + int ivalue = THRESHOLD_SIZE; + if (value != null) { + try { + ivalue = Integer.parseInt(value); + } catch(NumberFormatException e) { + logger.warn(UPLOAD_FILESIZE_THRESHOLD + " not a number", e); + } + } + return ivalue; + } + + public static int getMaxFilesize() { + String value = properties.getProperty(UPLOAD_MAX_FILESIZE); + int ivalue = MAX_FILE_SIZE; + if (value != null) { + try { + ivalue = Integer.parseInt(value); + } catch(NumberFormatException e) { + logger.warn(UPLOAD_MAX_FILESIZE + " not a number", e); + } + } + return ivalue; + } + + public static int getMaxRequestsize() { + String value = properties.getProperty(UPLOAD_MAX_REQUESTSIZE); + int ivalue = MAX_REQUEST_SIZE; + if (value != null) { + try { + ivalue = Integer.parseInt(value); + } catch(NumberFormatException e) { + logger.warn(UPLOAD_MAX_REQUESTSIZE + " not a number", e); + } + } + return ivalue; + } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java index 969aee24..9e217058 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java @@ -65,9 +65,6 @@ public class ExternSignServlet extends HttpServlet { private static final String UPLOAD_PDF_DATA = "pdf-file"; private static final String UPLOAD_DIRECTORY = "upload"; - private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; // 3MB - private static final int MAX_FILE_SIZE = 1024 * 1024 * 40; // 40MB - private static final int MAX_REQUEST_SIZE = 1024 * 1024 * 50; // 50MB private static final Logger logger = LoggerFactory .getLogger(ExternSignServlet.class); @@ -173,13 +170,13 @@ public class ExternSignServlet extends HttpServlet { } else { // configures upload settings DiskFileItemFactory factory = new DiskFileItemFactory(); - factory.setSizeThreshold(THRESHOLD_SIZE); + factory.setSizeThreshold(WebConfiguration.getFilesizeThreshold()); factory.setRepository(new File(System .getProperty("java.io.tmpdir"))); ServletFileUpload upload = new ServletFileUpload(factory); - upload.setFileSizeMax(MAX_FILE_SIZE); - upload.setSizeMax(MAX_REQUEST_SIZE); + upload.setFileSizeMax(WebConfiguration.getMaxFilesize()); + upload.setSizeMax(WebConfiguration.getMaxRequestsize()); // constructs the directory path to store upload file String uploadPath = getServletContext().getRealPath("") |