0

I have redirected 'http' (port 8080) traffic to 'https'(port 8443) using self signed certificate and its working fine. but post calls shows 405 (method not allowed) error.

this is my code that used for redirect

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

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

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

      return connector;
    }

This is the configuration that I used,

    server.port=8443
    server.ssl.key-alias=selfsigned_localhost_sslserver
    server.ssl.key-password=changeit
    server.ssl.key-store=classpath:ssl-server.jks
    server.ssl.key-store-provider=SUN
    server.ssl.key-store-type=JKS

1 Answer 1

0

HTTP redirects work by sending a Location header with the new address. The browser will follow this redirect using GET. You can not redirect a POST request because the POST body (eg data) would be lost.

You need to use the correct address.

You could omit the schema in your URLs (eg //myhost.com/foo/bar) as those protocol-relative links always pick up the protocol of the current site.

However, in your case also the port changes. So I would suggest to include the complete URL and take the address from some sort of variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.