private Channel initializeChannel()

in src/main/java/com/lambdajavablockchain/service/ManagedBlockchainService.java [166:203]


    private Channel initializeChannel(HFClient client) throws AppException {
        if (this.channel != null && this.channel.isInitialized()) {
            return channel;
        }
        try {
            // Read Managed Blockchain TLS certificate from resources folder
            Properties properties = new Properties();
            if (ambTlsCertAsString.isEmpty()) {
                properties.put("pemBytes", SecretsManagerUtil.readCert(AMBConfig.AMB_CERT_PATH));
            } else {
                properties.put("pemBytes", ambTlsCertAsString.getBytes());
            }

            properties.setProperty("sslProvider", "openSSL");
            properties.setProperty("negotiationType", "TLS");

            // Configure Peer
            Peer peer = client.newPeer(AMBConfig.ORG1_PEER_0, AMBConfig.ORG1_PEER_0_URL, properties);
            // Configure Orderer
            Orderer orderer = client.newOrderer(AMBConfig.ORDERER_NAME, AMBConfig.ORDERER_URL, properties);
            // Configure Channel
            Channel channel = client.newChannel(AMBConfig.CHANNEL_NAME);

            channel.addPeer(peer);
            channel.addOrderer(orderer);
            channel.initialize();

            return channel;
        } catch (InvalidArgumentException | TransactionException e) {
            e.printStackTrace();
            log.error("Unable to initialize channel - " + e.getMessage());
            throw new AppException("Unable to initialize channel", e);
        } catch (IOException e) {
            log.error("Could not find Managed Blockchain TLS certificate - " + e.getMessage());
            e.printStackTrace();
            throw new AppException("Managed Blockchain TLS certificate not found", e);
        }
    }