diff --git a/src/main/java/au/com/royalpay/payment/manage/CacheRequestFilter.java b/src/main/java/au/com/royalpay/payment/manage/CacheRequestFilter.java deleted file mode 100644 index 76ac19671..000000000 --- a/src/main/java/au/com/royalpay/payment/manage/CacheRequestFilter.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/au/com/royalpay/payment/manage/CachedBodyServletRequest.java b/src/main/java/au/com/royalpay/payment/manage/CachedBodyServletRequest.java deleted file mode 100644 index 5ceabe716..000000000 --- a/src/main/java/au/com/royalpay/payment/manage/CachedBodyServletRequest.java +++ /dev/null @@ -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(); - } - } -} diff --git a/src/main/java/au/com/royalpay/payment/manage/WebConfiguration.java b/src/main/java/au/com/royalpay/payment/manage/WebConfiguration.java index 40594a1c7..37eb85115 100644 --- a/src/main/java/au/com/royalpay/payment/manage/WebConfiguration.java +++ b/src/main/java/au/com/royalpay/payment/manage/WebConfiguration.java @@ -17,10 +17,6 @@ public class WebConfiguration implements WebMvcConfigurer { @Resource private ManagerUserInterceptor managerUserInterceptor; - @Bean - public CacheRequestFilter cacheRequestFilter() { - return new CacheRequestFilter(); - } @Bean public ShopifyRequestInfoInterceptor shopifyRequestInfoInterceptor() { diff --git a/src/main/resources/application-common.yml b/src/main/resources/application-common.yml index e8639b946..b9fc93dea 100644 --- a/src/main/resources/application-common.yml +++ b/src/main/resources/application-common.yml @@ -1,4 +1,8 @@ app: + http: + cache: + enable: true + path: / mail: appid: 1 host: https://mailsupport.royalpay.com.au