Class AbstractRootResource<S extends ADEPT2Service,W extends AbstractRootResourceWebService<S>>
- java.lang.Object
-
- de.aristaflow.ilm.ws.rest.base.service.AbstractRootResource<S,W>
-
- Type Parameters:
S
- TheADEPT2Service
which is exported as REST web service.W
- TheAbstractRootResourceWebService
which transforms between web service calls and the corresponding Java API.
- All Implemented Interfaces:
de.aristaflow.adept2.base.communication.rest.ServiceResource
- Direct Known Subclasses:
AbstractConfigurableRootResource
,GlobalProviderRest
,LicenceManagerRest
,OrgModelManagerRest
,ProcessImageRendererRest
,ProcessManagerRest
,ResModelManagerRest
,RuntimeManagerRest
,RuntimeServiceRest
,SimpleProcessImageRendererRest
,WorklistManagerRest
@Produces("application/json") @Consumes("application/json") public abstract class AbstractRootResource<S extends ADEPT2Service,W extends AbstractRootResourceWebService<S>> extends Object implements de.aristaflow.adept2.base.communication.rest.ServiceResource
This class provides the basic means for a REST root resource. It manages the web service (W
) that maps from the generic ILM to the Java API, e. g. transforms the ILM objects to the Java model and back.- See Also:
AbstractRootResourceWebService
-
-
Constructor Summary
Constructors Constructor Description AbstractRootResource()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Exception
adaptSessionTokenParam(Exception e)
Adapts the designated exception in case of aParameterException
and a#LOCATION_OPERATION
by setting the name to#SECURITY_TOKEN
, the expected class name tobyte[]
and the location to#LOCATION_HEADER
and#LOCATION_COOKIE
.protected abstract W
createWebService(S serv, ServiceMetaData smd)
Creates the generic web service implementation for the designated service.protected void
ensureReqMaxVersion(String required)
Ensures that the current request wants at most the designatedrequired
API version (or the same but not no version).protected void
ensureReqMinVersion(String required)
Ensures that the current request wants at least the designatedrequired
API version (or the same or the current, aka.protected static void
ensureVersion(de.aristaflow.adept2.base.communication.rest.RequestHandler handler, String required, boolean ensureRequestLess)
Ensures that the version of the request is less (or more) than the designatedrequired
version.void
exportService(ADEPT2Service serv, Supplier<SessionFactory> sfSupp, URI[] serviceUris, URL webAppBaseUrl, ServiceAccess serviceAccess, Supplier<com.fasterxml.jackson.databind.ObjectMapper> omSupp)
protected de.aristaflow.adept2.base.communication.rest.ExceptionHandler
getExceptionHandler()
Gets the exception handler creating appropriate wrapping exceptions for expected exceptions.protected Logger
getLogger()
Gets the logger to be used by web service endpoint implementations.protected com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Gets the object mapper for stubs of this root resource.@NotNull @Valid ServiceRelease
getRelease(javax.ws.rs.core.Application unused)
protected de.aristaflow.adept2.base.communication.rest.RequestHandler
getRequestHandler()
Gets the request handler allowing to access additional data from requests, e. g. headers.protected de.aristaflow.adept2.base.communication.rest.ResponseHandler
getResponseHandler()
Gets the response handler allowing to adapt the responses without returning aResponse
instance but the normal return value of the method.@NotNull @Valid ServiceInstanceName
getServiceInstanceName(javax.ws.rs.core.Application unused)
protected de.aristaflow.adept2.base.communication.rest.ServiceResourceConfig
getServiceResourceConfig()
Gets the configuration of this service resource.@NotEmpty List<URI>
getUris(javax.ws.rs.core.Application unused)
protected abstract String
getVersion()
Gets the current API version of this REST web service.protected W
getWebService()
Gets the web service instance mapping from ILM to the Java API and back.void
headerData(String apiVersion, String token, URI callerUri, UUID sessionId, String addAttributes, Boolean keepExceptionStack)
This method just serves documentation purpose.de.aristaflow.adept2.base.communication.rest.ExceptionHandler
init(de.aristaflow.adept2.base.communication.rest.RequestHandler requestHandler, de.aristaflow.adept2.base.communication.rest.ResponseHandler responseHandler, de.aristaflow.adept2.base.communication.rest.ServiceResourceConfig srConfig)
@NotNull @Min(-1L) Long
ping(javax.ws.rs.core.Application unused)
void
registerSse(javax.ws.rs.sse.SseEventSink eventSink, javax.ws.rs.sse.Sse sse)
This operation registers an SSE connection which can be used for server events by all services.void
unregisterService()
@NotNull Boolean
unregisterSse(UUID sseId)
This operation unregisters the designated SSE connection.
-
-
-
Method Detail
-
init
public final de.aristaflow.adept2.base.communication.rest.ExceptionHandler init(de.aristaflow.adept2.base.communication.rest.RequestHandler requestHandler, de.aristaflow.adept2.base.communication.rest.ResponseHandler responseHandler, de.aristaflow.adept2.base.communication.rest.ServiceResourceConfig srConfig)
- Specified by:
init
in interfacede.aristaflow.adept2.base.communication.rest.ServiceResource
-
exportService
public final void exportService(ADEPT2Service serv, Supplier<SessionFactory> sfSupp, URI[] serviceUris, URL webAppBaseUrl, ServiceAccess serviceAccess, Supplier<com.fasterxml.jackson.databind.ObjectMapper> omSupp) throws AbortServiceException
- Specified by:
exportService
in interfacede.aristaflow.adept2.base.communication.rest.ServiceResource
- Throws:
AbortServiceException
-
unregisterService
public void unregisterService()
- Specified by:
unregisterService
in interfacede.aristaflow.adept2.base.communication.rest.ServiceResource
-
getVersion
protected abstract String getVersion()
Gets the current API version of this REST web service.- Returns:
- The current API version of this REST web service.
-
createWebService
protected abstract W createWebService(S serv, ServiceMetaData smd) throws AbortServiceException
Creates the generic web service implementation for the designated service.- Parameters:
serv
- The service instance for which to create a generic web service implementation.smd
- The service meta data for provision to the sub resources.- Returns:
- The generic web service implementation for the designated service.
- Throws:
AbortServiceException
- If there are problems creating the web service anAbortServiceException
will be thrown.
-
getRequestHandler
protected de.aristaflow.adept2.base.communication.rest.RequestHandler getRequestHandler()
Gets the request handler allowing to access additional data from requests, e. g. headers.- Returns:
- The request handler allowing to access additional data from requests, e. g. headers.
-
getResponseHandler
protected de.aristaflow.adept2.base.communication.rest.ResponseHandler getResponseHandler()
Gets the response handler allowing to adapt the responses without returning aResponse
instance but the normal return value of the method.- Returns:
- The response handler allowing to adapt the responses without returning a
Response
instance but the normal return value of the method.
-
getExceptionHandler
protected de.aristaflow.adept2.base.communication.rest.ExceptionHandler getExceptionHandler()
Gets the exception handler creating appropriate wrapping exceptions for expected exceptions.- Returns:
- The exception handler creating appropriate wrapping exceptions for expected exceptions.
-
getServiceResourceConfig
protected de.aristaflow.adept2.base.communication.rest.ServiceResourceConfig getServiceResourceConfig()
Gets the configuration of this service resource.- Returns:
- The configuration of this service resource.
-
getWebService
protected W getWebService()
Gets the web service instance mapping from ILM to the Java API and back.- Returns:
- The web service instance mapping from ILM to the Java API and back.
-
getLogger
protected Logger getLogger()
Gets the logger to be used by web service endpoint implementations.- Returns:
- The logger to be used by web service endpoint implementations.
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Gets the object mapper for stubs of this root resource.- Returns:
- The object mapper for stubs of this root resource.
-
adaptSessionTokenParam
protected Exception adaptSessionTokenParam(Exception e)
Adapts the designated exception in case of aParameterException
and a#LOCATION_OPERATION
by setting the name to#SECURITY_TOKEN
, the expected class name tobyte[]
and the location to#LOCATION_HEADER
and#LOCATION_COOKIE
. AParameterException
with a operation location stems from the generic ILM part which a REST user will probably not understand.- Parameters:
e
- Possibly aParameterException
which to adapt.- Returns:
- The designated
Exception
possibly aParameterException
with adapted values for the parameter name, expected class name, message as well as location.
-
ensureReqMinVersion
protected void ensureReqMinVersion(String required)
Ensures that the current request wants at least the designatedrequired
API version (or the same or the current, aka.null
).- Parameters:
required
- The version the current request needs to request at least (or no version).
-
ensureReqMaxVersion
protected void ensureReqMaxVersion(String required)
Ensures that the current request wants at most the designatedrequired
API version (or the same but not no version).- Parameters:
required
- The version the current request needs to request at most (and not no version).
-
ensureVersion
protected static void ensureVersion(de.aristaflow.adept2.base.communication.rest.RequestHandler handler, String required, boolean ensureRequestLess)
Ensures that the version of the request is less (or more) than the designatedrequired
version. Otherwise aServiceUnavailableException
will be thrown.
If the request does not specify an API version, the current API version is expected which is never less and always more. A request version being the same as the required version is always accepted.- Parameters:
handler
- The request handler providing the API version that has been requested by the client. The API version need not be specified (and will then always be more than the required version).required
- The required version with which to compare the API version specified by the designated request.ensureRequestLess
- Whether to ensure that the API level of the designated request is less or equal to the designated request and notnull
. Otherwise it may be more or equal ornull
.
-
ping
@GET @Path("/start-time") @NotNull @Min(-1L) public @NotNull @Min(-1L) Long ping(@Context javax.ws.rs.core.Application unused)
- Parameters:
unused
- This unused parameter just prevents Bean Validation from treating this method as simple getter and calling it arbitrarily even without request context.- See Also:
AbstractRootResourceWebService.ping()
-
getRelease
@GET @Path("/release") @NotNull @Valid public @NotNull @Valid ServiceRelease getRelease(@Context javax.ws.rs.core.Application unused)
- Parameters:
unused
- This unused parameter just prevents Bean Validation from treating this method as simple getter and calling it arbitrarily even without request context.- See Also:
AbstractRootResourceWebService.getRelease()
-
getServiceInstanceName
@GET @Path("/service-instance-name") @NotNull @Valid public @NotNull @Valid ServiceInstanceName getServiceInstanceName(@Context javax.ws.rs.core.Application unused)
- Parameters:
unused
- This unused parameter just prevents Bean Validation from treating this method as simple getter and calling it arbitrarily even without request context.- See Also:
AbstractRootResourceWebService.getServiceInstanceName()
-
getUris
@GET @Path("/uris") @NotEmpty public @NotEmpty List<URI> getUris(@Context javax.ws.rs.core.Application unused)
- Parameters:
unused
- This unused parameter just prevents Bean Validation from treating this method as simple getter and calling it arbitrarily even without request context.- See Also:
AbstractRootResourceWebService.getUris()
-
registerSse
@GET @Path("/sse") @Produces("text/event-stream") public void registerSse(@Context javax.ws.rs.sse.SseEventSink eventSink, @Context javax.ws.rs.sse.Sse sse)
This operation registers an SSE connection which can be used for server events by all services. You will have to register the connection first before you can use it.
There will be a start event named "SseConnectionEstablished" sending the ID of the connection as plain text. This ID needs to be provided when starting service-specific notifications.In case of problems, this operation will return an exception using
#APPLICATION_JSON
. The exception will also be sent via SSE with the expected event name. This may lead to the event data having an unexpected type (an exception serialised as JSON). If the exception cannot be sent, the SSE connection will simply be closed.While the SSE connection can simply be closed, it is strongly suggested to unregister it properly allowing to clean up resources.
-
unregisterSse
@DELETE @Path("/sse/{sseId}") @NotNull public @NotNull Boolean unregisterSse(@PathParam("sseId") UUID sseId)
This operation unregisters the designated SSE connection. Unlike simply closing it, this allows for properly releasing all resources.- Returns:
- Whether unregistering has been successful. If not, the SSE connection may have been closed before.
-
headerData
@PUT @Path("/header-data") public void headerData(@HeaderParam("x-AF-Accept-Version") String apiVersion, @HeaderParam("x-AF-Security-Token") String token, @HeaderParam("x-AF-Caller-URI") URI callerUri, @HeaderParam("x-AF-Session-ID") UUID sessionId, @HeaderParam("x-AF-Add-UrlEnc-Attr") String addAttributes, @HeaderParam("x-AF-Exception-Stack") Boolean keepExceptionStack)
This method just serves documentation purpose. It has all parameters that most other methods accept/require as header data.
-
-