Interface Service<I extends Request,O extends Response>

Type Parameters:
I - the type of incoming Request. Must be HttpRequest or RpcRequest.
O - the type of outgoing Response. Must be HttpResponse or RpcResponse.
All Superinterfaces:
Unwrappable
All Known Subinterfaces:
GraphqlService, GrpcService, HttpService, HttpServiceWithRoutes, RpcService, RpcServiceWithRoutes, ServiceWithRoutes<I,O>, TransientHttpService, TransientRpcService, TransientService<I,O>
All Known Implementing Classes:
AbstractGraphqlService, AbstractHttpService, AbstractThrottlingService, AbstractUnaryGrpcService, AbstractUnsafeUnaryGrpcService, AuthService, BraveService, ContentPreviewingService, CoroutineContextService, CorsService, DecodingService, DecoratingService, DocService, EncodingService, FileService, HealthCheckService, JettyService, LoggingService, ManagementService, MetricCollectingService, PrometheusExpositionService, RedirectService, ResteasyService, SimpleDecoratingHttpService, SimpleDecoratingRpcService, SimpleDecoratingService, ThriftCallService, ThrottlingRpcService, ThrottlingService, THttpService, TomcatService, WebSocketService
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Service<I extends Request,O extends Response> extends Unwrappable
Handles a Request received by a Server.
  • Method Details

    • serviceAdded

      default void serviceAdded(ServiceConfig cfg) throws Exception
      Invoked when this service has been added to a Server with the specified configuration. Please note that this method can be invoked more than once if this service has been added more than once.
      Throws:
      Exception
    • serve

      O serve(ServiceRequestContext ctx, I req) throws Exception
      Serves an incoming Request.
      Parameters:
      ctx - the context of the received Request
      req - the received Request
      Returns:
      the Response
      Throws:
      Exception
    • as

      default <T> T as(Class<T> type)
      Unwraps this Service into the object of the specified type. Use this method instead of an explicit downcast. For example:
      
       HttpService s = new MyService().decorate(LoggingService.newDecorator())
                                      .decorate(AuthService.newDecorator());
       MyService s1 = s.as(MyService.class);
       LoggingService s2 = s.as(LoggingService.class);
       AuthService s3 = s.as(AuthService.class);
       
      Specified by:
      as in interface Unwrappable
      Parameters:
      type - the type of the object to return
      Returns:
      the object of the specified type if found, or null if not found.
      See Also:
    • unwrap

      default Service<? extends Request,? extends Response> unwrap()
      Unwraps this Service and returns the object being decorated. If this Service is the innermost object, this method returns itself. For example:
      
       HttpService service1 = new MyService();
       assert service1.unwrap() == service1;
      
       HttpService service2 = service1.decorate(LoggingService.newDecorator());
       HttpService service3 = service2.decorate(AuthService.newDecorator());
       assert service2.unwrap() == service1;
       assert service3.unwrap() == service2;
       assert service3.unwrap().unwrap() == service1;
       
      Specified by:
      unwrap in interface Unwrappable
    • shouldCachePath

      default boolean shouldCachePath(String path, @Nullable @Nullable String query, Route route)
      Returns whether the given path and query should be cached if the service's result is successful. By default, exact path mappings with no input query are cached.