Package i5.las2peer.restMapper
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
ConstructorDescriptionCreates a new REST service using a Jersey ResourceConfig as application. -
Method Summary
Modifier and TypeMethodDescriptionfinal String
getAlias()
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.final RESTResponse
Handles a REST call and passes it to Jersey.protected void
Register resources here usinggetResourceConfig()
or set a custom JAX-RS Application usingsetApplication(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
-
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 ininitResources()
.
-
-
Method Details
-
initResources
protected void initResources()Register resources here usinggetResourceConfig()
or set a custom JAX-RS Application usingsetApplication(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 usingsetApplication(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 usingsetApplication(Application)
orgetResourceConfig()
.
-
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 calledrequestUri
- full request URImethod
- HTTP methodbody
- request bodyheaders
- HTTP request headers- Returns:
- a RESTResponse wrapping the output from Jersey
-
getSwagger
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
Gets the alias from the service class'ServicePath
annotation.- Overrides:
getAlias
in classi5.las2peer.api.Service
-