public static interface ServerConfig.Builder extends ConfigDataSpec
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_BASE_DIR_MARKER_FILE_PATH
The default name for the base dir sentinel properties file.
|
static String |
DEFAULT_ENV_PREFIX |
static String |
DEFAULT_PROP_PREFIX |
Modifier and Type | Method and Description |
---|---|
ServerConfig.Builder |
add(ConfigSource configSource)
Adds a configuration source.
|
ServerConfig.Builder |
address(InetAddress address)
Sets the address to bind to.
|
ServerConfig |
build()
Builds the server config.
|
ServerConfig.Builder |
configureObjectMapper(Action<ObjectMapper> action)
Configures the object mapper used for binding configuration data to arbitrary objects.
|
ServerConfig.Builder |
connectTimeoutMillis(int connectTimeoutMillis)
The connect timeout of the channel.
|
ServerConfig.Builder |
development(boolean development)
Whether or not the application is "development".
|
ServerConfig.Builder |
env()
Adds a configuration source for environment variables starting with the prefix
"RATPACK_".
|
ServerConfig.Builder |
env(EnvironmentParser environmentParser)
Adds a configuration source for environment variables using custom parsing logic.
|
ServerConfig.Builder |
env(String prefix)
Adds a configuration source for environment variables starting with the specified prefix.
|
ServerConfig.Builder |
env(String prefix,
Function<String,String> mapFunc)
Adds a configuration source for environment variables starting with the specified prefix.
|
ServerConfig.Builder |
json(ByteSource byteSource)
Adds a configuration source for a JSON file.
|
ServerConfig.Builder |
json(Path path)
Adds a configuration source for a JSON file.
|
ServerConfig.Builder |
json(String path)
Adds a configuration source for a JSON file.
|
ServerConfig.Builder |
json(URL url)
Adds a configuration source for a JSON file.
|
ServerConfig.Builder |
maxContentLength(int maxContentLength)
The max number of bytes a request body can be.
|
ServerConfig.Builder |
maxMessagesPerRead(int maxMessagesPerRead)
The maximum number of messages to read per read loop.
|
ServerConfig.Builder |
onError(Action<? super Throwable> errorHandler)
Sets the error all that will be used for added configuration sources.
|
ServerConfig.Builder |
port(int port)
Sets the port to listen for requests on.
|
ServerConfig.Builder |
props(ByteSource byteSource)
Adds a configuration source for a properties file.
|
ServerConfig.Builder |
props(Map<String,String> map)
Adds a configuration source for a Map (flat key-value pairs).
|
ServerConfig.Builder |
props(Path path)
Adds a configuration source for a properties file.
|
ServerConfig.Builder |
props(Properties properties)
Adds a configuration source for a properties object.
|
ServerConfig.Builder |
props(String path)
Adds a configuration source for a properties file.
|
ServerConfig.Builder |
props(URL url)
Adds a configuration source for a properties file.
|
ServerConfig.Builder |
publicAddress(URI publicAddress)
The public address of the application.
|
ServerConfig.Builder |
receiveBufferSize(int receiveBufferSize)
The StandardSocketOptions.SO_RCVBUF option.
|
ServerConfig.Builder |
require(String pointer,
Class<?> type)
Declares that it is required that the server config provide an object of the given type at the given path.
|
ServerConfig.Builder |
requireClientSslAuth(boolean requireClientSslAuth)
The server needs client SSL authentication.
|
ServerConfig.Builder |
ssl(SSLContext sslContext)
The SSL context to use if the application serves content over HTTPS.
|
ServerConfig.Builder |
sysProps()
Adds a configuration source for system properties starting with the prefix "ratpack.".
|
ServerConfig.Builder |
sysProps(String prefix)
Adds a configuration source for system properties starting with the specified prefix.
|
ServerConfig.Builder |
threads(int threads)
The number of threads to use.
|
ServerConfig.Builder |
writeSpinCount(int writeSpinCount)
The maximum loop count for a write operation until WritableByteChannel.write(ByteBuffer) returns a non-zero value.
|
ServerConfig.Builder |
yaml(ByteSource byteSource)
Adds a configuration source for a YAML file.
|
ServerConfig.Builder |
yaml(Path path)
Adds a configuration source for a YAML file.
|
ServerConfig.Builder |
yaml(String path)
Adds a configuration source for a YAML file.
|
ServerConfig.Builder |
yaml(URL url)
Adds a configuration source for a YAML file.
|
getConfigSources, getObjectMapper
static final String DEFAULT_ENV_PREFIX
static final String DEFAULT_PROP_PREFIX
static final String DEFAULT_BASE_DIR_MARKER_FILE_PATH
Value: ".ratpack"
ServerConfig.findBaseDir()
,
Constant Field ValuesServerConfig.Builder port(int port)
Defaults to 5050.
port
- the port to listen for requests onthis
ServerConfig.getPort()
ServerConfig.Builder address(InetAddress address)
Default value is null
.
address
- The address to bind tothis
ServerConfig.getAddress()
ServerConfig.Builder development(boolean development)
Default value is false
.
development
- Whether or not the application is "development".this
ServerConfig.isDevelopment()
ServerConfig.Builder threads(int threads)
Defaults to ServerConfig.DEFAULT_THREADS
threads
- the size of the event loop thread poolthis
ServerConfig.getThreads()
ServerConfig.Builder publicAddress(URI publicAddress)
Default value is null
.
publicAddress
- the public address of the applicationthis
ServerConfig.getPublicAddress()
ServerConfig.Builder maxContentLength(int maxContentLength)
1048576
(1 megabyte).maxContentLength
- the max content length to acceptthis
ServerConfig.getMaxContentLength()
ServerConfig.Builder connectTimeoutMillis(int connectTimeoutMillis)
connectTimeoutMillis
- the connect timeout in millisecondsthis
ServerConfig.getConnectTimeoutMillis()
ServerConfig.Builder maxMessagesPerRead(int maxMessagesPerRead)
maxMessagesPerRead
- the max messages per readthis
ServerConfig.getMaxMessagesPerRead()
ServerConfig.Builder receiveBufferSize(int receiveBufferSize)
receiveBufferSize
- the recieve buffer sizethis
ServerConfig.getReceiveBufferSize()
ServerConfig.Builder writeSpinCount(int writeSpinCount)
writeSpinCount
- the write spin countthis
ServerConfig.getWriteSpinCount()
ServerConfig.Builder ssl(SSLContext sslContext)
sslContext
- the SSL contextthis
SSLContexts
,
ServerConfig.getSSLContext()
ServerConfig.Builder requireClientSslAuth(boolean requireClientSslAuth)
requireClientSslAuth
- whether or not server needs client SSL authenticationthis
ServerConfig.Builder env()
env
in interface ConfigDataSpec
ServerConfig.Builder env(String prefix)
env
in interface ConfigDataSpec
prefix
- the prefix which should be used to identify relevant environment variablesServerConfig.Builder props(ByteSource byteSource)
props
in interface ConfigDataSpec
byteSource
- the source of the properties datathis
ServerConfig.Builder props(String path)
props
in interface ConfigDataSpec
path
- the path to the source of the properties datathis
ServerConfig.Builder props(Path path)
props
in interface ConfigDataSpec
path
- the source of the properties datathis
ServerConfig.Builder props(Properties properties)
props
in interface ConfigDataSpec
properties
- the properties objectthis
ServerConfig.Builder props(Map<String,String> map)
import com.google.common.collect.ImmutableMap;
import ratpack.config.ConfigData;
import ratpack.server.ServerConfig;
import static org.junit.Assert.*;
public class Example {
public static void main(String[] args) throws Exception {
ServerConfig serverConfig = ServerConfig
.noBaseDir()
.props(ImmutableMap.of("server.port", "5060"))
.sysProps()
.build();
assertEquals(5060, serverConfig.getPort());
}
}
props
in interface ConfigDataSpec
map
- the mapthis
ServerConfig.Builder props(URL url)
props
in interface ConfigDataSpec
url
- the source of the properties datathis
ServerConfig.Builder sysProps()
sysProps
in interface ConfigDataSpec
this
ServerConfig.Builder sysProps(String prefix)
sysProps
in interface ConfigDataSpec
prefix
- the prefix which should be used to identify relevant system properties;
the prefix will be removed before loading the datathis
ServerConfig.Builder onError(Action<? super Throwable> errorHandler)
onError
in interface ConfigDataSpec
errorHandler
- the error allthis
Action.noop()
,
Action.throwException()
ServerConfig.Builder configureObjectMapper(Action<ObjectMapper> action)
configureObjectMapper
in interface ConfigDataSpec
action
- an action to perform upon the object mapperthis
ServerConfig.Builder add(ConfigSource configSource)
add
in interface ConfigDataSpec
configSource
- the configuration source to addthis
ServerConfig.Builder env(String prefix, Function<String,String> mapFunc)
env
in interface ConfigDataSpec
prefix
- the prefix which should be used to identify relevant environment variablesmapFunc
- the function to transform segments into field namesServerConfig.Builder env(EnvironmentParser environmentParser)
env
in interface ConfigDataSpec
environmentParser
- the parser to use to interpret environment variablesthis
ServerConfig.Builder json(ByteSource byteSource)
json
in interface ConfigDataSpec
byteSource
- the source of the JSON datathis
ServerConfig.Builder json(Path path)
json
in interface ConfigDataSpec
path
- the source of the JSON datathis
ServerConfig.Builder json(String path)
json
in interface ConfigDataSpec
path
- the path to the source of the JSON datathis
ServerConfig.Builder json(URL url)
json
in interface ConfigDataSpec
url
- the source of the JSON datathis
ServerConfig.Builder yaml(ByteSource byteSource)
yaml
in interface ConfigDataSpec
byteSource
- the source of the YAML datathis
ServerConfig.Builder yaml(Path path)
yaml
in interface ConfigDataSpec
path
- the source of the YAML datathis
ServerConfig.Builder yaml(String path)
yaml
in interface ConfigDataSpec
path
- the path to the source of the YAML datathis
ServerConfig.Builder yaml(URL url)
yaml
in interface ConfigDataSpec
url
- the source of the YAML datathis
ServerConfig.Builder require(String pointer, Class<?> type)
The build()
method will fail if the config is not able to provide the requested object.
All objects declared using this method will also automatically be implicitly added to the base registry.
The pointer
argument is of the same format given to the ConfigData.get(String, Class)
method.
import junit.framework.Assert;
import ratpack.server.ServerConfig;
import ratpack.test.embed.EmbeddedApp;
import java.util.Collections;
public class Example {
static class MyConfig {
public String value;
}
public static void main(String... args) throws Exception {
EmbeddedApp.of(a -> a
.serverConfig(ServerConfig.embedded()
.props(Collections.singletonMap("config.value", "foo"))
.require("/config", MyConfig.class)
)
.handlers(c -> c
.get(ctx -> ctx.render(ctx.get(MyConfig.class).value))
)
).test(httpClient ->
Assert.assertEquals("foo", httpClient.getText())
);
}
}
pointer
- a JSON Pointer specifying the point in the configuration data to bind fromtype
- the class of the type to bind tothis
ServerConfig build()
build
in interface ConfigDataSpec