How to enable HTTPS for standalone Wiremock

后端 未结 2 994
北恋
北恋 2021-01-03 03:12

Overview:

I used wiremock standalone 2.1.11 and did the following to enable HTTPS URL for my request but to no avail:

  • Studying the d
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 03:44

    I faced this issue where I wanted to mock one https ajax call to third party which is invoked during the page load. Our original wiremock setup was done on http and hence we were getting the error

     was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint
    

    To fix that I simply need to enable the Wiremock server to listen on Secure port (Please see the bold part of the code). Please see below the UtilityClass which starts stop the WireMock Server before each tests.

    public class WireMockHook {
        public static final int WIREMOCK_PORT_NUMBER = 8089;
        public static final int WIREMOCK_SECURE_PORT_NUMBER = 8043;
        public static final String WIREMOCK_HOST = "localhost";
        private WireMockServer wireMockServer;
    
        @Before(order = 0)
        public void startWireMock() {
            wireMockServer = new WireMockServer(wireMockConfig().httpsPort(WIREMOCK_SECURE_PORT_NUMBER).port(WIREMOCK_PORT_NUMBER));
            wireMockServer.start();
            configureFor(WIREMOCK_HOST, WIREMOCK_PORT_NUMBER);
        }
    
        @After(order = 0)
        public void stopWireMock() {
            wireMockServer.stop();
        }
    }
    

提交回复
热议问题