Class RESTService

java.lang.Object
i5.las2peer.api.Configurable
i5.las2peer.api.Service
i5.las2peer.restMapper.RESTService

@Path("/") public abstract class RESTService extends i5.las2peer.api.Service
Base class for RESTful services. Provides Jersey and Swagger integration.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new REST service using a Jersey ResourceConfig as application.
  • Method Summary

    Modifier and Type
    Method
    Description
    final String
    Gets the alias from the service class' ServicePath annotation.
    protected javax.ws.rs.core.Application
    Returns the JAX-RS application.
    protected org.glassfish.jersey.server.ResourceConfig
    Sets a Jersey's ResourceConfig as JAX-RS Application if no application is set and returns it.
    final String
    Gets the Swagger documentation for this service.
    handle(URI baseUri, URI requestUri, String method, byte[] body, Map<String,List<String>> headers)
    Handles a REST call and passes it to Jersey.
    protected void
    Register resources here using getResourceConfig() or set a custom JAX-RS Application using setApplication(Application).
    protected void
    setApplication(javax.ws.rs.core.Application application)
    Set a custom JAX-RS Application.

    Methods inherited from class i5.las2peer.api.Service

    getAgent, getCustomMessageDescriptions, getLogger, isMonitor, isSelfDeployable, onStart, onStart, onStop, setFieldValues

    Methods inherited from class i5.las2peer.api.Configurable

    getProperties

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RESTService

      public RESTService()
      Creates a new REST service using a Jersey ResourceConfig as application.
      Throws:
      IllegalStateException - if no resources have been set up in initResources().
  • Method Details

    • initResources

      protected void initResources()
      Register resources here using getResourceConfig() or set a custom JAX-RS Application using setApplication(Application). Resources cannot be set up afterwards. If the method is not overridden by the service, the service class itself will be registered as resource.
    • getResourceConfig

      protected org.glassfish.jersey.server.ResourceConfig getResourceConfig()
      Sets a Jersey's ResourceConfig as JAX-RS Application if no application is set and returns it. Use this to add resources to a RESTful service.
      Returns:
      the resource configuration
      Throws:
      IllegalStateException - if a custom Application has been set using setApplication(Application).
    • setApplication

      protected void setApplication(javax.ws.rs.core.Application application)
      Set a custom JAX-RS Application. Can only be called once.
      Parameters:
      application - the JAX-RS Application
      Throws:
      IllegalStateException - if the Application has already been set up using setApplication(Application) or getResourceConfig().
    • getApplication

      protected javax.ws.rs.core.Application getApplication()
      Returns the JAX-RS application.
      Returns:
      the JAX-RS Application
    • handle

      public final RESTResponse handle(URI baseUri, URI requestUri, String method, byte[] body, Map<String,List<String>> headers)
      Handles a REST call and passes it to Jersey. Intended for RMI calls only.
      Parameters:
      baseUri - base URI where the service was called
      requestUri - full request URI
      method - HTTP method
      body - request body
      headers - HTTP request headers
      Returns:
      a RESTResponse wrapping the output from Jersey
    • getSwagger

      public final String getSwagger() throws com.fasterxml.jackson.core.JsonProcessingException
      Gets the Swagger documentation for this service. Intended for RMI calls only.
      Returns:
      A JSON serialized Swagger object
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - thrown by Swagger
    • getAlias

      public final String getAlias()
      Gets the alias from the service class' ServicePath annotation.
      Overrides:
      getAlias in class i5.las2peer.api.Service