Class AssetRestServer

java.lang.Object
de.iip_ecosphere.platform.support.aas.basyx2.AssetRestServer
All Implemented Interfaces:
de.iip_ecosphere.platform.support.Server

public class AssetRestServer extends Object implements de.iip_ecosphere.platform.support.Server
Implements a simple Asset REST server as alternative to the (usually Tomcat-based) BaSyX-like implementation. The implementation is based on the REST plugin abstraction of oktoflow (assuming a non-Tomcat-based implementation to avoid conflicts with the singleton call of URL.setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)) but re-using BaSyx components where adequate.
Author:
Holger Eichelberger, SSE
  • Field Details

    • PREFIX_AUTH_BASIC

      private static final String PREFIX_AUTH_BASIC
      See Also:
    • PREFIX_AUTH_BEARER

      private static final String PREFIX_AUTH_BEARER
      See Also:
    • opProvider

      private AasOperationsProvider opProvider
    • setup

      private de.iip_ecosphere.platform.support.aas.SetupSpec.ComponentSetup setup
    • server

      private de.iip_ecosphere.platform.support.rest.Rest.RestServer server
    • mapper

      private com.fasterxml.jackson.databind.ObjectMapper mapper
    • users

      private Map<String,de.iip_ecosphere.platform.support.aas.AuthenticationDescriptor.IdentityTokenWithRole> users
  • Constructor Details

    • AssetRestServer

      public AssetRestServer(AasOperationsProvider opProvider, de.iip_ecosphere.platform.support.aas.SetupSpec.ComponentSetup setup)
      Creates an Asset REST server instance.
      Parameters:
      opProvider - the operations provider
      setup - the component setup
  • Method Details

    • start

      public de.iip_ecosphere.platform.support.Server start()
      Specified by:
      start in interface de.iip_ecosphere.platform.support.Server
    • setupAuthentication

      private void setupAuthentication(de.iip_ecosphere.platform.support.aas.AuthenticationDescriptor auth)
      Sets up the authentication.
      Parameters:
      auth - the authentication descriptor
    • handle

      private String handle(de.iip_ecosphere.platform.support.rest.Rest.Request req, de.iip_ecosphere.platform.support.rest.Rest.Response res, String opName, String category)
      Handles an operation call request.
      Parameters:
      req - the HTTP request
      res - the HTTP response
      opName - the operation name
      category - the category, may be null then a service function is determined based on opName
      Returns:
      the result body
    • invokeOperation

      static AssetRestServer.ResponseEnt<org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable[]> invokeOperation(String opName, org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable[] requestData, Function<Object[],Object> func)
      Executes a given function.
      Parameters:
      opName - the operation name
      requestData - the request data
      func - the function, may be null
      Returns:
      the function execution result
    • appendKey

      private String appendKey(String key, String text)
      Appends a JSON key to text.
      Parameters:
      key - the key
      text - the text to append to
      Returns:
      the appended text
    • appendValue

      private String appendValue(String key, String value, String text)
      Appends a JSON key-value pair to text.
      Parameters:
      key - the key
      value - the value
      Returns:
      the appended text
    • appendValue

      private String appendValue(String key, Number value, String text)
      Appends a JSON key-value pair to text.
      Parameters:
      key - the key
      value - the value
      Returns:
      the appended text
    • createErrorObject

      private String createErrorObject(de.iip_ecosphere.platform.support.rest.Rest.Request req, de.iip_ecosphere.platform.support.rest.Rest.Response res, AssetRestServer.HttpStat status, String error)
      Creates an error object (not using mapper to avoid further exception handling).
      Parameters:
      req - the request object
      res - the response object
      status - the status code (to be set on res)
      error - the error description
      Returns:
      the error object as JSON string
    • stop

      public void stop(boolean dispose)
      Specified by:
      stop in interface de.iip_ecosphere.platform.support.Server