Skip to content

Disabling HTTP leads to IllegalStateException "Not listening on HTTP port. Either HTTP is not enabled or the WireMock server is stopped." #183

Description

@meltz-dev

When disabling HTTP in favor for HTTPS, by setting the port to -1 or httpDisabled to true, the application is crashing with the following exception:

java.lang.IllegalStateException: Not listening on HTTP port. Either HTTP is not enabled or the WireMock server is stopped.

	at com.github.tomakehurst.wiremock.common.ParameterUtils.checkState(ParameterUtils.java:54)
	at com.github.tomakehurst.wiremock.WireMockServer.port(WireMockServer.java:209)
	at org.wiremock.spring.internal.WireMockSpringJunitExtension.configureWireMockForDefaultInstance(WireMockSpringJunitExtension.java:80)
	at org.wiremock.spring.internal.WireMockSpringJunitExtension.beforeEach(WireMockSpringJunitExtension.java:38)

The error is caused by this call of a logging statement in WireMockSpringJunitExtension. Regardless of whether http is disabled or not, the port function of the Wiremock instance gets called. However, the port function has a “state checker” and triggers an exception that you can see above when trying to get the (HTTP) port but HTTP was disabled.

 public int port() {
    checkState(
        isRunning() && !options.getHttpDisabled(),
        "Not listening on HTTP port. Either HTTP is not enabled or the WireMock server is stopped.");
    return httpServer.port();
  }

Activity

  1. tomasbjerre commented on Dec 17, 2025

    @tomasbjerre
    Collaborator

    See:

    @EnableWireMock({@ConfigureWireMock(port = -1, httpsPort = 0)})

    That test works. How do you do it?

  2. meltz-dev commented on Dec 17, 2025

    @meltz-dev
    Author

    You are right, when setting the port to -1 and not using httpDisabled it is working!

    The Wiremock documentation says that I should use the “httpDisabled” method to disable HTTP completely.
    https://wiremock.org/docs/https/#:~:text=To%20allow%20only%20HTTPS%20requests%2C%20disable%20HTTP%20by%20adding%3A

    I'm using a WireMockConfigurationCustomizer to configure my keystore paths

    public class WiremockHttpsConfiguration implements WireMockConfigurationCustomizer {
    
        @Override
        public void customize(WireMockConfiguration configuration, ConfigureWireMock options) {
        
            configuration
                ...<key-store-setup>
                .httpDisabled(true); // <- THIS
        }
    }

    On the Test WireMock is configured like this:

    @EnableWireMock(
        {
            @ConfigureWireMock(
                port = -1,
                httpsPort = 0,
                filesUnderClasspath = "mappings",
                configurationCustomizers = { WiremockHttpsConfiguration.class }
            ),
        }
    )

    I'll leave it up to you and other maintainers if this will be classified an issue, I'll just disable HTTP by setting the port to -1 and not using httpDisabled.
    Thank you

  3. jd1 commented on Dec 18, 2025

    @jd1

    I migrated from Spring Cloud Contract which removed the Wiremock dependency in favour of this integration: spring-attic/spring-cloud-contract#2289 and ran into the same issue.

    My existing test work with .httpDisabled(true), but after migrating to wiremock-spring-boot they fail because the Junit Extension uses the HTTP port for logging:

  4. tomasbjerre commented on Dec 18, 2025

    @tomasbjerre
    Collaborator

    I migrated from Spring Cloud Contract which removed the Wiremock dependency in favour of this integration: spring-cloud/spring-cloud-contract#2289 and ran into the same issue.

    The existing test (Spring Cloud Contract auto configuration) work with .httpDisabled(true), but the Junit Extension fails because it uses the HTTP port for logging:

    wiremock-spring-boot/wiremock-spring-boot/src/main/java/org/wiremock/spring/internal/WireMockSpringJunitExtension.java

    Line 80 in 0ff309a

    • wiremock.port()

    Open a new issue and clearly describe what you are doing if you want to report a problem. I don't understand this what you want with this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions