use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ForestRequest method getSSLSocketFactory.
/**
* 获取 SSL Socket 工厂
*
* @return SSL Socket 工厂
*/
public SSLSocketFactory getSSLSocketFactory() {
if (sslSocketFactoryBuilder != null) {
try {
return sslSocketFactoryBuilder.getSSLSocketFactory(this, getSslProtocol());
} catch (Exception e) {
throw new ForestRuntimeException(e);
}
}
SSLKeyStore keyStore = this.getKeyStore();
if (keyStore == null) {
return SSLUtils.getDefaultSSLSocketFactory(this, getSslProtocol());
}
SSLSocketFactoryBuilder sslSocketFactoryBuilder = keyStore.getSslSocketFactoryBuilder();
if (sslSocketFactoryBuilder == null) {
return SSLUtils.getDefaultSSLSocketFactory(this, getSslProtocol());
}
try {
SSLSocketFactory sslSocketFactory = sslSocketFactoryBuilder.getSSLSocketFactory(this, getSslProtocol());
if (sslSocketFactory == null) {
return SSLUtils.getDefaultSSLSocketFactory(this, getSslProtocol());
}
return sslSocketFactory;
} catch (Exception e) {
throw new ForestRuntimeException(e);
}
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ForestURL method setBasePath.
/**
* 设置URL根路径
* <p>该路径为整个URL去除前面协议 + Host + Port 后部分
*
* @param basePath
*/
public ForestURL setBasePath(String basePath) {
if (basePath == null) {
return this;
}
this.basePath = basePath.trim();
if (!this.basePath.startsWith("/")) {
if (URLUtils.isURL(this.basePath)) {
try {
URL url = new URL(this.basePath);
this.scheme = url.getProtocol();
this.userInfo = url.getUserInfo();
this.host = url.getHost();
this.port = url.getPort();
this.basePath = url.getPath();
} catch (MalformedURLException e) {
throw new ForestRuntimeException(e);
}
} else {
this.basePath = "/" + this.basePath;
}
}
this.originalUrl = toURLString();
return this;
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class DefaultInterceptorFactory method createInterceptor.
protected <T extends Interceptor> Interceptor createInterceptor(Class<T> clazz) {
Interceptor interceptor;
try {
interceptor = clazz.newInstance();
interceptorMap.put(clazz, interceptor);
} catch (InstantiationException e) {
throw new ForestRuntimeException(e);
} catch (IllegalAccessException e) {
throw new ForestRuntimeException(e);
}
return interceptor;
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ForestConfigurationBeanDefinitionParser method parse.
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
RootBeanDefinition beanDefinition = new RootBeanDefinition();
beanDefinition.setBeanClass(FOREST_CONFIGURATION_CLASS);
beanDefinition.setLazyInit(false);
beanDefinition.setFactoryMethodName("configuration");
String id = element.getAttribute("id");
BeanDefinition objectFactoryBean = createForestObjectFactoryBean();
beanDefinition.getPropertyValues().addPropertyValue("forestObjectFactory", objectFactoryBean);
BeanDefinition interceptorFactoryBean = createInterceptorFactoryBean();
beanDefinition.getPropertyValues().addPropertyValue("interceptorFactory", interceptorFactoryBean);
id = ClientFactoryBeanUtils.getBeanId(id, FOREST_CONFIGURATION_CLASS, parserContext);
if (id != null && id.length() > 0) {
if (parserContext.getRegistry().containsBeanDefinition(id)) {
throw new IllegalStateException("Duplicate spring bean id " + id);
}
parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
ConstructorArgumentValues argumentValues = new ConstructorArgumentValues();
argumentValues.addIndexedArgumentValue(0, id);
beanDefinition.setConstructorArgumentValues(argumentValues);
}
Method[] methods = FOREST_CONFIGURATION_CLASS.getMethods();
for (Method method : methods) {
String methodName = method.getName();
Class[] paramTypes = method.getParameterTypes();
if (paramTypes.length == 0 || paramTypes.length > 1) {
continue;
}
Class paramType = paramTypes[0];
if (Collections.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
continue;
}
if (methodName.length() >= 3 && methodName.startsWith("set")) {
String attributeName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
String attributeValue = element.getAttribute(attributeName);
if (StringUtils.isNotEmpty(attributeValue)) {
if ("backend".equals(attributeName)) {
beanDefinition.getPropertyValues().addPropertyValue("backendName", attributeValue);
} else if ("logHandler".equals(attributeName)) {
try {
Class clazz = Class.forName(attributeValue);
if (!ForestLogHandler.class.isAssignableFrom(clazz)) {
throw new ForestRuntimeException("property 'logHandler' must be a class extending from com.dtflys.forest.logging.ForestLogHandler");
}
ForestLogHandler handler = (ForestLogHandler) clazz.newInstance();
beanDefinition.getPropertyValues().addPropertyValue("logHandler", handler);
} catch (ClassNotFoundException e) {
throw new ForestRuntimeException(e);
} catch (IllegalAccessException e) {
throw new ForestRuntimeException(e);
} catch (InstantiationException e) {
throw new ForestRuntimeException(e);
}
} else {
beanDefinition.getPropertyValues().addPropertyValue(attributeName, attributeValue);
}
}
}
}
parseChildren(element.getChildNodes(), beanDefinition);
LOG.info("[Forest] Created Forest Configuration Bean: " + beanDefinition);
return beanDefinition;
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ConverterBeanListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
ForestConfiguration forestConfiguration = this.forestConfiguration;
if (forestConfiguration == null) {
try {
forestConfiguration = applicationContext.getBean(ForestConfiguration.class);
} catch (Exception ignored) {
throw new ForestRuntimeException("property forestConfiguration undefined", ignored);
}
}
Map<String, ForestConverter> forestConverterMap = applicationContext.getBeansOfType(ForestConverter.class);
for (ForestConverter forestConverter : forestConverterMap.values()) {
forestConfiguration.getConverterMap().put(forestConverter.getDataType(), forestConverter);
}
}
Aggregations