use of com.dtflys.forest.springboot.properties.ForestConvertProperties in project forest by dromara.
the class ForestBeanRegister method registerForestConfiguration.
public ForestConfiguration registerForestConfiguration(ForestConfigurationProperties forestConfigurationProperties) {
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ForestConfiguration.class);
String id = forestConfigurationProperties.getBeanId();
if (StringUtils.isBlank(id)) {
id = "forestConfiguration";
}
Class<? extends ForestLogHandler> logHandlerClass = forestConfigurationProperties.getLogHandler();
ForestLogHandler logHandler = null;
if (logHandlerClass != null) {
try {
logHandler = logHandlerClass.newInstance();
} catch (InstantiationException e) {
throw new ForestRuntimeException(e);
} catch (IllegalAccessException e) {
throw new ForestRuntimeException(e);
}
}
beanDefinitionBuilder.addPropertyValue("maxAsyncThreadSize", forestConfigurationProperties.getMaxAsyncThreadSize()).addPropertyValue("maxConnections", forestConfigurationProperties.getMaxConnections()).addPropertyValue("maxRouteConnections", forestConfigurationProperties.getMaxRouteConnections()).addPropertyValue("timeout", forestConfigurationProperties.getTimeout()).addPropertyValue("connectTimeout", forestConfigurationProperties.getConnectTimeoutMillis()).addPropertyValue("readTimeout", forestConfigurationProperties.getReadTimeoutMillis()).addPropertyValue("charset", forestConfigurationProperties.getCharset()).addPropertyValue("retryer", forestConfigurationProperties.getRetryer()).addPropertyValue("maxRetryCount", forestConfigurationProperties.getMaxRetryCount()).addPropertyValue("maxRetryInterval", forestConfigurationProperties.getMaxRetryInterval()).addPropertyValue("autoRedirection", forestConfigurationProperties.isAutoRedirection()).addPropertyValue("logEnabled", forestConfigurationProperties.isLogEnabled()).addPropertyValue("logRequest", forestConfigurationProperties.isLogRequest()).addPropertyValue("logResponseStatus", forestConfigurationProperties.isLogResponseStatus()).addPropertyValue("logResponseContent", forestConfigurationProperties.isLogResponseContent()).addPropertyValue("logHandler", logHandler).addPropertyValue("backendName", forestConfigurationProperties.getBackend()).addPropertyValue("baseAddressScheme", forestConfigurationProperties.getBaseAddressScheme()).addPropertyValue("baseAddressHost", forestConfigurationProperties.getBaseAddressHost()).addPropertyValue("baseAddressPort", forestConfigurationProperties.getBaseAddressPort()).addPropertyValue("baseAddressSourceClass", forestConfigurationProperties.getBaseAddressSource()).addPropertyValue("successWhenClass", forestConfigurationProperties.getSuccessWhen()).addPropertyValue("retryWhenClass", forestConfigurationProperties.getRetryWhen()).addPropertyValue("interceptors", forestConfigurationProperties.getInterceptors()).addPropertyValue("sslProtocol", forestConfigurationProperties.getSslProtocol()).addPropertyValue("variables", forestConfigurationProperties.getVariables()).setLazyInit(false).setFactoryMethod("configuration");
BeanDefinition forestPropertiesBean = registerForestPropertiesBean();
beanDefinitionBuilder.addPropertyValue("properties", forestPropertiesBean);
BeanDefinition forestObjectFactoryBeanDefinition = registerForestObjectFactoryBean();
beanDefinitionBuilder.addPropertyValue("forestObjectFactory", forestObjectFactoryBeanDefinition);
BeanDefinition interceptorFactoryBeanDefinition = registerInterceptorFactoryBean();
beanDefinitionBuilder.addPropertyValue("interceptorFactory", interceptorFactoryBeanDefinition);
List<ForestSSLKeyStoreProperties> sslKeyStorePropertiesList = forestConfigurationProperties.getSslKeyStores();
ManagedMap<String, BeanDefinition> sslKeystoreMap = new ManagedMap<>();
for (ForestSSLKeyStoreProperties keyStoreProperties : sslKeyStorePropertiesList) {
registerSSLKeyStoreBean(sslKeystoreMap, keyStoreProperties);
}
BeanDefinition beanDefinition = beanDefinitionBuilder.getRawBeanDefinition();
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
beanDefinition.getPropertyValues().addPropertyValue("sslKeyStores", sslKeystoreMap);
BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) applicationContext.getBeanFactory();
beanFactory.registerBeanDefinition(id, beanDefinition);
ForestConfiguration configuration = applicationContext.getBean(id, ForestConfiguration.class);
Map<String, Class> filters = forestConfigurationProperties.getFilters();
for (Map.Entry<String, Class> entry : filters.entrySet()) {
String filterName = entry.getKey();
Class filterClass = entry.getValue();
configuration.registerFilter(filterName, filterClass);
}
ForestConvertProperties convertProperties = forestConfigurationProperties.getConverters();
if (convertProperties != null) {
registerConverter(configuration, ForestDataType.TEXT, convertProperties.getText());
registerConverter(configuration, ForestDataType.JSON, convertProperties.getJson());
registerConverter(configuration, ForestDataType.XML, convertProperties.getXml());
registerConverter(configuration, ForestDataType.BINARY, convertProperties.getBinary());
registerConverter(configuration, ForestDataType.PROTOBUF, convertProperties.getProtobuf());
}
registerConverterBeanListener(configuration);
return configuration;
}
Aggregations