/** * Adds the <a href="https://en.wikipedia.org/wiki/Virtual_hosting#Name-based">name-based virtual host</a> * specified by {@link VirtualHost}. * * @param defaultHostname default hostname of this virtual host * @param hostnamePattern virtual host name regular expression * @return {@link VirtualHostBuilder} for build the virtual host */ public ChainedVirtualHostBuilder withVirtualHost(String defaultHostname, String hostnamePattern) { final ChainedVirtualHostBuilder virtualHostBuilder = new ChainedVirtualHostBuilder(defaultHostname, hostnamePattern, this); virtualHostBuilders.add(virtualHostBuilder); return virtualHostBuilder; }
/** * Binds the specified {@link ServiceWithPathMappings} at multiple {@link PathMapping}s * of the default {@link VirtualHost}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public <T extends ServiceWithPathMappings<HttpRequest, HttpResponse>> ServerBuilder service(T serviceWithPathMappings) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.service(serviceWithPathMappings); return this; }
/** * Binds the specified {@link Service} under the specified directory of the default {@link VirtualHost}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder serviceUnder(String pathPrefix, Service<HttpRequest, HttpResponse> service) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.serviceUnder(pathPrefix, service); return this; }
/** * Configures SSL or TLS of the default {@link VirtualHost} from the specified {@code keyCertChainFile}, * {@code keyFile} and {@code keyPassword}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder tls( File keyCertChainFile, File keyFile, @Nullable String keyPassword) throws SSLException { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.tls(keyCertChainFile, keyFile, keyPassword); return this; }
/** * Sets the {@link SslContext} of the default {@link VirtualHost} from the specified * {@link SessionProtocol}, {@code keyCertChainFile} and cleartext {@code keyFile}. * * @deprecated Use {@link #tls(File, File)}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ @Deprecated public ServerBuilder sslContext( SessionProtocol protocol, File keyCertChainFile, File keyFile) throws SSLException { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.sslContext(protocol, keyCertChainFile, keyFile); return this; }
/** * Configures SSL or TLS of the default {@link VirtualHost} with an auto-generated self-signed * certificate. <strong>Note:</strong> You should never use this in production but only for a testing * purpose. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already * @throws CertificateException if failed to generate a self-signed certificate */ public ServerBuilder tlsSelfSigned() throws SSLException, CertificateException { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.tlsSelfSigned(); return this; }
/** * Binds the specified annotated service object under the specified path prefix. * * @param exceptionHandlersAndConverters an iterable object of {@link ExceptionHandlerFunction}, * {@link RequestConverterFunction} and/or * {@link ResponseConverterFunction} */ public ServerBuilder annotatedService(String pathPrefix, Object service, Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator, Iterable<?> exceptionHandlersAndConverters) { requireNonNull(pathPrefix, "pathPrefix"); requireNonNull(service, "service"); requireNonNull(decorator, "decorator"); requireNonNull(exceptionHandlersAndConverters, "exceptionHandlersAndConverters"); defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.annotatedService(pathPrefix, service, decorator, exceptionHandlersAndConverters); return this; }
/** * Sets the {@link SslContext} of the default {@link VirtualHost}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder tls(SslContext sslContext) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.tls(sslContext); return this; }
/** * Sets the {@link SslContext} of the default {@link VirtualHost} from the specified * {@link SessionProtocol}, {@code keyCertChainFile}, {@code keyFile} and {@code keyPassword}. * * @deprecated Use {@link #tls(File, File, String)}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ @Deprecated public ServerBuilder sslContext( SessionProtocol protocol, File keyCertChainFile, File keyFile, String keyPassword) throws SSLException { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.sslContext(protocol, keyCertChainFile, keyFile, keyPassword); return this; }
/** * Binds the specified {@link Service} at the specified {@link PathMapping} of the default * {@link VirtualHost}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder service(PathMapping pathMapping, Service<HttpRequest, HttpResponse> service) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.service(pathMapping, service); return this; }
/** * Configures SSL or TLS of the default {@link VirtualHost} from the specified {@code keyCertChainFile} * and cleartext {@code keyFile}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder tls(File keyCertChainFile, File keyFile) throws SSLException { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.tls(keyCertChainFile, keyFile); return this; }
/** * Adds the <a href="https://en.wikipedia.org/wiki/Virtual_hosting#Name-based">name-based virtual host</a> * specified by {@link VirtualHost}. * * @param hostnamePattern virtual host name regular expression * @return {@link VirtualHostBuilder} for build the virtual host */ public ChainedVirtualHostBuilder withVirtualHost(String hostnamePattern) { final ChainedVirtualHostBuilder virtualHostBuilder = new ChainedVirtualHostBuilder(hostnamePattern, this); virtualHostBuilders.add(virtualHostBuilder); return virtualHostBuilder; }
/** * Binds the specified {@link Service} at the specified {@link PathMapping} of the default * {@link VirtualHost}. * * @deprecated Use a logging framework integration such as {@code RequestContextExportingAppender} in * {@code armeria-logback}. */ @Deprecated public ServerBuilder service(PathMapping pathMapping, Service<HttpRequest, HttpResponse> service, String loggerName) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.service(pathMapping, service, loggerName); return this; }
/** * Sets the {@link SslContext} of the default {@link VirtualHost}. * * @deprecated Use {@link #tls(SslContext)}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ @Deprecated public ServerBuilder sslContext(SslContext sslContext) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.tls(sslContext); return this; }
/** * Decorates and binds the specified {@link ServiceWithPathMappings} at multiple {@link PathMapping}s * of the default {@link VirtualHost}. * * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public <T extends ServiceWithPathMappings<HttpRequest, HttpResponse>, R extends Service<HttpRequest, HttpResponse>> ServerBuilder service(T serviceWithPathMappings, Function<? super T, R> decorator) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.service(serviceWithPathMappings, decorator); return this; }
/** * Binds the specified {@link Service} at the specified path pattern of the default {@link VirtualHost}. * e.g. * <ul> * <li>{@code /login} (no path parameters)</li> * <li>{@code /users/{userId}} (curly-brace style)</li> * <li>{@code /list/:productType/by/:ordering} (colon style)</li> * <li>{@code exact:/foo/bar} (exact match)</li> * <li>{@code prefix:/files} (prefix match)</li> * <li><code>glob:/~*/downloads/**</code> (glob pattern)</li> * <li>{@code regex:^/files/(?<filePath>.*)$} (regular expression)</li> * </ul> * * @throws IllegalArgumentException if the specified path pattern is invalid * @throws IllegalStateException if the default {@link VirtualHost} has been set via * {@link #defaultVirtualHost(VirtualHost)} already */ public ServerBuilder service(String pathPattern, Service<HttpRequest, HttpResponse> service) { defaultVirtualHostBuilderUpdated(); defaultVirtualHostBuilder.service(pathPattern, service); return this; }