All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.mstream.trader.datafeed.stocks.quandl.QuandlSslEngineSupplier Maven / Gradle / Ivy

The newest version!
package io.mstream.trader.datafeed.stocks.quandl;


import io.mstream.trader.commons.config.model.DownstreamService;

import javax.inject.Inject;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import java.net.URI;
import java.util.function.Supplier;


class QuandlSslEngineSupplier
        implements Supplier {
    
    private final Supplier configSupplier;
    
    @Inject
    public QuandlSslEngineSupplier(
            @Quandl
                    Supplier configSupplier
    ) {
        
        this.configSupplier = configSupplier;
    }
    
    @Override
    public SSLEngine get() {
        
        String url = configSupplier
                .get()
                .getUrl()
                .url();
        
        try {
            URI uri = new URI(url);
            
            String host = uri.getHost();
            int port = uri.getPort();
            
            SSLContext sslContext = SSLContext.getDefault();
            SSLEngine sslEngine = sslContext.createSSLEngine(host, port);
            
            sslEngine.setUseClientMode(true);
            
            return sslEngine;
            
        } catch (Exception e) {
            throw new RuntimeException("can't create a SSL engine", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy