All Products
Search
Document Center

Environment interface

Last Updated: May 08, 2020

The environment initialization API init is used to initialize the environment configuration.

  • Function prototype
  1. public boolean init(final ClientEnv env)
  • Request parameter
Parameter Required Type Description
env true ClientEnv The client environment-related information.
  • Example
  1. ClientEnv env = buildClientEnv();
  2. MychainClient sdk = new MychainClient();
  3. sdk.init(env);
  4. private static MychainEnv buildClientEnv() {
  5. String keyFilePath = "client.key";
  6. String certFilePath = "client.crt";
  7. String trustStoreFilePath = "trustCa";
  8. // build ssl option
  9. ISslOption sslOption = new SslBytesOption.Builder()
  10. .keyBytes(Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(keyFilePath).getPath()))
  11. .certBytes(Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(certFilePath).getPath()))
  12. .keyPassword(keyPassword)
  13. .trustStorePassword(trustStorePassword)
  14. .trustStoreBytes(
  15. Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(trustStoreFilePath).getPath()))
  16. .build();
  17. // ip and port
  18. InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved(host, port);
  19. List<InetSocketAddress> socketAddressArrayList = new ArrayList<>();
  20. socketAddressArrayList.add(inetSocketAddress);
  21. ClientEnv env = ClientEnv.build(socketAddressArrayList, sslOption, signerOption);
  22. // if you need to use https, you need to set the following information.
  23. env.getNetworkOption().setNetworkType(NetworkType.HTTPS);
  24. env.getNetworkOption().setCodecType(CodecType.JSON);
  25. return env;
  26. }