Class JettyServerBuilder

java.lang.Object
io.grpc.ServerBuilder<T>
io.grpc.ForwardingServerBuilder<JettyServerBuilder>
com.illumon.util.jettyhelper.JettyServerBuilder

public final class JettyServerBuilder extends io.grpc.ForwardingServerBuilder<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 by sniHostCheck(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 Details

    • forPort

      public static JettyServerBuilder forPort(int port)
      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:
      delegate in class io.grpc.ForwardingServerBuilder<JettyServerBuilder>
    • tlsKeystore

      public JettyServerBuilder tlsKeystore(String tlsKeystorePath, String tlsKeystorePassphrase)
      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 file
      tlsKeystorePassphrase - the keystore's passphrase
      Returns:
      this builder
    • sniHostCheck

      public JettyServerBuilder sniHostCheck(boolean 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 events
      groupProvider - an IrisGroupProvider to validate group membership, may be null if authentication is not required
      mainClassName - the main class name, used for group validation
      authenticationRequired - true if password authentication is required, false otherwise
      Returns:
      this builder
    • addLambdaServlet

      public JettyServerBuilder addLambdaServlet(String name, Supplier<String> lambda)
      Add a Lambda servlet to the Jetty server
      Parameters:
      name - the name of the servlet, used to build the path specifications
      lambda - 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 specifications
      httpservlet - the servlet that is bound to the specified name
      methods - 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 specifications
      httpservlet - the servlet that is bound to the specified name
      params - The init parameters that should be set on the ServletHolder
      methods - The HTTP methods that should be allowed for this servlet
      Returns:
      this builder
    • addHomeLambdaServlet

      public JettyServerBuilder addHomeLambdaServlet(Supplier<String> lambda)
      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

      public JettyServerBuilder requireHttp11()
    • build

      public io.grpc.Server build()
      Overrides:
      build in class io.grpc.ForwardingServerBuilder<JettyServerBuilder>