Logo
Section 1 / 5

服务器和客户端配置属性

显示 gRPC 服务器和客户端的配置属性。

导入

服务器和客户端配置属性

显示 gRPC 服务器和客户端的配置属性。

1DESTINATION_DIRECTORY_ON_SERVER=/Users/IdeaProjects/grpc-ftp-project/destOnServer/ 2TEMP_WRITE_PATH=/Users/IdeaProjects/grpc-ftp-project/destOnServer/tmp
1public class ServerConfiguration { 2 private static final Logger logger = LogManager.getLogger(ServerConfiguration.class); 3 private Properties properties; 4}
1public class ServerConfiguration { 2 private static final Logger logger = LogManager.getLogger(ServerConfiguration.class); 3 private Properties properties; 4 5 public ServerConfiguration(){ 6 properties = new Properties(); 7 } 8 9 public ServerConfiguration(String configFileName) { 10 properties = new Properties(); 11 File file = new File(configFileName); 12 13 try (FileInputStream inputStream = new FileInputStream(file)) { 14 properties.load(inputStream); 15 } catch (IOException e) { 16 logger.error("Cannot read in config file", e); 17 } 18 } 19}
1public String getDestinationDirectoryOnServer() { 2 return properties.getProperty(ServerConstants.DESTINATION_DIRECTORY_ON_SERVER); 3} 4 5public String getTempWritePath() { 6 return properties.getProperty(ServerConstants.TEMP_WRITE_PATH); 7}

client.config.properties file

1CLIENT_KEY_PATH=target/certs/clientKey.pem 2CLIENT_CERT_PATH=target/certs/clientCert.pem 3CA_CERT_PATH=target/certs/rootCACert.pem

ClientConfiguration class

1public class ClientConfiguration { 2 private Properties properties; 3}

ClientConfiguration class constructor

1public class ClientConfiguration { 2 private Properties properties; 3 4 public ClientConfiguration() { 5 try (InputStream input = 6 ClientConfiguration.class.getClassLoader().getResourceAsStream("client.config.properties")) { 7 properties = new Properties(); 8 properties.load(input); 9 } catch (IOException e) { 10 log.error("Cannot read in config file", e); 11 } 12 } 13}

Getter methods

1public String getCAPath() { 2 return properties.getProperty(ClientConstants.CA_CERT_PATH); 3} 4 5public String getClientCertPath() { 6 return properties.getProperty(ClientConstants.CLIENT_CERT_PATH); 7} 8 9public String getClientKeyPath() { 10 return properties.getProperty(ClientConstants.CLIENT_KEY_PATH); 11}

ClientConfiguration class

1/* 2 * Copyright 2023, DataJek.io 3 * All Rights Reserved 4 */ 5 6package io.datajek.ftpservice.utils; 7 8import java.io.IOException; 9import java.io.InputStream; 10import java.util.Properties; 11 12/** 13 * This class manages the configuration settings for the client. 14 */ 15public class ClientConfiguration { 16 17 private Properties properties; 18 19 public ClientConfiguration() { 20 try (InputStream input = 21 ClientConfiguration.class.getClassLoader().getResourceAsStream("client.config.properties")) { 22 properties = new Properties(); 23 properties.load(input); 24 } catch (IOException e) { 25 // log.error("Cannot read in config file", e); 26 } 27 } 28 29 public String getCAPath() { 30 return properties.getProperty(ClientConstants.CA_CERT_PATH); 31 } 32 33 public String getClientCertPath() { 34 return properties.getProperty(ClientConstants.CLIENT_CERT_PATH); 35 } 36 37 public String getClientKeyPath() { 38 return properties.getProperty(ClientConstants.CLIENT_KEY_PATH); 39 } 40}

gRPC 中的安全性

服务器和客户端常量