added properties printer to debug error

develop
bvn13 2020-05-04 17:05:49 +03:00
parent 2da55bd99a
commit fcca438980
3 changed files with 60 additions and 7 deletions

View File

@ -0,0 +1,57 @@
package com.bvn13.covid19.scheduler;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.StandardServletEnvironment;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
@Component
public class PropertiesPrinter extends PropertySourcesPlaceholderConfigurer {
private static final String ENVIRONMENT_PROPERTIES = "environmentProperties";
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
super.postProcessBeanFactory(beanFactory);
final StandardServletEnvironment propertySources =
(StandardServletEnvironment) super.getAppliedPropertySources().get(ENVIRONMENT_PROPERTIES).getSource();
propertySources.getPropertySources().forEach(propertySource -> {
if (propertySource.getSource() instanceof Map) {
// it will print systemProperties, systemEnvironment, application.properties and other overrides of
// application.properties
System.out.println("#######" + propertySource.getName() + "#######");
final Map<String, String> properties = mapValueAsString((Map<String, Object>) propertySource.getSource());
System.out.println(toString(properties));
}
});
}
private Map<String, String> mapValueAsString(final Map<String, Object> map) {
return map.entrySet().stream()
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> toString(entry.getValue())));
}
private String toString(final Object object) {
return Optional.ofNullable(object).map(value -> value.toString()).orElse(null);
}
private String toString(Map<String, String> properties) {
StringBuilder sb = new StringBuilder();
Set<String> keys = new TreeSet<>(properties.keySet());
keys.forEach((k) -> {
sb.append(k).append(" = ").append(properties.get(k)).append("\n");
});
return sb.toString();
}
}

View File

@ -18,14 +18,11 @@ package com.bvn13.covid19.scheduler.updater.stopcoronovirusrf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import javax.annotation.PostConstruct;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
@NoArgsConstructor
@Data
@ -34,7 +31,7 @@ import javax.validation.constraints.Min;
public class MailConfig {
private String username;
private String password;
private String passwd;
private String host;
private int port;
private String sender;
@ -46,7 +43,7 @@ public class MailConfig {
public void init() {
if (StringUtils.isBlank(host) ||
StringUtils.isBlank(username) ||
StringUtils.isBlank(password) ||
StringUtils.isBlank(passwd) ||
StringUtils.isBlank(sender) ||
StringUtils.isBlank(recipient) ||
StringUtils.isBlank(subject) ||
@ -60,7 +57,7 @@ public class MailConfig {
public String constructEndpoint() {
return "smtps://" + host + ":" + port +
"?username=" + username +
"&password=" + password +
"&password=" + passwd +
"&from=" + sender +
"&to=" + recipient +
"&subject=" + subject +

View File

@ -24,7 +24,6 @@ import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;