SUPPORT-8381: set property as required
This commit is contained in:
parent
51635810a7
commit
9f76a5b13b
2 changed files with 22 additions and 27 deletions
|
|
@ -19,17 +19,17 @@ import org.springframework.kafka.core.ProducerFactory;
|
|||
*/
|
||||
@Configuration
|
||||
public class KafkaProducerConfig {
|
||||
@Value("${kafka.send.url:#{null}}")
|
||||
@Value("${kafka.send.url}")
|
||||
private String kafkaUrl;
|
||||
@Value("${kafka.send.security.protocol:#{null}}")
|
||||
@Value("${kafka.send.security.protocol}")
|
||||
private String securityProtocol;
|
||||
@Value("${kafka.send.login.module:org.apache.kafka.common.security.scram.ScramLoginModule}")
|
||||
private String loginModule;
|
||||
@Value("${kafka.send.username:#{null}}")
|
||||
@Value("${kafka.send.username}")
|
||||
private String username;
|
||||
@Value("${kafka.send.password:#{null}}")
|
||||
@Value("${kafka.send.password}")
|
||||
private String password;
|
||||
@Value("${kafka.sasl.mechanism:#{null}}")
|
||||
@Value("${kafka.sasl.mechanism}")
|
||||
private String saslMechanism;
|
||||
|
||||
@Bean
|
||||
|
|
@ -39,20 +39,15 @@ public class KafkaProducerConfig {
|
|||
|
||||
@Bean
|
||||
public Map<String, Object> producerConfigs() {
|
||||
if (this.kafkaUrl == null) {
|
||||
throw new RuntimeException("Property kafka.send.url is null");
|
||||
}
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.kafkaUrl);
|
||||
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
|
||||
|
||||
if (securityProtocol != null && username != null && password != null && saslMechanism != null) {
|
||||
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
|
||||
props.put(SaslConfigs.SASL_JAAS_CONFIG, loginModule + " required username=\""
|
||||
+ username + "\" password=\"" + password + "\";");
|
||||
props.put(SaslConfigs.SASL_MECHANISM, saslMechanism);
|
||||
}
|
||||
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol);
|
||||
props.put(SaslConfigs.SASL_JAAS_CONFIG, loginModule + " required username=\""
|
||||
+ username + "\" password=\"" + password + "\";");
|
||||
props.put(SaslConfigs.SASL_MECHANISM, saslMechanism);
|
||||
|
||||
return props;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,26 +23,26 @@ public class EmployeeInfoWebDavClient {
|
|||
|
||||
@Value("${file.webdav.upload.url:http://localhost:5757}")
|
||||
private String url;
|
||||
@Value("${file.webdav.upload.username:#{null}}")
|
||||
@Value("${file.webdav.upload.username}")
|
||||
private String username;
|
||||
@Value("${file.webdav.upload.password:#{null}}")
|
||||
@Value("${file.webdav.upload.password}")
|
||||
private String password;
|
||||
|
||||
public boolean webDavUploadFile(String filename, MultipartFile multipartFile) {
|
||||
try {
|
||||
HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
|
||||
if (username != null && password != null) {
|
||||
httpClientBuilder.authenticator(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password.toCharArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
HttpClient httpClient = HttpClient.newBuilder()
|
||||
.authenticator(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password.toCharArray());
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
HttpRequest httpRequest = HttpRequest.newBuilder().uri(URI.create(this.url + "/" + filename))
|
||||
.PUT(HttpRequest.BodyPublishers.ofByteArray(multipartFile.getBytes())).build();
|
||||
HttpResponse<String> response = httpClientBuilder.build()
|
||||
.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
HttpResponse<String> response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||
logger.debug("Response starus code: {}", response.statusCode());
|
||||
return (response.statusCode() >= 200) && (response.statusCode() <= 202);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue