Package com.illumon.util.jettyhelper
Class JettyServerBuilder
java.lang.Object
io.grpc.ServerBuilder<T>
io.grpc.ForwardingServerBuilder<JettyServerBuilder>
com.illumon.util.jettyhelper.JettyServerBuilder
Analog of gRPC's ServerBuilder, plus servlet support to replace internal usage of JettyServerHelper, enabling
applications to assemble http2 and grpc services and expose them on a single port.
If defined, some configuration options will be used to manage server behavior:
http2.maxConcurrentStreams- sets the maximum number of concurrent h2 streams a socket can have.http.maxHeaderRequestSize- sets the maximum size of headers in an incoming request.http2.streamIdleTimeoutMs- sets the idle timeout for individual h2 streams, in milliseconds. Defaults to zero to disable the timeout.cors.allowedOrigins- enables CORS support and sets the allowed origins. If not defined, CORS is disabled unless Envoy is not in use, in which case the web UI host and port are used.cors.allowedMethods- sets the allowed methods for CORS requests. If not defined, all methods that the server is configured to use are allowed.cors.allowedHeaders- sets the allowed headers for CORS requests. If not defined, a set of headers required for gRPC, gRPC-web, and deephaven's authentication are allowed.cors.exposedHeaders- sets the exposed headers for CORS requests. If not defined, a set of headers required for gRPC, gRPC-web, and deephaven's authentication are exposed.Jetty.sniHostCheck- determines if http Host/Authority is checked against expected subject in the certificate. Default is true. Can be overridden bysniHostCheck(boolean).http.requireHttp2- allows forbidding http/1.1 connections, to generally encourage h2 adoption and help diagnose connection issues. Defaults to true.tls.certificateExpirationWarningDays- enables certificate expiration checking and sets the threshold in days to warn about. Default is 30 days.
-
Method Summary
Modifier and TypeMethodDescriptionaddHomeLambdaServlet(Supplier<String> lambda) Add the home lambda servlet to provide the home pageaddLambdaServlet(String name, Supplier<String> lambda) Add a Lambda servlet to the Jetty serveraddServlet(String name, jakarta.servlet.http.HttpServlet httpservlet, String... methods) Add a raw HttpServlet servlet to the Jetty serveraddServlet(String name, jakarta.servlet.http.HttpServlet httpservlet, Map<String, String> params, String... methods) Add a raw HttpServlet servlet to the Jetty server with init params.addServletContainerInitializer(jakarta.servlet.ServletContainerInitializer initializer) io.grpc.Serverbuild()protected io.grpc.ServerBuilder<?>delegate()static JettyServerBuilderforPort(int port) Creates a builder for a gRPC+Jetty server listening on the given port.lambdaServletConfiguration(AuditEventLogger auditEventLogLogger, IrisGroupProvider groupProvider, String mainClassName, boolean authenticationRequired) Configure the server to support lambda servlets.The group provider may be null if authentication is not required.setAllowUriViolations(org.eclipse.jetty.http.UriCompliance.Violation... violations) sniHostCheck(boolean sniHostCheck) Specifies if the server should validate that the SNI hostname matches the certificate.tlsKeystore(String tlsKeystorePath, String tlsKeystorePassphrase) Configure TLS for the server, using the given keystore path and passphrase.Methods inherited from class io.grpc.ForwardingServerBuilder
addService, addService, addStreamTracerFactory, addTransportFilter, callExecutor, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, handshakeTimeout, intercept, keepAliveTime, keepAliveTimeout, maxConnectionAge, maxConnectionAgeGrace, maxConnectionIdle, maxInboundMessageSize, maxInboundMetadataSize, permitKeepAliveTime, permitKeepAliveWithoutCalls, setBinaryLog, toString, useTransportSecurity, useTransportSecurityMethods inherited from class io.grpc.ServerBuilder
addServices
-
Method Details
-
forPort
Creates a builder for a gRPC+Jetty server listening on the given port.- Parameters:
port- the port to listen on- Returns:
- a server builder to configure a gRPC server
-
delegate
protected io.grpc.ServerBuilder<?> delegate()- Specified by:
delegatein classio.grpc.ForwardingServerBuilder<JettyServerBuilder>
-
tlsKeystore
Configure TLS for the server, using the given keystore path and passphrase. This is required.On startup, the server will check the keystore for certificates that are expiring soon, and log an error message if any are expiring within the threshold set (default 30 days).
- Parameters:
tlsKeystorePath- the path to the keystore filetlsKeystorePassphrase- the keystore's passphrase- Returns:
- this builder
-
sniHostCheck
Specifies if the server should validate that the SNI hostname matches the certificate. Default is true. If not specified through this builder method, the value will be taken from the configuration property.- Parameters:
sniHostCheck- true to enable SNI hostname verification, false to disable it- Returns:
- this builder
-
lambdaServletConfiguration
public JettyServerBuilder lambdaServletConfiguration(AuditEventLogger auditEventLogLogger, IrisGroupProvider groupProvider, String mainClassName, boolean authenticationRequired) Configure the server to support lambda servlets.The group provider may be null if authentication is not required.- Parameters:
auditEventLogLogger- an AuditEventLogger to log authentication eventsgroupProvider- an IrisGroupProvider to validate group membership, may be null if authentication is not requiredmainClassName- the main class name, used for group validationauthenticationRequired- true if password authentication is required, false otherwise- Returns:
- this builder
-
addLambdaServlet
Add a Lambda servlet to the Jetty server- Parameters:
name- the name of the servlet, used to build the path specificationslambda- the lambda to run for the specified name- Returns:
- this builder
-
addServlet
public JettyServerBuilder addServlet(String name, jakarta.servlet.http.HttpServlet httpservlet, String... methods) Add a raw HttpServlet servlet to the Jetty server- Parameters:
name- the name of the servlet, used to build the path specificationshttpservlet- the servlet that is bound to the specified namemethods- The HTTP methods that should be allowed for this servlet- Returns:
- this builder
-
addServlet
public JettyServerBuilder addServlet(@NotNull String name, @NotNull jakarta.servlet.http.HttpServlet httpservlet, @NotNull Map<String, String> params, @NotNull String... methods) Add a raw HttpServlet servlet to the Jetty server with init params.- Parameters:
name- the name of the servlet, used to build the path specificationshttpservlet- the servlet that is bound to the specified nameparams- The init parameters that should be set on theServletHoldermethods- The HTTP methods that should be allowed for this servlet- Returns:
- this builder
-
addHomeLambdaServlet
Add the home lambda servlet to provide the home page- Parameters:
lambda- the home lambda to run- Returns:
- this builder
-
setAllowUriViolations
public JettyServerBuilder setAllowUriViolations(org.eclipse.jetty.http.UriCompliance.Violation... violations) - Parameters:
violations- a list of ee10 / servlet 6.0 uri spec violations to ignore (needed for acl write server jax-rs api)
-
addServletContainerInitializer
public JettyServerBuilder addServletContainerInitializer(jakarta.servlet.ServletContainerInitializer initializer) -
requireHttp11
-
build
public io.grpc.Server build()- Overrides:
buildin classio.grpc.ForwardingServerBuilder<JettyServerBuilder>
-