diff --git a/zuul-core/src/main/java/com/netflix/zuul/http/HttpServletRequestWrapper.java b/zuul-core/src/main/java/com/netflix/zuul/http/HttpServletRequestWrapper.java index cec3eff2da..f6110d8add 100755 --- a/zuul-core/src/main/java/com/netflix/zuul/http/HttpServletRequestWrapper.java +++ b/zuul-core/src/main/java/com/netflix/zuul/http/HttpServletRequestWrapper.java @@ -27,15 +27,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.RequestDispatcher; import javax.servlet.ServletInputStream; -import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; import java.io.*; import java.net.SocketTimeoutException; import java.net.URLDecoder; -import java.security.Principal; import java.util.*; import java.util.zip.*; @@ -55,7 +51,7 @@ * * @author pgurov */ -public class HttpServletRequestWrapper implements HttpServletRequest { +public class HttpServletRequestWrapper extends javax.servlet.http.HttpServletRequestWrapper { private final static HashMap EMPTY_MAP = new HashMap(); protected static final Logger LOG = LoggerFactory.getLogger(HttpServletRequestWrapper.class); @@ -67,19 +63,23 @@ public class HttpServletRequestWrapper implements HttpServletRequest { private long bodyBufferingTimeNs = 0; public HttpServletRequestWrapper() { + super(groovyTrick()); + } + + private static HttpServletRequest groovyTrick() { //a trick for Groovy throw new IllegalArgumentException("Please use HttpServletRequestWrapper(HttpServletRequest request) constructor!"); } private HttpServletRequestWrapper(HttpServletRequest request, byte[] contentData, HashMap parameters) { + super(request); req = request; this.contentData = contentData; this.parameters = parameters; } public HttpServletRequestWrapper(HttpServletRequest request) { - if (request == null) - throw new IllegalArgumentException("The HttpServletRequest is null!"); + super(request); req = request; } @@ -364,349 +364,6 @@ public String[] getParameterValues(String name) { return arr.clone(); } - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getAuthType() - */ - public String getAuthType() { - return req.getAuthType(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getContextPath() - */ - public String getContextPath() { - return req.getContextPath(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getCookies() - */ - public Cookie[] getCookies() { - return req.getCookies(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String) - */ - public long getDateHeader(String name) { - return req.getDateHeader(name); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String) - */ - public String getHeader(String name) { - return req.getHeader(name); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getHeaderNames() - */ - @SuppressWarnings("unchecked") - public Enumeration getHeaderNames() { - return req.getHeaderNames(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) - */ - @SuppressWarnings("unchecked") - public Enumeration getHeaders(String name) { - return req.getHeaders(name); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String) - */ - public int getIntHeader(String name) { - return req.getIntHeader(name); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getMethod() - */ - public String getMethod() { - return req.getMethod(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getPathInfo() - */ - public String getPathInfo() { - return req.getPathInfo(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getPathTranslated() - */ - public String getPathTranslated() { - return req.getPathTranslated(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getQueryString() - */ - public String getQueryString() { - return req.getQueryString(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getRemoteUser() - */ - public String getRemoteUser() { - return req.getRemoteUser(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getRequestURI() - */ - public String getRequestURI() { - return req.getRequestURI(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getRequestURL() - */ - public StringBuffer getRequestURL() { - return req.getRequestURL(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId() - */ - public String getRequestedSessionId() { - return req.getRequestedSessionId(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getServletPath() - */ - public String getServletPath() { - return req.getServletPath(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getSession() - */ - public HttpSession getSession() { - return req.getSession(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getSession(boolean) - */ - public HttpSession getSession(boolean create) { - return req.getSession(create); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#getUserPrincipal() - */ - public Principal getUserPrincipal() { - return req.getUserPrincipal(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie() - */ - public boolean isRequestedSessionIdFromCookie() { - return req.isRequestedSessionIdFromCookie(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL() - */ - public boolean isRequestedSessionIdFromURL() { - return req.isRequestedSessionIdFromURL(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl() - */ - @SuppressWarnings("deprecation") - public boolean isRequestedSessionIdFromUrl() { - return req.isRequestedSessionIdFromUrl(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid() - */ - public boolean isRequestedSessionIdValid() { - return req.isRequestedSessionIdValid(); - } - - /* (non-Javadoc) - * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String) - */ - public boolean isUserInRole(String role) { - return req.isUserInRole(role); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getAttribute(java.lang.String) - */ - public Object getAttribute(String name) { - return req.getAttribute(name); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getAttributeNames() - */ - @SuppressWarnings("unchecked") - public Enumeration getAttributeNames() { - return req.getAttributeNames(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getCharacterEncoding() - */ - public String getCharacterEncoding() { - return req.getCharacterEncoding(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getContentLength() - */ - public int getContentLength() { - return req.getContentLength(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getContentType() - */ - public String getContentType() { - return req.getContentType(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getLocalAddr() - */ - public String getLocalAddr() { - return req.getLocalAddr(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getLocalName() - */ - public String getLocalName() { - return req.getLocalName(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getLocalPort() - */ - public int getLocalPort() { - return req.getLocalPort(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getLocale() - */ - public Locale getLocale() { - return req.getLocale(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getLocales() - */ - @SuppressWarnings("unchecked") - public Enumeration getLocales() { - return req.getLocales(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getProtocol() - */ - public String getProtocol() { - return req.getProtocol(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getRealPath(java.lang.String) - */ - @SuppressWarnings("deprecation") - public String getRealPath(String path) { - return req.getRealPath(path); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getRemoteAddr() - */ - public String getRemoteAddr() { - return req.getRemoteAddr(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getRemoteHost() - */ - public String getRemoteHost() { - return req.getRemoteHost(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getRemotePort() - */ - public int getRemotePort() { - return req.getRemotePort(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String) - */ - public RequestDispatcher getRequestDispatcher(String path) { - return req.getRequestDispatcher(path); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getScheme() - */ - public String getScheme() { - return req.getScheme(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getServerName() - */ - public String getServerName() { - return req.getServerName(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#getServerPort() - */ - public int getServerPort() { - return req.getServerPort(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#isSecure() - */ - public boolean isSecure() { - return req.isSecure(); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String) - */ - public void removeAttribute(String name) { - req.removeAttribute(name); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object) - */ - public void setAttribute(String name, Object value) { - req.setAttribute(name, value); - } - - /* (non-Javadoc) - * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String) - */ - public void setCharacterEncoding(String env) - throws UnsupportedEncodingException { - req.setCharacterEncoding(env); - } - public static final class UnitTest { @Mock