This is an automated email from the ASF dual-hosted git repository. jochen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push: new cd03180 Add the package org.apache.fileupload2.jaksrvlt, for compliance with Jakarta Servlet API 5.0. (See https://github.com/apache/commons-fileupload/pull/25.) cd03180 is described below commit cd031805d2618b0c1dd9c90265ebea1a1ce85387 Author: Jochen Wiedmann <jochen.wiedm...@gmail.com> AuthorDate: Mon May 4 14:07:37 2020 +0200 Add the package org.apache.fileupload2.jaksrvlt, for compliance with Jakarta Servlet API 5.0. (See https://github.com/apache/commons-fileupload/pull/25.) --- pom.xml | 9 +- src/changes/changes.xml | 3 + .../fileupload2/jaksrvlt/JakSrvltFileUpload.java | 153 +++++ .../jaksrvlt/JakSrvltRequestContext.java | 130 ++++ .../commons/fileupload2/jaksrvlt/package-info.java | 41 ++ .../apache/commons/fileupload2/util/Streams.java | 9 +- .../jaksrvlt/JakSrvltFileUploadTest.java | 103 ++++ .../jaksrvlt/MockJakSrvltHttpRequest.java | 673 +++++++++++++++++++++ 8 files changed, 1116 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 238f9af..af82532 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ <parent> <groupId>org.apache.commons</groupId> <artifactId>commons-parent</artifactId> - <version>48</version> + <version>50</version> </parent> <artifactId>commons-fileupload2</artifactId> @@ -250,6 +250,12 @@ <artifactId>commons-io</artifactId> <version>2.2</version> </dependency> + <dependency> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> + <version>5.0.0-M1</version> + <scope>provided</scope> + </dependency> </dependencies> <build> @@ -332,6 +338,7 @@ </plugin> </plugins> </pluginManagement> + <defaultGoal>clean verify apache-rat:check clirr:check javadoc:javadoc</defaultGoal> </build> <reporting> diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 805c7a6..d9fa59c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -48,6 +48,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="jochen" type="update">Bumping Compiler Level to 1.8.</action> <action issue="FILEUPLOAD-293" dev="jochen" type="fix">DiskFileItem.write(File) had been changed to use FileUtils.moveFile internally, preventing an existing file as the target.</action> <action issue="FILEUPLOAD-296" dev="jochen" type="fix" due-to="David Georg Reochelt">Performance gains by reusing an internal buffer.</action> + <action dev="jochen" type="add">Add the package org.apache.fileupload2.jaksrvlt, + for compliance with Jakarta Servlet API 5.0. + </action> </release> <release version="1.4" date="2018-12-23" description="1.4 Release"> <action issue="FILEUPLOAD-292" dev="chtompki" type="update">Don't create un-needed resources in FileUploadBase.java</action> diff --git a/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUpload.java b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUpload.java new file mode 100644 index 0000000..b5944f9 --- /dev/null +++ b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUpload.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload2.jaksrvlt; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import jakarta.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload2.FileItem; +import org.apache.commons.fileupload2.FileItemFactory; +import org.apache.commons.fileupload2.FileItemIterator; +import org.apache.commons.fileupload2.FileUpload; +import org.apache.commons.fileupload2.FileUploadBase; +import org.apache.commons.fileupload2.FileUploadException; + +/** + * <p>High level API for processing file uploads.</p> + * + * <p>This class handles multiple files per single HTML widget, sent using + * {@code multipart/mixed} encoding type, as specified by + * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link + * #parseRequest(HttpServletRequest)} to acquire a list of {@link + * org.apache.commons.fileupload2.FileItem}s associated with a given HTML + * widget.</p> + * + * <p>How the data for individual parts is stored is determined by the factory + * used to create them; a given part may be in memory, on disk, or somewhere + * else.</p> + */ +public class JakSrvltFileUpload extends FileUpload { + + /** + * Constant for HTTP POST method. + */ + private static final String POST_METHOD = "POST"; + + // ---------------------------------------------------------- Class methods + + /** + * Utility method that determines whether the request contains multipart + * content. + * + * @param request The servlet request to be evaluated. Must be non-null. + * + * @return {@code true} if the request is multipart; + * {@code false} otherwise. + */ + public static final boolean isMultipartContent( + HttpServletRequest request) { + if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) { + return false; + } + return FileUploadBase.isMultipartContent(new JakSrvltRequestContext(request)); + } + + // ----------------------------------------------------------- Constructors + + /** + * Constructs an uninitialised instance of this class. A factory must be + * configured, using {@code setFileItemFactory()}, before attempting + * to parse requests. + * + * @see FileUpload#FileUpload(FileItemFactory) + */ + public JakSrvltFileUpload() { + super(); + } + + /** + * Constructs an instance of this class which uses the supplied factory to + * create {@code FileItem} instances. + * + * @see FileUpload#FileUpload() + * @param fileItemFactory The factory to use for creating file items. + */ + public JakSrvltFileUpload(FileItemFactory fileItemFactory) { + super(fileItemFactory); + } + + // --------------------------------------------------------- Public methods + + /** + * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> + * compliant {@code multipart/form-data} stream. + * + * @param request The servlet request to be parsed. + * + * @return A list of {@code FileItem} instances parsed from the + * request, in the order that they were transmitted. + * + * @throws FileUploadException if there are problems reading/parsing + * the request or storing files. + */ + public List<FileItem> parseRequest(HttpServletRequest request) throws FileUploadException { + return parseRequest(new JakSrvltRequestContext(request)); + } + + /** + * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> + * compliant {@code multipart/form-data} stream. + * + * @param request The servlet request to be parsed. + * + * @return A map of {@code FileItem} instances parsed from the request. + * + * @throws FileUploadException if there are problems reading/parsing + * the request or storing files. + * + * @since 1.3 + */ + public Map<String, List<FileItem>> parseParameterMap(HttpServletRequest request) + throws FileUploadException { + return parseParameterMap(new JakSrvltRequestContext(request)); + } + + /** + * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a> + * compliant {@code multipart/form-data} stream. + * + * @param request The servlet request to be parsed. + * + * @return An iterator to instances of {@code FileItemStream} + * parsed from the request, in the order that they were + * transmitted. + * + * @throws FileUploadException if there are problems reading/parsing + * the request or storing files. + * @throws IOException An I/O error occurred. This may be a network + * error while communicating with the client or a problem while + * storing the uploaded content. + */ + public FileItemIterator getItemIterator(HttpServletRequest request) + throws FileUploadException, IOException { + return super.getItemIterator(new JakSrvltRequestContext(request)); + } + +} diff --git a/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltRequestContext.java b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltRequestContext.java new file mode 100644 index 0000000..c89b8e2 --- /dev/null +++ b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltRequestContext.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload2.jaksrvlt; + +import static java.lang.String.format; + +import java.io.IOException; +import java.io.InputStream; + +import jakarta.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload2.FileUploadBase; +import org.apache.commons.fileupload2.UploadContext; + +/** + * <p>Provides access to the request information needed for a request made to + * an HTTP servlet.</p> + * + * @since FileUpload 1.1 + */ +public class JakSrvltRequestContext implements UploadContext { + + // ----------------------------------------------------- Instance Variables + + /** + * The request for which the context is being provided. + */ + private final HttpServletRequest request; + + // ----------------------------------------------------------- Constructors + + /** + * Construct a context for this request. + * + * @param request The request to which this context applies. + */ + public JakSrvltRequestContext(HttpServletRequest request) { + this.request = request; + } + + // --------------------------------------------------------- Public Methods + + /** + * Retrieve the character encoding for the request. + * + * @return The character encoding for the request. + */ + @Override + public String getCharacterEncoding() { + return request.getCharacterEncoding(); + } + + /** + * Retrieve the content type of the request. + * + * @return The content type of the request. + */ + @Override + public String getContentType() { + return request.getContentType(); + } + + /** + * Retrieve the content length of the request. + * + * @return The content length of the request. + * @deprecated 1.3 Use {@link #contentLength()} instead + */ + @Override + @Deprecated + public int getContentLength() { + return request.getContentLength(); + } + + /** + * Retrieve the content length of the request. + * + * @return The content length of the request. + * @since 1.3 + */ + @Override + public long contentLength() { + long size; + try { + size = Long.parseLong(request.getHeader(FileUploadBase.CONTENT_LENGTH)); + } catch (NumberFormatException e) { + size = request.getContentLength(); + } + return size; + } + + /** + * Retrieve the input stream for the request. + * + * @return The input stream for the request. + * + * @throws IOException if a problem occurs. + */ + @Override + public InputStream getInputStream() throws IOException { + return request.getInputStream(); + } + + /** + * Returns a string representation of this object. + * + * @return a string representation of this object. + */ + @Override + public String toString() { + return format("ContentLength=%s, ContentType=%s", + Long.valueOf(this.contentLength()), + this.getContentType()); + } + +} diff --git a/src/main/java/org/apache/commons/fileupload2/jaksrvlt/package-info.java b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/package-info.java new file mode 100644 index 0000000..82f5df5 --- /dev/null +++ b/src/main/java/org/apache/commons/fileupload2/jaksrvlt/package-info.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * <p> + * An implementation of + * {@link org.apache.commons.fileupload2.FileUpload FileUpload} + * for use in servlets conforming to the namespace {@code jakarta.servlet}. + * + * </p> + * <p> + * The following code fragment demonstrates typical usage. + * </p> + * <pre> + * DiskFileItemFactory factory = new DiskFileItemFactory(); + * // Configure the factory here, if desired. + * JakSrvltFileUpload upload = new JakSrvltFileUpload(factory); + * // Configure the uploader here, if desired. + * List fileItems = upload.parseRequest(request); + * </pre> + * <p> + * Please see the FileUpload + * <a href="https://commons.apache.org/fileupload/using.html" target="_top">User Guide</a> + * for further details and examples of how to use this package. + * </p> + */ +package org.apache.commons.fileupload2.jaksrvlt; diff --git a/src/main/java/org/apache/commons/fileupload2/util/Streams.java b/src/main/java/org/apache/commons/fileupload2/util/Streams.java index b2ff7ce..cd66b86 100644 --- a/src/main/java/org/apache/commons/fileupload2/util/Streams.java +++ b/src/main/java/org/apache/commons/fileupload2/util/Streams.java @@ -56,10 +56,10 @@ public final class Streams { * @param outputStream The output stream, to which data should * be written. May be null, in which case the input streams * contents are simply discarded. - * @param closeOutputStream True guarantees, that {@link OutputStream#close()} - * is called on the stream. False indicates, that only + * @param closeOutputStream True guarantees, that + * {@link OutputStream#close()} is called on the stream. + * False indicates, that only * {@link OutputStream#flush()} should be called finally. - * * @return Number of bytes, which have been copied. * @throws IOException An I/O error occurred. */ @@ -153,7 +153,8 @@ public final class Streams { * @return The streams contents, as a string. * @throws IOException An I/O error occurred. */ - public static String asString(InputStream inputStream, String encoding) throws IOException { + public static String asString(final InputStream inputStream, final String encoding) + throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copy(inputStream, baos, true); return baos.toString(encoding); diff --git a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java new file mode 100644 index 0000000..0d80386 --- /dev/null +++ b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload2.jaksrvlt; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.Map; + +import jakarta.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload2.Constants; +import org.apache.commons.fileupload2.FileItem; +import org.apache.commons.fileupload2.FileUploadTest; +import org.apache.commons.fileupload2.disk.DiskFileItemFactory; +import org.junit.jupiter.api.Test; + +/** + * Test for {@link ServletFileUpload}. + * + * @see FileUploadTest + * @since 1.4 + */ +public class JakSrvltFileUploadTest { + + /** + * Test case for <a href="https://issues.apache.org/jira/browse/FILEUPLOAD-210"> + */ + @Test + public void parseParameterMap() + throws Exception { + String text = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + + "Content-Type: text/whatever\r\n" + + "\r\n" + + "This is the content of the file\n" + + "\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field\"\r\n" + + "\r\n" + + "fieldValue\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value1\r\n" + + "-----1234\r\n" + + "Content-Disposition: form-data; name=\"multi\"\r\n" + + "\r\n" + + "value2\r\n" + + "-----1234--\r\n"; + byte[] bytes = text.getBytes("US-ASCII"); + HttpServletRequest request = new MockJakSrvltHttpRequest(bytes, Constants.CONTENT_TYPE); + + JakSrvltFileUpload upload = new JakSrvltFileUpload(new DiskFileItemFactory()); + Map<String, List<FileItem>> mappedParameters = upload.parseParameterMap(request); + assertTrue(mappedParameters.containsKey("file")); + assertEquals(1, mappedParameters.get("file").size()); + + assertTrue(mappedParameters.containsKey("field")); + assertEquals(1, mappedParameters.get("field").size()); + + assertTrue(mappedParameters.containsKey("multi")); + assertEquals(2, mappedParameters.get("multi").size()); + } + + + @Test + public void parseImpliedUtf8() + throws Exception { + // utf8 encoded form-data without explicit content-type encoding + String text = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + + "\r\n" + + "Th�s �s the co�te�t of the f�le\n" + + "\r\n" + + "-----1234--\r\n"; + + byte[] bytes = text.getBytes("UTF-8"); + HttpServletRequest request = new MockJakSrvltHttpRequest(bytes, Constants.CONTENT_TYPE); + + DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); + fileItemFactory.setDefaultCharset("UTF-8"); + JakSrvltFileUpload upload = new JakSrvltFileUpload(fileItemFactory); + List<FileItem> fileItems = upload.parseRequest(request); + FileItem fileItem = fileItems.get(0); + assertTrue(fileItem.getString().contains("co�te�t"), fileItem.getString()); + } +} diff --git a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java new file mode 100644 index 0000000..b5d92c7 --- /dev/null +++ b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/MockJakSrvltHttpRequest.java @@ -0,0 +1,673 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload2.jaksrvlt; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + + +import org.apache.commons.fileupload2.FileUploadBase; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.ReadListener; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.Part; + +public class MockJakSrvltHttpRequest implements HttpServletRequest { + + private final InputStream m_requestData; + + private long length; + + private final String m_strContentType; + + private int readLimit = -1; + + private final Map<String, String> m_headers = new java.util.HashMap<String, String>(); + + /** + * Creates a new instance with the given request data + * and content type. + */ + public MockJakSrvltHttpRequest( + final byte[] requestData, + final String strContentType) { + this(new ByteArrayInputStream(requestData), + requestData.length, strContentType); + } + + /** + * Creates a new instance with the given request data + * and content type. + */ + public MockJakSrvltHttpRequest( + final InputStream requestData, + final long requestLength, + final String strContentType) { + m_requestData = requestData; + length = requestLength; + m_strContentType = strContentType; + m_headers.put(FileUploadBase.CONTENT_TYPE, strContentType); + } + + /** + * @see javax.servlet.http.HttpServletRequest#getAuthType() + */ + @Override + public String getAuthType() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getCookies() + */ + @Override + public Cookie[] getCookies() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getDateHeader(String) + */ + @Override + public long getDateHeader(String arg0) { + return 0; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getHeader(String) + */ + @Override + public String getHeader(String headerName) { + return m_headers.get(headerName); + } + + /** + * @see javax.servlet.http.HttpServletRequest#getHeaders(String) + */ + @Override + public Enumeration<String> getHeaders(String arg0) { + // todo - implement + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getHeaderNames() + */ + @Override + public Enumeration<String> getHeaderNames() { + // todo - implement + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getIntHeader(String) + */ + @Override + public int getIntHeader(String arg0) { + return 0; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getMethod() + */ + @Override + public String getMethod() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getPathInfo() + */ + @Override + public String getPathInfo() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getPathTranslated() + */ + @Override + public String getPathTranslated() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getContextPath() + */ + @Override + public String getContextPath() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getQueryString() + */ + @Override + public String getQueryString() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getRemoteUser() + */ + @Override + public String getRemoteUser() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#isUserInRole(String) + */ + @Override + public boolean isUserInRole(String arg0) { + return false; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() + */ + @Override + public Principal getUserPrincipal() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId() + */ + @Override + public String getRequestedSessionId() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getRequestURI() + */ + @Override + public String getRequestURI() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getRequestURL() + */ + @Override + public StringBuffer getRequestURL() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getServletPath() + */ + @Override + public String getServletPath() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getSession(boolean) + */ + @Override + public HttpSession getSession(boolean arg0) { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#getSession() + */ + @Override + public HttpSession getSession() { + return null; + } + + /** + * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() + */ + @Override + public boolean isRequestedSessionIdValid() { + return false; + } + + /** + * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() + */ + @Override + public boolean isRequestedSessionIdFromCookie() { + return false; + } + + /** + * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() + */ + @Override + public boolean isRequestedSessionIdFromURL() { + return false; + } + + /** + * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() + * @deprecated + */ + @Override + @Deprecated + public boolean isRequestedSessionIdFromUrl() { + return false; + } + + /** + * @see javax.servlet.ServletRequest#getAttribute(String) + */ + @Override + public Object getAttribute(String arg0) { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getAttributeNames() + */ + @Override + public Enumeration<String> getAttributeNames() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getCharacterEncoding() + */ + @Override + public String getCharacterEncoding() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#setCharacterEncoding(String) + */ + @Override + public void setCharacterEncoding(String arg0) + throws UnsupportedEncodingException { + } + + /** + * @see javax.servlet.ServletRequest#getContentLength() + */ + @Override + public int getContentLength() { + int iLength = 0; + + if (null == m_requestData) { + iLength = -1; + } else { + if (length > Integer.MAX_VALUE) { + throw new RuntimeException("Value '" + length + "' is too large to be converted to int"); + } + iLength = (int) length; + } + return iLength; + } + + /** + * For testing attack scenarios in SizesTest. + */ + public void setContentLength(long length) { + this.length = length; + } + + /** + * @see javax.servlet.ServletRequest#getContentType() + */ + @Override + public String getContentType() { + return m_strContentType; + } + + /** + * @see javax.servlet.ServletRequest#getInputStream() + */ + @Override + public ServletInputStream getInputStream() throws IOException { + ServletInputStream sis = new MyServletInputStream(m_requestData, readLimit); + return sis; + } + + /** + * Sets the read limit. This can be used to limit the number of bytes to read ahead. + * + * @param readLimit the read limit to use + */ + public void setReadLimit(int readLimit) { + this.readLimit = readLimit; + } + + /** + * @see javax.servlet.ServletRequest#getParameter(String) + */ + @Override + public String getParameter(String arg0) { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getParameterNames() + */ + @Override + public Enumeration<String> getParameterNames() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getParameterValues(String) + */ + @Override + public String[] getParameterValues(String arg0) { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getParameterMap() + */ + @Override + public Map<String, String[]> getParameterMap() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getProtocol() + */ + @Override + public String getProtocol() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getScheme() + */ + @Override + public String getScheme() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getServerName() + */ + @Override + public String getServerName() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getLocalName() + */ + @Override + @SuppressWarnings("javadoc") // This is a Servlet 2.4 method + public String getLocalName() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getServerPort() + */ + @Override + public int getServerPort() { + return 0; + } + + /** + * @see javax.servlet.ServletRequest#getLocalPort() + */ + @Override + @SuppressWarnings("javadoc") // This is a Servlet 2.4 method + public int getLocalPort() { + return 0; + } + + /** + * @see javax.servlet.ServletRequest#getRemotePort() + */ + @Override + @SuppressWarnings("javadoc") // This is a Servlet 2.4 method + public int getRemotePort() { + return 0; + } + + /** + * @see javax.servlet.ServletRequest#getReader() + */ + @Override + public BufferedReader getReader() throws IOException { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getRemoteAddr() + */ + @Override + public String getRemoteAddr() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getLocalAddr() + */ + @Override + @SuppressWarnings("javadoc") // This is a Servlet 2.4 method + public String getLocalAddr() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getRemoteHost() + */ + @Override + public String getRemoteHost() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#setAttribute(String, Object) + */ + @Override + public void setAttribute(String arg0, Object arg1) { + } + + /** + * @see javax.servlet.ServletRequest#removeAttribute(String) + */ + @Override + public void removeAttribute(String arg0) { + } + + /** + * @see javax.servlet.ServletRequest#getLocale() + */ + @Override + public Locale getLocale() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#getLocales() + */ + @Override + public Enumeration<Locale> getLocales() { + return null; + } + + /** + * @see javax.servlet.ServletRequest#isSecure() + */ + @Override + public boolean isSecure() { + return false; + } + + /** + * @see javax.servlet.ServletRequest#getRequestDispatcher(String) + */ + @Override + public RequestDispatcher getRequestDispatcher(String arg0) { + return null; + } + + private static class MyServletInputStream + extends jakarta.servlet.ServletInputStream { + + private final InputStream in; + private final int readLimit; + + /** + * Creates a new instance, which returns the given + * streams data. + */ + public MyServletInputStream(InputStream pStream, int readLimit) { + in = pStream; + this.readLimit = readLimit; + } + + @Override + public int read() throws IOException { + return in.read(); + } + + @Override + public int read(byte b[], int off, int len) throws IOException { + if (readLimit > 0) { + return in.read(b, off, Math.min(readLimit, len)); + } + return in.read(b, off, len); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + throw new IllegalStateException("Not implemented"); + } + + } + + @Override + public long getContentLengthLong() { + return (long) getContentLength(); + } + + @Override + public ServletContext getServletContext() { + final HttpSession session = getSession(); + if (session == null) { + return null; + } else { + return session.getServletContext(); + } + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + throw new IllegalStateException("Not implemented"); + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) + throws IllegalStateException { + throw new IllegalStateException("Not implemented"); + } + + @Override + public boolean isAsyncStarted() { + return false; + } + + @Override + public boolean isAsyncSupported() { + return false; + } + + @Override + public AsyncContext getAsyncContext() { + return null; + } + + @Override + public DispatcherType getDispatcherType() { + return null; + } + + @Override + public String changeSessionId() { + return null; + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { + return false; + } + + @Override + public void login(String username, String password) throws ServletException { + throw new IllegalStateException("Not implemented"); + } + + @Override + public void logout() throws ServletException { + throw new IllegalStateException("Not implemented"); + } + + @Override + public Collection<Part> getParts() throws IOException, ServletException { + return null; + } + + @Override + public Part getPart(String name) throws IOException, ServletException { + return null; + } + + @Override + public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException { + throw new IllegalStateException("Not implemented"); + } + + @Override + public String getRealPath(String path) { + return null; + } +}