Class GrpcHandlerFactory

java.lang.Object
org.bluezoo.gumdrop.grpc.server.GrpcHandlerFactory
All Implemented Interfaces:
HTTPRequestHandlerFactory

public class GrpcHandlerFactory extends Object implements HTTPRequestHandlerFactory
HTTPRequestHandlerFactory that routes gRPC requests to a GrpcHandler.

Checks that the path matches /package.Service/Method and content-type is application/grpc, then returns a handler that parses gRPC framing and dispatches to the GrpcService.

Author:
Chris Burdess
  • Constructor Details

    • GrpcHandlerFactory

      public GrpcHandlerFactory(ProtoFile protoFile, GrpcService service)
      Creates a factory with the given Proto model and service.
      Parameters:
      protoFile - the Proto model
      service - the gRPC service implementation
  • Method Details

    • createHandler

      public HTTPRequestHandler createHandler(HTTPResponseState state, Headers headers)
      Description copied from interface: HTTPRequestHandlerFactory
      Creates a handler for a new request.

      Called when the initial headers for a stream are received. The factory can examine the headers to decide which handler implementation to return.

      The returned handler will receive a HTTPRequestHandler.headers(org.bluezoo.gumdrop.http.HTTPResponseState, org.bluezoo.gumdrop.http.Headers) callback with the same headers - the factory is for routing/creation, the handler performs the actual request processing.

      Specified by:
      createHandler in interface HTTPRequestHandlerFactory
      Parameters:
      state - the response state for this stream (can be used to send early responses like 401)
      headers - the initial request headers (includes :method, :path, :scheme, :authority pseudo-headers)
      Returns:
      a handler for this request, or null to reject (sends 404 if no response was sent via state)
    • getSupportedMethods

      public Set<String> getSupportedMethods()
      Description copied from interface: HTTPRequestHandlerFactory
      Returns the set of HTTP methods supported by this factory.

      Override this method to add custom methods (e.g., WebDAV methods like PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK) or to restrict the methods that are accepted.

      If this method returns null (the default), the connection uses its default set of known methods:

      • Standard HTTP: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH
      • HTTP/2: PRI
      • WebDAV: PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK

      Unknown methods result in a 501 Not Implemented response.

      Specified by:
      getSupportedMethods in interface HTTPRequestHandlerFactory
      Returns:
      set of supported method names (uppercase), or null to use defaults