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

io.mstream.trader.simulation.stocks.datafeed.client.DataFeedSslEngineSupplier Maven / Gradle / Ivy

package io.mstream.trader.simulation.stocks.datafeed.client;


import io.mstream.trader.commons.config.model.DownstreamService;
import io.mstream.trader.simulation.stocks.datafeed.api.DataFeed;

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


class DataFeedSslEngineSupplier
        implements Supplier {
    
    private final Supplier configSupplier;
    
    @Inject
    public DataFeedSslEngineSupplier(
            @DataFeed
                    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