move cache request filter into parent

master
Yixian 3 years ago
parent 5363d298b4
commit f8fa60ed36

@ -1,21 +0,0 @@
package au.com.royalpay.payment.manage;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CacheRequestFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
if (request instanceof CachedBodyServletRequest) {
filterChain.doFilter(request, response);
} else {
CachedBodyServletRequest wrappedRequest = new CachedBodyServletRequest(request);
filterChain.doFilter(wrappedRequest, response);
}
}
}

@ -1,63 +0,0 @@
package au.com.royalpay.payment.manage;
import org.springframework.util.StreamUtils;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.*;
public class CachedBodyServletRequest extends HttpServletRequestWrapper {
private final byte[] content;
public CachedBodyServletRequest(HttpServletRequest request) throws IOException {
super(request);
try (InputStream in = request.getInputStream()) {
content = StreamUtils.copyToByteArray(in);
}
}
@Override
public ServletInputStream getInputStream() throws IOException {
return new CachedBodyServletInputStream(content);
}
@Override
public BufferedReader getReader() throws IOException {
ByteArrayInputStream boi = new ByteArrayInputStream(content);
return new BufferedReader(new InputStreamReader(boi));
}
public static class CachedBodyServletInputStream extends ServletInputStream {
private final InputStream delegate;
public CachedBodyServletInputStream(byte[] content) {
this.delegate = new ByteArrayInputStream(content);
}
@Override
public boolean isFinished() {
try {
return delegate.available() == 0;
} catch (IOException e) {
return true;
}
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return delegate.read();
}
}
}

@ -17,10 +17,6 @@ public class WebConfiguration implements WebMvcConfigurer {
@Resource
private ManagerUserInterceptor managerUserInterceptor;
@Bean
public CacheRequestFilter cacheRequestFilter() {
return new CacheRequestFilter();
}
@Bean
public ShopifyRequestInfoInterceptor shopifyRequestInfoInterceptor() {

@ -1,4 +1,8 @@
app:
http:
cache:
enable: true
path: /
mail:
appid: 1
host: https://mailsupport.royalpay.com.au

Loading…
Cancel
Save