我遇到了这个 url,它表明可以添加一个 Http Handler(示例在 Spring 1.x 中)。 https://lists.jboss.org/pipermail/undertow-dev/2017-March/001938.html
我尝试添加以下代码 - 除非我添加侦听器,否则它似乎不会被调用。不幸的是,Spring 似乎已经添加了一个监听器。想要做的是用我的 Http 处理程序更新 Spring 的侦听器。我只是不知道该怎么做。
很感谢任何形式的帮助。
@Component
@Slf4j
public class LibCoreEmbeddedServletCustomerizer implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
@Value("${same.site.string}")
private String sameSiteString;
@Value("${server.port}")
private int serverPort;
@Value("${server.address}")
private String serverAddress;
@Override
public void customize(UndertowServletWebServerFactory factory) {
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override
public void customize(Undertow.Builder builder) {
log.debug("LibCoreEmbeddedServletCustomerizer::customize");
UndertowBuilderCustomizer customizer = new UndertowBuilderCustomizer() {
@Override
public void customize(Undertow.Builder builder) {
builder.
//addHttpListener(serverPort, serverAddress)
setHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange httpServerExchange) throws Exception {
Map<String, Cookie> cookies = httpServerExchange.getResponseCookies();
log.debug(Encode.log(String.format("UndertowServletWebServerFactory handleRequest sameSiteString=%s", sameSiteString)));
for (Cookie cookie:cookies.values()) {
log.debug(Encode.log(String.format("UndertowServletWebServerFactory handleRequest cookie=%s", cookie)));
cookie.setSameSiteMode(sameSiteString);
}
}
});
}
};
factory.addBuilderCustomizers(customizer);
}
});
}
}