GH-1111 Fix filter registration for serverless-web

Resolves #1111
This commit is contained in:
Oleg Zhurakousky
2024-02-20 15:08:02 +01:00
parent 0b08e8b242
commit 062db0b13d
5 changed files with 98 additions and 25 deletions

View File

@@ -16,17 +16,18 @@
package org.springframework.cloud.function.serverless.web;
import jakarta.servlet.Filter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean;
import org.springframework.boot.web.context.ConfigurableWebServerApplicationContext;
import org.springframework.boot.web.server.WebServer;
import org.springframework.boot.web.server.WebServerException;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletContextInitializerBeans;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.cloud.function.serverless.web.ServerlessMVC.ProxyServletConfig;
@@ -96,9 +97,11 @@ public class ServerlessAutoConfiguration {
logger.info("Configuring Serverless Web Container");
ServerlessServletContext servletContext = new ServerlessServletContext();
servletApplicationContet.setServletContext(servletContext);
this.applicationContext.getBeansOfType(Filter.class).entrySet().forEach(entry -> {
servletContext.addFilter(entry.getKey(), entry.getValue());
});
for (ServletContextInitializer beans : new ServletContextInitializerBeans(this.applicationContext)) {
if (!(beans instanceof DispatcherServletRegistrationBean)) {
beans.onStartup(servletContext);
}
}
}
}
}

View File

@@ -169,6 +169,7 @@ public class ServerlessHttpServletRequest implements HttpServletRequest {
this.servletContext = servletContext;
this.method = method;
this.requestURI = requestURI;
this.pathInfo = requestURI;
this.locales.add(Locale.ENGLISH);
}