Я написал фильтр, который не делает ничего, кроме проверки размера запроса на соответствие настраиваемому максимуму и возвращает 413, если запрос слишком велик .
Код: Выделить всё
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
@Slf4j
public class RequestSizeFilter implements Filter {
@Value("${fam.max_request_size:10485760}")
private int maxContentBytes;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException {
try {
if (request.getContentLength() > maxContentBytes) {
throw new RuntimeException();
} else {
chain.doFilter(request, response);
}
} catch (Exception e) {
log.error("Detected overlarge request of %s bytes. Rejecting.".formatted(request.getContentLength()));
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
httpResponse.getWriter().println("Request exceeds maximum size of %s bytes".formatted(maxContentBytes));
}
}
}
Код: Выделить всё
org.springframework.web.reactive.function.client.WebClientRequestException: Connection refused: localhost/[0:0:0:0:0:0:0:1]:8080
at app//org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:137)
Caused by:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/[0:0:0:0:0:0:0:1]:8080
Caused by:
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:336)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:1583)
Интересно Дело в том, что если я отключу тест, запускающий этот фильтр, все остальные тесты пройдут. Кроме того, поскольку порядок тестов не гарантирован, я знаю, что тот же тест, который проходит до теста, запускающего этот фильтр, завершится неудачно, если он будет выполнен после него. Должно быть, фильтр оставляет сервер в каком-то нестабильном состоянии, но я не могу определить, как и почему. Нужен ли мне какой-то звонок, чтобы вернуть службу в состояние, когда она снова готова принимать входящие соединения?
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-connect