The environment initialization API init
is used to initialize the environment configuration.
- Function prototype
public boolean init(final ClientEnv env)
- Request parameter
Parameter | Required | Type | Description |
---|---|---|---|
env | true | ClientEnv | The client environment-related information. |
- Example
ClientEnv env = buildClientEnv();
MychainClient sdk = new MychainClient();
sdk.init(env);
private static MychainEnv buildClientEnv() {
String keyFilePath = "client.key";
String certFilePath = "client.crt";
String trustStoreFilePath = "trustCa";
// build ssl option
ISslOption sslOption = new SslBytesOption.Builder()
.keyBytes(Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(keyFilePath).getPath()))
.certBytes(Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(certFilePath).getPath()))
.keyPassword(keyPassword)
.trustStorePassword(trustStorePassword)
.trustStoreBytes(
Utils.readFileToByteArray(DemoSample.class.getClassLoader().getResource(trustStoreFilePath).getPath()))
.build();
// ip and port
InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved(host, port);
List<InetSocketAddress> socketAddressArrayList = new ArrayList<>();
socketAddressArrayList.add(inetSocketAddress);
ClientEnv env = ClientEnv.build(socketAddressArrayList, sslOption, signerOption);
// if you need to use https, you need to set the following information.
env.getNetworkOption().setNetworkType(NetworkType.HTTPS);
env.getNetworkOption().setCodecType(CodecType.JSON);
return env;
}