Package io.karatelabs.core
Class MockServer.Builder
java.lang.Object
io.karatelabs.core.MockServer.Builder
- Enclosing class:
MockServer
Builder for creating MockServer instances.
-
Method Summary
Modifier and TypeMethodDescriptionSet initial arguments (variables) for the mock.Set the SSL certificate file path (PEM format).Add a parsed Feature.Add a feature file by path.featureString(String featureContent) Add a feature from inline string content.javaBridgeEnabled(boolean javaBridgeEnabled) Enable Java interop (Java.type(...)) for mock features.Set the SSL private key file path (PEM format).pathPrefix(String prefix) Set a path prefix to strip from incoming requests.port(int port) Set the port to listen on. 0 = dynamic port.requestExpressionsEnabled(boolean requestExpressionsEnabled) Evaluate embedded#(...)expressions found in request-derived data (request/requestHeaders/requestParams).ssl(boolean ssl) Enable SSL/TLS.sslContext(io.netty.handler.ssl.SslContext sslContext) Set a custom Netty SslContext (e.g. for mTLS with client auth).start()Start the mock server.watch(boolean watch) Enable watch mode for hot-reloading feature files when they change.
-
Method Details
-
feature
Add a feature file by path. -
feature
Add a parsed Feature. -
featureString
Add a feature from inline string content. -
port
Set the port to listen on. 0 = dynamic port. -
arg
Set initial arguments (variables) for the mock. -
pathPrefix
Set a path prefix to strip from incoming requests. -
ssl
Enable SSL/TLS. -
certPath
Set the SSL certificate file path (PEM format). -
keyPath
Set the SSL private key file path (PEM format). -
sslContext
Set a custom Netty SslContext (e.g. for mTLS with client auth). When set, certPath/keyPath are ignored. -
watch
Enable watch mode for hot-reloading feature files when they change. The server will check file modification times before each request and reload features if any have changed.Note: Watch mode only works for file-based features, not classpath resources in JARs.
-
javaBridgeEnabled
Enable Java interop (Java.type(...)) for mock features. OFF by default: a mock that assigns request-derived data (request/requestHeaders/requestParams) would otherwise evaluate attacker-controlled embedded expressions with full Java access, which is a remote code execution risk. Only enable for mocks that are not exposed to untrusted clients and genuinely need Java interop. Individual features can also opt in withconfigure javaBridgeEnabled = true. -
requestExpressionsEnabled
Evaluate embedded#(...)expressions found in request-derived data (request/requestHeaders/requestParams). OFF by default: attacker-controlled request data is treated as inert data, not Karate code. Only enable for trusted mocks that intentionally template off request content. Individual features can also opt in withconfigure requestExpressionsEnabled = true. -
start
Start the mock server.
-