Example usage for io.netty.util DomainNameMappingBuilder add

List of usage examples for io.netty.util DomainNameMappingBuilder add

Introduction

In this page you can find the example usage for io.netty.util DomainNameMappingBuilder add.

Prototype

public DomainNameMappingBuilder<V> add(String hostname, V output) 

Source Link

Document

Adds a mapping that maps the specified (optionally wildcard) host name to the specified output value.

Usage

From source file:com.liferay.sync.engine.lan.server.file.LanFileServerInitializer.java

License:Open Source License

public void updateDomainNameMapping() {
    DomainNameMappingBuilder<SslContext> domainNameMappingBuilder = null;

    for (SyncAccount syncAccount : SyncAccountService.findAll()) {
        if (!syncAccount.isActive() || !syncAccount.isLanEnabled()) {
            continue;
        }/*from   w w  w .j av  a2 s . c o  m*/

        SslContext sslContext = null;

        try {
            X509Certificate x509Certificate = LanPEMParserUtil
                    .parseX509Certificate(syncAccount.getLanCertificate());

            SslContextBuilder sslContextBuilder = SslContextBuilder
                    .forServer(LanPEMParserUtil.parsePrivateKey(syncAccount.getLanKey()), x509Certificate);

            sslContextBuilder.clientAuth(ClientAuth.REQUIRE);
            sslContextBuilder.sslProvider(SslProvider.JDK);
            sslContextBuilder.trustManager(x509Certificate);

            sslContext = sslContextBuilder.build();
        } catch (Exception e) {
            _logger.error(e.getMessage(), e);

            continue;
        }

        if (domainNameMappingBuilder == null) {
            domainNameMappingBuilder = new DomainNameMappingBuilder<>(sslContext);
        }

        domainNameMappingBuilder.add(LanClientUtil.getSNIHostname(syncAccount.getLanServerUuid()), sslContext);
    }

    if (domainNameMappingBuilder == null) {
        return;
    }

    _domainNameMapping = domainNameMappingBuilder.build();
}

From source file:com.linecorp.armeria.server.Server.java

License:Apache License

Server(ServerConfig config) {
    this.config = requireNonNull(config, "config");
    config.setServer(this);

    // Pre-populate the domain name mapping for later matching.
    SslContext lastSslContext = null;//from w w  w  .  j  a  v a 2s.  c  o m
    for (VirtualHost h : config.virtualHosts()) {
        lastSslContext = h.sslContext();
    }

    if (lastSslContext == null) {
        sslContexts = null;
        for (ServerPort p : config.ports()) {
            if (p.protocol().isTls()) {
                throw new IllegalArgumentException("no SSL context specified");
            }
        }
    } else {
        final DomainNameMappingBuilder<SslContext> mappingBuilder = new DomainNameMappingBuilder<>(
                lastSslContext);
        for (VirtualHost h : config.virtualHosts()) {
            final SslContext sslCtx = h.sslContext();
            if (sslCtx != null) {
                mappingBuilder.add(h.hostnamePattern(), sslCtx);
            }
        }
        sslContexts = mappingBuilder.build();
    }

    // Invoke the serviceAdded() method in Service so that it can keep the reference to this Server or
    // add a listener to it.
    config.serviceConfigs().forEach(cfg -> ServiceCallbackInvoker.invokeServiceAdded(cfg, cfg.service()));
}

From source file:com.linecorp.armeria.server.ServerConfig.java

License:Apache License

ServerConfig(Iterable<ServerPort> ports, VirtualHost defaultVirtualHost, Iterable<VirtualHost> virtualHosts,
        int numWorkers, int maxPendingRequests, int maxConnections, long idleTimeoutMillis,
        long defaultRequestTimeoutMillis, long defaultMaxRequestLength, Duration gracefulShutdownQuietPeriod,
        Duration gracefulShutdownTimeout, Executor blockingTaskExecutor, String serviceLoggerPrefix) {

    requireNonNull(ports, "ports");
    requireNonNull(virtualHosts, "virtualHosts");
    requireNonNull(defaultVirtualHost, "defaultVirtualHost");

    // Set the primitive properties.
    this.numWorkers = validateNumWorkers(numWorkers);
    this.maxPendingRequests = validateMaxPendingRequests(maxPendingRequests);
    this.maxConnections = validateMaxConnections(maxConnections);
    this.idleTimeoutMillis = validateIdleTimeoutMillis(idleTimeoutMillis);
    this.defaultRequestTimeoutMillis = validateDefaultRequestTimeoutMillis(defaultRequestTimeoutMillis);
    this.defaultMaxRequestLength = validateDefaultMaxRequestLength(defaultMaxRequestLength);
    this.gracefulShutdownQuietPeriod = validateNonNegative(requireNonNull(gracefulShutdownQuietPeriod),
            "gracefulShutdownQuietPeriod");
    this.gracefulShutdownTimeout = validateNonNegative(requireNonNull(gracefulShutdownTimeout),
            "gracefulShutdownTimeout");
    validateGreaterThanOrEqual(gracefulShutdownTimeout, "gracefulShutdownTimeout", gracefulShutdownQuietPeriod,
            "gracefulShutdownQuietPeriod");

    requireNonNull(blockingTaskExecutor, "blockingTaskExecutor");
    if (blockingTaskExecutor instanceof ExecutorService) {
        this.blockingTaskExecutor = new InterminableExecutorService((ExecutorService) blockingTaskExecutor);
    } else {//from  w  w  w  .j  a  v  a2 s.  c  om
        this.blockingTaskExecutor = new ExecutorBasedExecutorService(blockingTaskExecutor);
    }

    this.serviceLoggerPrefix = ServiceConfig.validateLoggerName(serviceLoggerPrefix, "serviceLoggerPrefix");

    // Set localAddresses.
    final List<ServerPort> portsCopy = new ArrayList<>();
    for (ServerPort p : ports) {
        if (p == null) {
            break;
        }
        portsCopy.add(p);
    }

    if (portsCopy.isEmpty()) {
        throw new IllegalArgumentException("no ports in the server");
    }

    this.ports = Collections.unmodifiableList(portsCopy);

    // Set virtual host definitions and initialize their domain name mapping.
    defaultVirtualHost = normalizeDefaultVirtualHost(defaultVirtualHost, portsCopy);
    final DomainNameMappingBuilder<VirtualHost> mappingBuilder = new DomainNameMappingBuilder<>(
            defaultVirtualHost);
    final List<VirtualHost> virtualHostsCopy = new ArrayList<>();
    for (VirtualHost h : virtualHosts) {
        if (h == null) {
            break;
        }
        virtualHostsCopy.add(h);
        mappingBuilder.add(h.hostnamePattern(), h);
    }
    virtualHostMapping = mappingBuilder.build();

    // Add the default VirtualHost to the virtualHosts so that a user can retrieve all VirtualHosts
    // via virtualHosts(). i.e. no need to check defaultVirtualHost().
    virtualHostsCopy.add(defaultVirtualHost);

    // Sets the parent of VirtualHost to this configuration.
    virtualHostsCopy.forEach(h -> h.setServerConfig(this));

    if (virtualHostsCopy.stream().allMatch(h -> h.serviceConfigs().isEmpty())) {
        throw new IllegalArgumentException("no services in the server");
    }

    this.virtualHosts = Collections.unmodifiableList(virtualHostsCopy);
    this.defaultVirtualHost = defaultVirtualHost;

    // Build the complete list of the services available in this server.
    services = Collections.unmodifiableList(
            virtualHostsCopy.stream().flatMap(h -> h.serviceConfigs().stream()).collect(Collectors.toList()));
}