/** * Sets the {@link Logger} of this {@link VirtualHost}, which is used for writing access logs. */ public B accessLogger(Logger logger) { requireNonNull(logger, "logger"); return accessLogger(host -> logger); }
/** * Binds the specified annotated service object under the specified path prefix. */ public B annotatedService(String pathPrefix, Object service) { return annotatedService(pathPrefix, service, Function.identity(), ImmutableList.of()); }
@Override public VirtualHost build() { return super.build(); } }
/** * Sets the {@link SslContext} of this {@link VirtualHost} from the specified {@link SessionProtocol}, * {@code keyCertChainFile} and cleartext {@code keyFile}. * * @deprecated Use {@link #tls(File, File)}. */ @Deprecated public B sslContext( SessionProtocol protocol, File keyCertChainFile, File keyFile) throws SSLException { sslContext(protocol, keyCertChainFile, keyFile, null); return self(); }
/** * Sets the access logger mapper of this {@link VirtualHost}. * When {@link #build()} is called, this {@link VirtualHost} gets {@link Logger} * via the {@code mapper} for writing access logs. */ public B accessLogger(Function<VirtualHost, Logger> mapper) { accessLoggerMapper = requireNonNull(mapper, "mapper"); return self(); }
/** * Sets the {@link SslContext} of this {@link VirtualHost}. * * @deprecated Use {@link #tls(SslContext)}. */ @Deprecated public B sslContext(SslContext sslContext) { return tls(sslContext); }
/** * Binds the specified {@link Service} at the specified path pattern. * * @deprecated Use {@link #service(String, Service)} instead. */ @Deprecated public B serviceAt(String pathPattern, Service<HttpRequest, HttpResponse> service) { return service(pathPattern, service); }
/** * Binds the specified {@link Service} at the specified path pattern. 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 */ public B service(String pathPattern, Service<HttpRequest, HttpResponse> service) { service(PathMapping.of(pathPattern), service); return self(); }
/** * Decorates all {@link Service}s with the specified {@code decorator}. * * @param decorator the {@link Function} that decorates a {@link Service} * @param <T> the type of the {@link Service} being decorated * @param <R> the type of the {@link Service} {@code decorator} will produce */ public <T extends Service<HttpRequest, HttpResponse>, R extends Service<HttpRequest, HttpResponse>> B decorator(Function<T, R> decorator) { requireNonNull(decorator, "decorator"); @SuppressWarnings("unchecked") final Function<Service<HttpRequest, HttpResponse>, Service<HttpRequest, HttpResponse>> castDecorator = (Function<Service<HttpRequest, HttpResponse>, Service<HttpRequest, HttpResponse>>) decorator; if (this.decorator != null) { this.decorator = this.decorator.andThen(castDecorator); } else { this.decorator = castDecorator; } return self(); }
/** * Sets the {@link SslContext} of this {@link VirtualHost} from the specified {@link SessionProtocol}, * {@code keyCertChainFile}, {@code keyFile} and {@code keyPassword}. * * @deprecated Use {@link #tls(File, File, String)}. */ @Deprecated public B sslContext( SessionProtocol protocol, File keyCertChainFile, File keyFile, @Nullable String keyPassword) throws SSLException { if (requireNonNull(protocol, "protocol") != SessionProtocol.HTTPS) { throw new IllegalArgumentException("unsupported protocol: " + protocol); } return tls(keyCertChainFile, keyFile, keyPassword); }
/** * Binds the specified {@link ServiceWithPathMappings} at multiple {@link PathMapping}s. */ public <T extends ServiceWithPathMappings<HttpRequest, HttpResponse>> B service(T serviceWithPathMappings) { return service(serviceWithPathMappings, Function.identity()); }
/** * Decorates and binds the specified {@link ServiceWithPathMappings} at multiple {@link PathMapping}s. */ public <T extends ServiceWithPathMappings<HttpRequest, HttpResponse>, R extends Service<HttpRequest, HttpResponse>> B service(T serviceWithPathMappings, Function<? super T, R> decorator) { requireNonNull(serviceWithPathMappings, "serviceWithPathMappings"); requireNonNull(serviceWithPathMappings.pathMappings(), "serviceWithPathMappings.pathMappings()"); requireNonNull(decorator, "decorator"); final Service<HttpRequest, HttpResponse> decorated = decorator.apply(serviceWithPathMappings); serviceWithPathMappings.pathMappings().forEach(pathMapping -> service(pathMapping, decorated)); return self(); }
/** * Binds the specified annotated service object under the path prefix {@code "/"}. */ public B annotatedService(Object service) { return annotatedService("/", service, Function.identity(), ImmutableList.of()); }
/** * Binds the specified {@link Service} at the specified {@link PathMapping}. */ public B service(PathMapping pathMapping, Service<HttpRequest, HttpResponse> service) { services.add(new ServiceConfig(pathMapping, service, null)); return self(); }
/** * Configures SSL or TLS of this {@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 CertificateException if failed to generate a self-signed certificate */ public B tlsSelfSigned() throws SSLException, CertificateException { final SelfSignedCertificate ssc = new SelfSignedCertificate(defaultHostname); return tls(ssc.certificate(), ssc.privateKey()); }
/** * Sets the {@link Logger} named {@code loggerName} of this {@link VirtualHost}, * which is used for writing access logs. */ public B accessLogger(String loggerName) { requireNonNull(loggerName, "loggerName"); return accessLogger(host -> LoggerFactory.getLogger(loggerName)); }