Class AbstractRestProcessService<I,​O>

    • Field Detail

      • connection

        private java.net.HttpURLConnection connection
      • executor

        private java.util.concurrent.ExecutorService executor
      • client

        private org.apache.http.impl.client.CloseableHttpClient client
    • Constructor Detail

      • AbstractRestProcessService

        protected AbstractRestProcessService​(de.iip_ecosphere.platform.transport.serialization.TypeTranslator<I,​java.lang.String> inTrans,
                                             de.iip_ecosphere.platform.transport.serialization.TypeTranslator<java.lang.String,​O> outTrans,
                                             de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback,
                                             YamlService yaml)
        Creates an instance of the service with the required type translators.
        Parameters:
        inTrans - the input translator
        outTrans - the output translator
        callback - called when data from the service is available
        yaml - the service description
    • Method Detail

      • getApiPath

        protected abstract java.lang.String getApiPath()
        Returns the HTTP/HTTPS path to the REST API.
        Returns:
        the path
      • getConnection

        protected java.net.HttpURLConnection getConnection()
        Returns the connection instance.
        Returns:
        the connection instance, may be null if service was not started before
      • getBearerToken

        protected abstract java.lang.String getBearerToken()
        Returns the bearer token for authentication.
        Returns:
        the bearer token, may be null for none
      • getNewConnectionInstance

        protected java.net.HttpURLConnection getNewConnectionInstance()
                                                               throws java.io.IOException
        Creates a new connection and overwrites the existing connection instance.
        Returns:
        the created connection
        Throws:
        java.io.IOException - if creating the connection fails
      • setupConnectionManager

        protected void setupConnectionManager()
        Sets up the connection manager and creates a new httpClient based on a connection pool.
      • getNewConnectionInstanceQuiet

        protected void getNewConnectionInstanceQuiet​(boolean changeState)
        Get Connection to local server.
        Parameters:
        changeState - whether the state shall be changed if the connection creation fails
      • process

        public void process​(I data)
                     throws java.io.IOException
        Description copied from class: AbstractProcessService
        Requests to process the given data item.
        Specified by:
        process in class AbstractProcessService<I,​java.lang.String,​java.lang.String,​O>
        Parameters:
        data - the data to process
        Throws:
        java.io.IOException - if processing/transferring to the service fails
      • adjustRestQuery

        protected abstract java.lang.String adjustRestQuery​(java.lang.String input)
        Adjusts the input produced by AbstractProcessService.getInputTranslator() to the actual receiver.
        Parameters:
        input - the input
        Returns:
        the adjusted input
      • adjustRestResponse

        protected abstract java.lang.String adjustRestResponse​(java.lang.String response)
        The rest response.
        Parameters:
        response - the received response
        Returns:
        the adjusted response
      • redirectRest

        public void redirectRest​(java.net.HttpURLConnection connection,
                                 de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<O> callback)
        Redirects rest answers to the reception callback.
        Parameters:
        connection - the connection to redirect
        callback - the callback to use
        See Also:
        adjustRestResponse(String)
      • handleInputStream

        protected void handleInputStream​(java.io.InputStream in)
        Description copied from class: AbstractProcessService
        Handles the input stream upon process creation.
        Specified by:
        handleInputStream in class AbstractProcessService<I,​java.lang.String,​java.lang.String,​O>
        Parameters:
        in - the process input stream