批量替换表前缀调整
This commit is contained in:
parent
c0cd030d0f
commit
109c64e7c2
|
@ -9,8 +9,6 @@ import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.ruoyi.common.enums.HttpMethod;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repeatable 过滤器
|
* Repeatable 过滤器
|
||||||
*
|
*
|
||||||
|
@ -28,15 +26,18 @@ public class RepeatableFilter implements Filter
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException
|
||||||
{
|
{
|
||||||
HttpServletRequest req = (HttpServletRequest) request;
|
ServletRequest requestWrapper = null;
|
||||||
if (HttpMethod.PUT.name().equals(req.getMethod()) || HttpMethod.POST.name().equals(req.getMethod()))
|
if (request instanceof HttpServletRequest)
|
||||||
{
|
{
|
||||||
RepeatedlyRequestWrapper repeatedlyRequest = new RepeatedlyRequestWrapper((HttpServletRequest) request);
|
requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
|
||||||
chain.doFilter(repeatedlyRequest, response);
|
}
|
||||||
|
if (null == requestWrapper)
|
||||||
|
{
|
||||||
|
chain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(requestWrapper, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import javax.servlet.ReadListener;
|
import javax.servlet.ReadListener;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.http.HttpHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建可重复读取inputStream的request
|
* 构建可重复读取inputStream的request
|
||||||
|
@ -20,10 +20,13 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
||||||
{
|
{
|
||||||
private final byte[] body;
|
private final byte[] body;
|
||||||
|
|
||||||
public RepeatedlyRequestWrapper(HttpServletRequest request) throws IOException
|
public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
super(request);
|
super(request);
|
||||||
body = readBytes(request.getReader(), "utf-8");
|
request.setCharacterEncoding("UTF-8");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
|
||||||
|
body = HttpHelper.getBodyString(request).getBytes("UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,10 +38,18 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
||||||
@Override
|
@Override
|
||||||
public ServletInputStream getInputStream() throws IOException
|
public ServletInputStream getInputStream() throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
final ByteArrayInputStream bais = new ByteArrayInputStream(body);
|
final ByteArrayInputStream bais = new ByteArrayInputStream(body);
|
||||||
|
|
||||||
return new ServletInputStream()
|
return new ServletInputStream()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException
|
||||||
|
{
|
||||||
|
return bais.read();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFinished()
|
public boolean isFinished()
|
||||||
{
|
{
|
||||||
|
@ -52,33 +63,10 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReadListener(ReadListener listener)
|
public void setReadListener(ReadListener readListener)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read() throws IOException
|
|
||||||
{
|
|
||||||
return bais.read();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过BufferedReader和字符编码集转换成byte数组
|
|
||||||
*/
|
|
||||||
private byte[] readBytes(BufferedReader br, String encoding) throws IOException
|
|
||||||
{
|
|
||||||
String str = null, retStr = "";
|
|
||||||
while ((str = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
retStr += str;
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(retStr))
|
|
||||||
{
|
|
||||||
return retStr.getBytes(Charset.forName(encoding));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class GenUtils
|
||||||
*/
|
*/
|
||||||
public static String replaceFirst(String replacementm, String[] searchList)
|
public static String replaceFirst(String replacementm, String[] searchList)
|
||||||
{
|
{
|
||||||
String text = StringUtils.EMPTY;
|
String text = replacementm;
|
||||||
for (String searchString : searchList)
|
for (String searchString : searchList)
|
||||||
{
|
{
|
||||||
if (replacementm.startsWith(searchString))
|
if (replacementm.startsWith(searchString))
|
||||||
|
|
Loading…
Reference in New Issue