类 LogHttpServletRequestWrapper
java.lang.Object
javax.servlet.ServletRequestWrapper
javax.servlet.http.HttpServletRequestWrapper
org.hy.microservice.common.LogHttpServletRequestWrapper
- 所有已实现的接口:
javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest
public class LogHttpServletRequestWrapper
extends javax.servlet.http.HttpServletRequestWrapper
Request Body只能读取一次
原因很简单:因为是流。想想看,java中的流也是只能读一次,因为读完之后,position就到末尾了。
思路:第一次读的时候,把流数据暂存起来。后面需要的时候,直接把暂存的数据返回出去。
实现逻辑:
1. 自定义一个HttpServletRequestWrapper,覆写getInputStream()和getReader()方法。
2. 增加一个Filter,在doFilter()中启用自定义的Wrapper
- 版本:
- v1.0
- 作者:
- ZhengWei(HY)
-
字段概要
从接口继承的字段 javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明获取:请求体的数据javax.servlet.ServletInputStream从类继承的方法 javax.servlet.http.HttpServletRequestWrapper
authenticate, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathInfo, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade从类继承的方法 javax.servlet.ServletRequestWrapper
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 javax.servlet.ServletRequest
getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, getContentType, getDispatcherType, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap, getParameterNames, getParameterValues, getProtocol, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
-
构造器详细资料
-
LogHttpServletRequestWrapper
public LogHttpServletRequestWrapper(javax.servlet.http.HttpServletRequest i_Request) throws IOException - 抛出:
IOException
-
-
方法详细资料
-
getBodyString
获取:请求体的数据 -
getReader
- 指定者:
getReader在接口中javax.servlet.ServletRequest- 覆盖:
getReader在类中javax.servlet.ServletRequestWrapper- 抛出:
IOException
-
getInputStream
- 指定者:
getInputStream在接口中javax.servlet.ServletRequest- 覆盖:
getInputStream在类中javax.servlet.ServletRequestWrapper- 抛出:
IOException
-