Class AwsProductSender

    • Field Detail

      • LOGGER

        public static final java.util.logging.Logger LOGGER
        Initialzation of logger. For us later in file.
      • HUB_URL_PROPERTY

        public static final java.lang.String HUB_URL_PROPERTY
        Base URL for Hub API.
        See Also:
        Constant Field Values
      • PRIVATE_KEY_PROPERTY

        public static final java.lang.String PRIVATE_KEY_PROPERTY
        Private Key to sign products, if signProducts is true.
        See Also:
        Constant Field Values
      • SIGN_PRODUCTS_PROPERTY

        public static final java.lang.String SIGN_PRODUCTS_PROPERTY
        Whether to sign products using private key.
        See Also:
        Constant Field Values
      • hubUrl

        protected java.net.URL hubUrl
        url where products are sent
      • privateKey

        protected java.security.PrivateKey privateKey
        signing key
      • signProducts

        protected boolean signProducts
        wheter to sign products
      • connectTimeout

        protected int connectTimeout
        Connection timeout. 5s seems excessive, but be cautious for now
      • readTimeout

        protected int readTimeout
        Server-side timeout. Called at getInputStream().read()
    • Constructor Detail

      • AwsProductSender

        public AwsProductSender()
        Empty class constructor
      • AwsProductSender

        public AwsProductSender​(java.net.URL url)
    • Method Detail

      • configure

        public void configure​(Config config)
                       throws java.lang.Exception
        Description copied from class: DefaultConfigurable
        Process configuration settings. Called before startup().
        Specified by:
        configure in interface Configurable
        Overrides:
        configure in class DefaultConfigurable
        Parameters:
        config - the Config object with settings.
        Throws:
        java.lang.Exception - if configuration exceptions occur.
      • sendProduct

        public void sendProduct​(Product product)
                         throws java.lang.Exception
        Send a product to the hub.
        Specified by:
        sendProduct in interface ProductSender
        Parameters:
        product - the product to send.
        Throws:
        java.lang.Exception - if any errors occur while sending.
      • getUploadUrls

        protected Product getUploadUrls​(javax.json.JsonObject json)
                                 throws java.lang.Exception
        Get content upload urls.
        Parameters:
        json - product in json format.
        Returns:
        product with content urls set to upload URLs.
        Throws:
        java.lang.Exception - Exception
      • postProductJson

        protected HttpResponse postProductJson​(java.net.URL url,
                                               javax.json.JsonObject product)
                                        throws java.lang.Exception
        Post product json to a hub url. This is a HTTP POST method, with a JSON content body with a "product" property with the product.
        Parameters:
        url - url of connection
        product - product in json format
        Returns:
        new HTTP POST response
        Throws:
        java.lang.Exception - Exception
      • sendProduct

        protected Product sendProduct​(javax.json.JsonObject json)
                               throws java.lang.Exception
        Send product after content has been uploaded.
        Parameters:
        json - product in json format.
        Returns:
        product with content urls pointing to hub.
        Throws:
        java.lang.Exception - Exception
      • uploadContent

        protected HttpResponse uploadContent​(java.lang.String path,
                                             Content content,
                                             java.net.URL signedUrl)
                                      throws java.lang.Exception
        Upload content to a signed url.
        Parameters:
        path - content path.
        content - content to upload.
        signedUrl - url where content should be uploaded.
        Returns:
        HTTP result
        Throws:
        java.lang.Exception - Exception
      • uploadContents

        protected java.util.Map<java.lang.String,​HttpResponse> uploadContents​(Product product,
                                                                                    Product uploadProduct)
                                                                             throws java.lang.Exception
        Upload product contents. Runs uploads in parallel using a parallel stream. This can be called within a custom ForkJoinPool to use a non-default pool, the default pool is shared by the process and based on number of available cores.
        Parameters:
        product - product to upload.
        uploadProduct - product with signed upload urls.
        Returns:
        upload results
        Throws:
        java.lang.Exception - if any upload errors occur
      • getSignProducts

        public boolean getSignProducts()
        Getter for signProducts
        Returns:
        boolean
      • setSignProducts

        public void setSignProducts​(boolean sign)
        Setter for signProducts
        Parameters:
        sign - boolean
      • getPrivateKey

        public java.security.PrivateKey getPrivateKey()
        getter for privateKey
        Returns:
        privateKey
      • setPrivateKey

        public void setPrivateKey​(java.security.PrivateKey key)
        setting for privateKey
        Parameters:
        key - PrivateKey