Both WireMockServer and the WireMockRule take a configuration builder as the parameter to their constructor e.g.

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

WireMockServer wm = new WireMockServer(options().port(2345));

WireMockRule wm = new WireMockRule(options().port(2345));

Every option has a sensible default, so only options that you require an override for should be specified.

Network ports and binding

// Statically set the HTTP port number. Defaults to 8080.

// Statically set the HTTPS port number. Defaults to 8443.

// Randomly assign the HTTP port on startup

// Randomly asssign the HTTPS port on startup

// Bind the WireMock server to this IP address locally. Defaults to the loopback adaptor.

Jetty configuration

Typically it is only necessary to tweak these settings if you are doing performance testing under significant loads.

// Set the number of request handling threads in Jetty. Defaults to 10.

// Set the number of connection acceptor threads in Jetty. Defaults to 2.

// Set the Jetty accept queue size. Defaults to Jetty's default of unbounded.

 // Set the size of Jetty's header buffer (to avoid exceptions when very large request headers are sent). Defaults to 8192.

HTTPS configuration

WireMock can accept HTTPS connections from clients, require a client to present a certificate for authentication, and pass a client certificate on to another service when proxying.

// Set the keystore containing the HTTPS certificate

// Set the password to the keystore

// Set the keystore type

// Require a client calling WireMock to present a client certificate

// Path to the trust store containing the client certificate required in by the previous parameter

// The password to the trust store

The client certificate in the trust store defined in the last two options will also be used when proxying to another service that requires a client certificate for authentication.

Proxy settings

// Make WireMock behave as a forward proxy e.g. via browser proxy settings

// Send the Host header in the original request onwards to the system being proxied to

 // Override the Host header sent when reverse proxying to another system (this and the previous parameter are mutually exclusive)

 // When reverse proxying, also route via the specified forward proxy (useful inside corporate firewalls)
.proxyVia("my.corporate.proxy", 8080)

File locations

WireMock, when started programmatically, will default to src/test/resources as a filesystem root if not configured otherwise.

// Set the root of the filesystem WireMock will look under for files and mappings

// Set a path within the classpath as the filesystem root

Request journal

The request journal records requests received by WireMock. It is required by the verification features, so these will throw errors if it is disabled.

// Do not record received requests. Typically needed during load testing to avoid JVM heap exhaustion.

// Limit the size of the request log (for the same reason as above).

Notification (logging)

WireMock wraps all logging in its own Notifier interface. It ships with no-op, Slf4j and console (stdout) implementations.

// Provide an alternative notifier. The default logs to slf4j.
.notifier(new ConsoleNotifier(true))


For details see Extending WireMock.

// Add extensions
.extensions("com.mycorp.ExtensionOne", "com.mycorp.ExtensionTwo")