diff options
Diffstat (limited to '')
-rw-r--r-- | test/java/empty_war/empty.war | bin | 0 -> 484 bytes | |||
-rw-r--r-- | test/java/multipart/app.java | 93 | ||||
-rw-r--r-- | test/java/session_inactive/app.java | 8 |
3 files changed, 100 insertions, 1 deletions
diff --git a/test/java/empty_war/empty.war b/test/java/empty_war/empty.war Binary files differnew file mode 100644 index 00000000..4985e804 --- /dev/null +++ b/test/java/empty_war/empty.war diff --git a/test/java/multipart/app.java b/test/java/multipart/app.java new file mode 100644 index 00000000..c4c89ffb --- /dev/null +++ b/test/java/multipart/app.java @@ -0,0 +1,93 @@ + +import java.io.IOException; +import java.io.PrintWriter; + +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.annotation.MultipartConfig; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.FileOutputStream; +import java.io.OutputStream; +import javax.servlet.http.Part; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet("/") +@MultipartConfig( + fileSizeThreshold = 1024 * 1024 * 1, // 1 MB + maxFileSize = 1024 * 1024 * 10, // 10 MB + maxRequestSize = 1024 * 1024 * 15 // 15 MB +) +public class app extends HttpServlet +{ + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException + { + response.setContentType("text/html;charset=UTF-8"); + + // Create path components to save the file + final String path = request.getParameter("destination"); + final Part filePart = request.getPart("file"); + final String fileName = getFileName(filePart); + + OutputStream out = null; + InputStream filecontent = null; + final PrintWriter writer = response.getWriter(); + + try { + out = new FileOutputStream(new File(path + File.separator + + fileName)); + filecontent = filePart.getInputStream(); + + int read = 0; + final byte[] bytes = new byte[1024]; + + while ((read = filecontent.read(bytes)) != -1) { + out.write(bytes, 0, read); + } + writer.println(fileName + " created at " + path); + + } catch (FileNotFoundException fne) { + writer.println("You either did not specify a file to upload or are " + + "trying to upload a file to a protected or nonexistent " + + "location."); + writer.println("<br/> ERROR: " + fne.getMessage()); + + } finally { + if (out != null) { + out.close(); + } + if (filecontent != null) { + filecontent.close(); + } + if (writer != null) { + writer.close(); + } + } + + return; + } + + private String getFileName(final Part part) { + final String partHeader = part.getHeader("content-disposition"); + + for (String content : part.getHeader("content-disposition").split(";")) + { + if (content.trim().startsWith("filename")) { + return content.substring( + content.indexOf("=") + 1).trim().replace("\"", ""); + } + } + return null; + } +} diff --git a/test/java/session_inactive/app.java b/test/java/session_inactive/app.java index f338fc89..618e4d67 100644 --- a/test/java/session_inactive/app.java +++ b/test/java/session_inactive/app.java @@ -17,7 +17,13 @@ public class app extends HttpServlet HttpSession s = request.getSession(); if (s.isNew()) { - s.setMaxInactiveInterval(2); + String interval = request.getHeader("X-Interval"); + + if (interval == null) { + s.setMaxInactiveInterval(0); + } else { + s.setMaxInactiveInterval(Integer.parseInt(interval)); + } } response.addHeader("X-Session-Id", s.getId()); |