Spring Boot “Request method 'GET' not supported” while redirecting POST request to https port through Catalina Connector

徘徊边缘 提交于 2019-12-07 07:05:16

问题


I'm trying to redirect http to https through Catalina Connector in my Spring Boot application. If the incoming POST request is "https" then it is working as expected. But if my incoming POST request is "http" and after the redirection to "https" through below code, somewhere it is getting changed to GET because of which I'm getting -

WARN 45028 --- [nio-8443-exec-8] o.s.web.servlet.PageNotFound : Request method 'GET' not supported

Below are the methods in my @SpringBootApplication class:

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(org.apache.catalina.Context context) {
          SecurityConstraint securityConstraint = new SecurityConstraint();
          securityConstraint.setUserConstraint("CONFIDENTIAL");
          SecurityCollection collection = new SecurityCollection();
          collection.addPattern("/*");
          securityConstraint.addCollection(collection);
          context.addConstraint(securityConstraint);
        }
    };

    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    return tomcat;
 }

private Connector initiateHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setPort(10024);
    connector.setSecure(false);
    connector.setRedirectPort(8443);

    return connector;
 }

回答1:


Add collection.addMethod(DEFAULT_PROTOCOL); this line in postProcessContext() override method from code. It working properly with all HTTP request methods like POST,PUT,DELETE,GET etc..



来源:https://stackoverflow.com/questions/39528694/spring-boot-request-method-get-not-supported-while-redirecting-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!