Skip to content

Commit

Permalink
Ensure compatibility with 4.x servlet API
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Nov 4, 2023
1 parent 7d54563 commit e448aca
Show file tree
Hide file tree
Showing 5 changed files with 430 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.IOException;
import java.io.OutputStream;

Expand Down Expand Up @@ -61,5 +62,15 @@ public void write(final byte[] b) throws IOException {
public void write(final byte[] b, final int off, final int len) throws IOException {
stream.write(b, off, len);
}

@Override
public boolean isReady() {
return true;
}

@Override
public void setWriteListener(WriteListener writeListener) {
//
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@
import org.tuckey.web.filters.urlrewrite.UrlRewriter;
import org.tuckey.web.filters.urlrewrite.utils.Log;

import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUpgradeHandler;
import javax.servlet.http.Part;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -57,6 +64,7 @@
import java.net.URL;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
Expand Down Expand Up @@ -308,6 +316,11 @@ public HttpSession getSession() {
return null;
}

@Override
public String changeSessionId() {
return null;
}

public boolean isRequestedSessionIdValid() {
return false;
}
Expand All @@ -320,6 +333,36 @@ public boolean isRequestedSessionIdFromURL() {
return false;
}

@Override
public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException {
return false;
}

@Override
public void login(String s, String s1) throws ServletException {

}

@Override
public void logout() throws ServletException {

}

@Override
public Collection<Part> getParts() throws IOException, ServletException {
return null;
}

@Override
public Part getPart(String s) throws IOException, ServletException {
return null;
}

@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> aClass) throws IOException, ServletException {
return null;
}

/**
* @deprecated
*/
Expand Down Expand Up @@ -349,6 +392,11 @@ public int getContentLength() {
return contentLength;
}

@Override
public long getContentLengthLong() {
return 0;
}

public String getContentType() {
return contentType;
}
Expand Down Expand Up @@ -448,6 +496,41 @@ public int getLocalPort() {
return localPort;
}

@Override
public ServletContext getServletContext() {
return null;
}

@Override
public AsyncContext startAsync() throws IllegalStateException {
return null;
}

@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException {
return null;
}

@Override
public boolean isAsyncStarted() {
return false;
}

@Override
public boolean isAsyncSupported() {
return false;
}

@Override
public AsyncContext getAsyncContext() {
return null;
}

@Override
public DispatcherType getDispatcherType() {
return null;
}

public void setServerPort(int i) {
serverPort = i;
}
Expand Down Expand Up @@ -651,6 +734,11 @@ public void setContentLength(int i) {

}

@Override
public void setContentLengthLong(long l) {

}

public void setContentType(String s) {

}
Expand Down Expand Up @@ -691,6 +779,16 @@ public String getHeader(String s) {
return (String) responseHeaders.get(s);
}

@Override
public Collection<String> getHeaders(String s) {
return null;
}

@Override
public Collection<String> getHeaderNames() {
return null;
}

public int getStatus() {
return status;
}
Expand Down
89 changes: 87 additions & 2 deletions src/test/java/org/tuckey/web/testhelper/MockRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@
*/
package org.tuckey.web.testhelper;

import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUpgradeHandler;
import javax.servlet.http.Part;
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.CharArrayReader;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
Expand Down Expand Up @@ -209,10 +219,15 @@ public HttpSession getSession() {
return session;
}

@Override
public String changeSessionId() {
return null;
}

public MockSession getMockSession() {
return session;
}

public boolean isRequestedSessionIdValid() {
return requestedSessionIdValid;
}
Expand All @@ -225,6 +240,36 @@ public boolean isRequestedSessionIdFromURL() {
return requestedSessionIdFromURL;
}

@Override
public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException {
return false;
}

@Override
public void login(String s, String s1) throws ServletException {

}

@Override
public void logout() throws ServletException {

}

@Override
public Collection<Part> getParts() throws IOException, ServletException {
return null;
}

@Override
public Part getPart(String s) throws IOException, ServletException {
return null;
}

@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> aClass) throws IOException, ServletException {
return null;
}

/**
* @deprecated
*/
Expand Down Expand Up @@ -254,6 +299,11 @@ public int getContentLength() {
return contentLength;
}

@Override
public long getContentLengthLong() {
return 0;
}

public String getContentType() {
return contentType;
}
Expand Down Expand Up @@ -357,6 +407,41 @@ public int getLocalPort() {
return localPort;
}

@Override
public ServletContext getServletContext() {
return null;
}

@Override
public AsyncContext startAsync() throws IllegalStateException {
return null;
}

@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException {
return null;
}

@Override
public boolean isAsyncStarted() {
return false;
}

@Override
public boolean isAsyncSupported() {
return false;
}

@Override
public AsyncContext getAsyncContext() {
return null;
}

@Override
public DispatcherType getDispatcherType() {
return null;
}

public void setServerPort(int i) {
serverPort = i;
}
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/org/tuckey/web/testhelper/MockResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
package org.tuckey.web.testhelper;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -177,6 +179,11 @@ public void setContentLength(int i) {

}

@Override
public void setContentLengthLong(long l) {

}

public void setContentType(String s) {

}
Expand Down Expand Up @@ -217,6 +224,16 @@ public String getHeader(String s) {
return (String) responseHeaders.get(s);
}

@Override
public Collection<String> getHeaders(String s) {
return null;
}

@Override
public Collection<String> getHeaderNames() {
return null;
}

public int getStatus() {
return status;
}
Expand All @@ -238,6 +255,16 @@ public MockSerlvetOutputStream() {
this.baos = new ByteArrayOutputStream();
}

@Override
public boolean isReady() {
return false;
}

@Override
public void setWriteListener(WriteListener writeListener) {

}

public void write(int b) throws IOException {
baos.write(b);
}
Expand Down
Loading

0 comments on commit e448aca

Please sign in to comment.