Search in sources :

Example 1 with ServerConfigData

use of ratpack.server.internal.ServerConfigData in project ratpack by ratpack.

the class ServerConfigDataDeserializer method deserialize.

@Override
public ServerConfigData deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();
    ObjectNode serverNode = jp.readValueAsTree();
    ServerConfigData data = new ServerConfigData(baseDirSupplier.get(), address, port, development, publicAddress);
    if (serverNode.hasNonNull("port")) {
        data.setPort(parsePort(serverNode.get("port")));
    }
    if (serverNode.hasNonNull("address")) {
        data.setAddress(toValue(codec, serverNode.get("address"), InetAddress.class));
    }
    if (serverNode.hasNonNull("development")) {
        data.setDevelopment(serverNode.get("development").asBoolean(false));
    }
    if (serverNode.hasNonNull("threads")) {
        data.setThreads(serverNode.get("threads").asInt(ServerConfig.DEFAULT_THREADS));
    }
    if (serverNode.hasNonNull("publicAddress")) {
        data.setPublicAddress(toValue(codec, serverNode.get("publicAddress"), URI.class));
    }
    if (serverNode.hasNonNull("maxContentLength")) {
        data.setMaxContentLength(serverNode.get("maxContentLength").asInt(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH));
    }
    if (serverNode.hasNonNull("maxChunkSize")) {
        data.setMaxChunkSize(serverNode.get("maxChunkSize").asInt(ServerConfig.DEFAULT_MAX_CHUNK_SIZE));
    }
    if (serverNode.hasNonNull("maxInitialLineLength")) {
        data.setMaxInitialLineLength(serverNode.get("maxInitialLineLength").asInt(ServerConfig.DEFAULT_MAX_INITIAL_LINE_LENGTH));
    }
    if (serverNode.hasNonNull("maxHeaderSize")) {
        data.setMaxHeaderSize(serverNode.get("maxHeaderSize").asInt(ServerConfig.DEFAULT_MAX_HEADER_SIZE));
    }
    if (serverNode.hasNonNull("ssl")) {
        data.setSslContext(toValue(codec, serverNode.get("ssl"), SSLContext.class));
    }
    if (serverNode.hasNonNull("requireClientSslAuth")) {
        data.setRequireClientSslAuth(serverNode.get("requireClientSslAuth").asBoolean(false));
    }
    if (serverNode.hasNonNull("baseDir")) {
        throw new IllegalStateException("baseDir value cannot be set via config, it must be set directly via ServerConfigBuilder.baseDir()");
    }
    if (serverNode.hasNonNull("connectTimeoutMillis")) {
        parseOptionalIntValue("connectTimeoutMillis", serverNode.get("connectTimeoutMillis")).ifPresent(data::setConnectTimeoutMillis);
    }
    if (serverNode.hasNonNull("maxMessagesPerRead")) {
        parseOptionalIntValue("maxMessagesPerRead", serverNode.get("maxMessagesPerRead")).ifPresent(data::setMaxMessagesPerRead);
    }
    if (serverNode.hasNonNull("receiveBufferSize")) {
        parseOptionalIntValue("receiveBufferSize", serverNode.get("receiveBufferSize")).ifPresent(data::setReceiveBufferSize);
    }
    if (serverNode.hasNonNull("writeSpinCount")) {
        parseOptionalIntValue("writeSpinCount", serverNode.get("writeSpinCount")).ifPresent(data::setWriteSpinCount);
    }
    return data;
}
Also used : ServerConfigData(ratpack.server.internal.ServerConfigData) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) SSLContext(javax.net.ssl.SSLContext) InetAddress(java.net.InetAddress) URI(java.net.URI)

Aggregations

ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InetAddress (java.net.InetAddress)1 URI (java.net.URI)1 SSLContext (javax.net.ssl.SSLContext)1 ServerConfigData (ratpack.server.internal.ServerConfigData)1