diff --git a/pom.xml b/pom.xml index f998c2008479118e3c788d5553e977a9c7fcaec5..4c4403326c5c45b24a8c1cb751a6bf2c24247dd2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ cos jar Cos - 2020.4 + 2022.2 https://gitee.com/jfinal/cos Cos @@ -59,8 +59,8 @@ javax.servlet - servlet-api - 2.5 + javax.servlet-api + 3.1.0 provided diff --git a/src/main/java/com/oreilly/servlet/CacheHttpServlet.java b/src/main/java/com/oreilly/servlet/CacheHttpServlet.java index e3470a25f0f8225c3e1d45866507f07742977075..1f1855d6ab90b0abf4ba764d5a736c633e1b6de4 100644 --- a/src/main/java/com/oreilly/servlet/CacheHttpServlet.java +++ b/src/main/java/com/oreilly/servlet/CacheHttpServlet.java @@ -9,7 +9,7 @@ import java.util.*; import javax.servlet.*; import javax.servlet.http.*; -/** +/** * A superclass for HTTP servlets that wish to have their output * cached and automatically resent as appropriate according to the * servlet's getLastModified() method. To take advantage of this class, @@ -78,7 +78,7 @@ public abstract class CacheHttpServlet extends HttpServlet { // If the client sent an If-Modified-Since header equal or after the // servlet's last modified time, send a short "Not Modified" status code // Round down to the nearest second since client headers are in seconds - if ((servletLastMod / 1000 * 1000) <= + if ((servletLastMod / 1000 * 1000) <= req.getDateHeader("If-Modified-Since")) { res.setStatus(res.SC_NOT_MODIFIED); return; @@ -87,7 +87,7 @@ public abstract class CacheHttpServlet extends HttpServlet { // Use the existing cache if it's current and valid CacheHttpServletResponse localResponseCopy = null; synchronized (lock) { - if (servletLastMod <= cacheLastMod && + if (servletLastMod <= cacheLastMod && cacheResponse.isValid() && equal(cacheQueryString, req.getQueryString()) && equal(cachePathInfo, req.getPathInfo()) && @@ -262,6 +262,11 @@ class CacheHttpServletResponse implements HttpServletResponse { // No need to save the length; we can calculate it later } + @Override + public void setContentLengthLong(long len) { + delegate.setContentLengthLong(len); + } + public void setContentType(String type) { delegate.setContentType(type); contentType = type; @@ -295,106 +300,126 @@ class CacheHttpServletResponse implements HttpServletResponse { out.getBuffer().reset(); } - public boolean isCommitted() { + public boolean isCommitted() { return delegate.isCommitted(); } - public void flushBuffer() throws IOException { + public void flushBuffer() throws IOException { delegate.flushBuffer(); } - public void setLocale(Locale loc) { + public void setLocale(Locale loc) { delegate.setLocale(loc); locale = loc; } - public Locale getLocale() { + public Locale getLocale() { return delegate.getLocale(); } - public void addCookie(Cookie cookie) { + public void addCookie(Cookie cookie) { delegate.addCookie(cookie); cookies.addElement(cookie); } - public boolean containsHeader(String name) { + public boolean containsHeader(String name) { return delegate.containsHeader(name); } - public String getContentType() { + public String getContentType() { return delegate.getContentType(); } /** @deprecated */ - public void setStatus(int sc, String sm) { + public void setStatus(int sc, String sm) { delegate.setStatus(sc, sm); status = sc; } - public void setStatus(int sc) { + public void setStatus(int sc) { delegate.setStatus(sc); status = sc; } - public void setHeader(String name, String value) { + public void setHeader(String name, String value) { delegate.setHeader(name, value); internalSetHeader(name, value); } - public void setIntHeader(String name, int value) { + public void setIntHeader(String name, int value) { delegate.setIntHeader(name, value); internalSetHeader(name, new Integer(value)); } - public void setDateHeader(String name, long date) { + public void setDateHeader(String name, long date) { delegate.setDateHeader(name, date); internalSetHeader(name, new Long(date)); } - public void sendError(int sc, String msg) throws IOException { + public void sendError(int sc, String msg) throws IOException { delegate.sendError(sc, msg); didError = true; } - public void sendError(int sc) throws IOException { + public void sendError(int sc) throws IOException { delegate.sendError(sc); didError = true; } - public void sendRedirect(String location) throws IOException { + public void sendRedirect(String location) throws IOException { delegate.sendRedirect(location); didRedirect = true; } - public String encodeURL(String url) { + public String encodeURL(String url) { return delegate.encodeURL(url); } - public String encodeRedirectURL(String url) { + public String encodeRedirectURL(String url) { return delegate.encodeRedirectURL(url); } - public void addHeader(String name, String value) { + public void addHeader(String name, String value) { internalAddHeader(name, value); } - public void addIntHeader(String name, int value) { + public void addIntHeader(String name, int value) { internalAddHeader(name, new Integer(value)); } - public void addDateHeader(String name, long value) { + public void addDateHeader(String name, long value) { internalAddHeader(name, new Long(value)); } /** @deprecated */ - public String encodeUrl(String url) { + public String encodeUrl(String url) { return this.encodeURL(url); } /** @deprecated */ - public String encodeRedirectUrl(String url) { + public String encodeRedirectUrl(String url) { return this.encodeRedirectURL(url); } + + @Override + public int getStatus() { + return delegate.getStatus(); + } + + @Override + public String getHeader(String name) { + return delegate.getHeader(name); + } + + @Override + public Collection getHeaders(String name) { + return delegate.getHeaders(name); + } + + @Override + public Collection getHeaderNames() { + return delegate.getHeaderNames(); + } } class CacheServletOutputStream extends ServletOutputStream { @@ -425,4 +450,14 @@ class CacheServletOutputStream extends ServletOutputStream { delegate.write(buf, offset, len); cache.write(buf, offset, len); } + + @Override + public boolean isReady() { + return delegate.isReady(); + } + + @Override + public void setWriteListener(WriteListener writeListener) { + delegate.setWriteListener(writeListener); + } } diff --git a/src/main/java/com/oreilly/servlet/MultipartRequest.java b/src/main/java/com/oreilly/servlet/MultipartRequest.java index 947343ca10c8ebff4591d9964d2acba0c8513efa..354cee52ef81a44cb75aed6c18b5b24bfdf1c714 100644 --- a/src/main/java/com/oreilly/servlet/MultipartRequest.java +++ b/src/main/java/com/oreilly/servlet/MultipartRequest.java @@ -67,7 +67,7 @@ import com.oreilly.servlet.multipart.FileRenamePolicy; */ public class MultipartRequest { - private static final int DEFAULT_MAX_POST_SIZE = 1024 * 1024; // 1 Meg + private static final long DEFAULT_MAX_POST_SIZE = 1024 * 1024; // 1 Meg protected Hashtable parameters = new Hashtable(); // name - Vector of values // protected Hashtable files = new Hashtable(); // name - UploadedFile @@ -107,7 +107,7 @@ public class MultipartRequest { */ public MultipartRequest(HttpServletRequest request, String saveDirectory, - int maxPostSize) throws IOException { + long maxPostSize) throws IOException { this(request, saveDirectory, maxPostSize, null, null); } @@ -148,7 +148,7 @@ public class MultipartRequest { */ public MultipartRequest(HttpServletRequest request, String saveDirectory, - int maxPostSize, + long maxPostSize, FileRenamePolicy policy) throws IOException { this(request, saveDirectory, maxPostSize, null, policy); } @@ -170,12 +170,12 @@ public class MultipartRequest { */ public MultipartRequest(HttpServletRequest request, String saveDirectory, - int maxPostSize, + long maxPostSize, String encoding) throws IOException { this(request, saveDirectory, maxPostSize, encoding, null); } - public MultipartRequest(HttpServletRequest request, String saveDirectory, int maxPostSize, String encoding, FileRenamePolicy policy) throws IOException { + public MultipartRequest(HttpServletRequest request, String saveDirectory, long maxPostSize, String encoding, FileRenamePolicy policy) throws IOException { try { parse(request, saveDirectory, maxPostSize, encoding, policy); } @@ -214,7 +214,7 @@ public class MultipartRequest { */ public void parse(HttpServletRequest request, String saveDirectory, - int maxPostSize, + long maxPostSize, String encoding, FileRenamePolicy policy) throws IOException { // Sanity check values @@ -324,7 +324,7 @@ public class MultipartRequest { */ public MultipartRequest(ServletRequest request, String saveDirectory, - int maxPostSize) throws IOException { + long maxPostSize) throws IOException { this((HttpServletRequest)request, saveDirectory, maxPostSize); } diff --git a/src/main/java/com/oreilly/servlet/multipart/BufferedServletInputStream.java b/src/main/java/com/oreilly/servlet/multipart/BufferedServletInputStream.java index 35d1a94bec3553c15a544990bf0ad421aa7167f1..8f16abf71a52711a98c16b1cf3c5ebccf0825daa 100644 --- a/src/main/java/com/oreilly/servlet/multipart/BufferedServletInputStream.java +++ b/src/main/java/com/oreilly/servlet/multipart/BufferedServletInputStream.java @@ -6,6 +6,7 @@ package com.oreilly.servlet.multipart; import java.io.IOException; +import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; /** @@ -195,4 +196,19 @@ public class BufferedServletInputStream extends ServletInputStream { } return total; } + + @Override + public boolean isFinished() { + return in.isFinished(); + } + + @Override + public boolean isReady() { + return in.isReady(); + } + + @Override + public void setReadListener(ReadListener readListener) { + in.setReadListener(readListener); + } } diff --git a/src/main/java/com/oreilly/servlet/multipart/LimitedServletInputStream.java b/src/main/java/com/oreilly/servlet/multipart/LimitedServletInputStream.java index 33a978bca2363ba700366556b45c59a3248883bd..afe2ba0e4f4efa5ee060ee7c5ed2042bc5f6b47a 100644 --- a/src/main/java/com/oreilly/servlet/multipart/LimitedServletInputStream.java +++ b/src/main/java/com/oreilly/servlet/multipart/LimitedServletInputStream.java @@ -6,6 +6,7 @@ package com.oreilly.servlet.multipart; import java.io.IOException; +import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; /** @@ -25,16 +26,16 @@ public class LimitedServletInputStream extends ServletInputStream { private ServletInputStream in; /** number of bytes to read before giving up */ - private int totalExpected; + private long totalExpected; /** number of bytes we have currently read */ - private int totalRead = 0; + private long totalRead = 0; /** * Creates a LimitedServletInputStream with the specified * length limit that wraps the provided ServletInputStream. */ - public LimitedServletInputStream(ServletInputStream in, int totalExpected) { + public LimitedServletInputStream(ServletInputStream in, long totalExpected) { this.in = in; this.totalExpected = totalExpected; } @@ -53,11 +54,12 @@ public class LimitedServletInputStream extends ServletInputStream { * @exception IOException if an I/O error occurs. */ public int readLine(byte b[], int off, int len) throws IOException { - int result, left = totalExpected - totalRead; - if (left <= 0) { + int result; + long left = totalExpected - totalRead; + if (left <= 0L) { return -1; } else { - result = ((ServletInputStream)in).readLine(b, off, Math.min(left, len)); + result = in.readLine(b, off, (int)Math.min(left,len)); } if (result > 0) { totalRead += result; @@ -97,15 +99,31 @@ public class LimitedServletInputStream extends ServletInputStream { * @exception IOException if an I/O error occurs. */ public int read( byte b[], int off, int len ) throws IOException { - int result, left = totalExpected - totalRead; + int result; + long left = totalExpected - totalRead; if (left <= 0) { return -1; } else { - result = in.read(b, off, Math.min(left, len)); + result = in.read(b, off, (int)Math.min(left, len)); } if (result > 0) { totalRead += result; } return result; } + + @Override + public boolean isFinished() { + return in.isFinished(); + } + + @Override + public boolean isReady() { + return in.isReady(); + } + + @Override + public void setReadListener(ReadListener readListener) { + in.setReadListener(readListener); + } } diff --git a/src/main/java/com/oreilly/servlet/multipart/MultipartParser.java b/src/main/java/com/oreilly/servlet/multipart/MultipartParser.java index cfaf7136ecf205371475449c53ec46c48df1011b..82107d61672166e90e8af17d7f2f275d62860cf3 100644 --- a/src/main/java/com/oreilly/servlet/multipart/MultipartParser.java +++ b/src/main/java/com/oreilly/servlet/multipart/MultipartParser.java @@ -98,7 +98,7 @@ public class MultipartParser { * @param maxSize the maximum size of the POST content. */ public MultipartParser(HttpServletRequest req, - int maxSize) throws IOException { + long maxSize) throws IOException { this(req, maxSize, true, true); } @@ -116,7 +116,7 @@ public class MultipartParser { * the request's input stream to prevent trying to * read past the end of the stream. */ - public MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, + public MultipartParser(HttpServletRequest req, long maxSize, boolean buffer, boolean limitLength) throws IOException { this(req, maxSize, buffer, limitLength, null); } @@ -136,7 +136,7 @@ public class MultipartParser { * read past the end of the stream. * @param encoding the encoding to use for parsing, default is ISO-8859-1. */ - public MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, + public MultipartParser(HttpServletRequest req, long maxSize, boolean buffer, boolean limitLength, String encoding) throws IOException { // First make sure we know the encoding to handle chars correctly. @@ -169,7 +169,7 @@ public class MultipartParser { } // Check the content length to prevent denial of service attacks - int length = req.getContentLength(); + long length = req.getContentLengthLong(); if (length > maxSize) { // throw new IOException("Posted content length of " + length + " exceeds limit of " + maxSize); throw new ExceededSizeException("Posted content length of " + length + " exceeds limit of " + maxSize);