use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class MappingDot method getPropMethodFromClass.
public Method getPropMethodFromClass(Class clazz, MappingIdentity right) {
Method method = null;
String getterName = StringUtils.toGetterName(right.getName());
Throwable th = null;
try {
method = clazz.getDeclaredMethod(getterName);
} catch (NoSuchMethodException e) {
try {
method = clazz.getDeclaredMethod(right.getName());
} catch (NoSuchMethodException e1) {
th = e1;
}
}
if (method == null) {
if (!Object.class.equals(clazz)) {
return getPropMethodFromClass(clazz.getSuperclass(), right);
}
if (th != null) {
throw new ForestRuntimeException(th);
}
}
return method;
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class SSLTest2 method testConfiguration.
@Test
public void testConfiguration() {
ForestLogger logger = Mockito.mock(ForestLogger.class);
assertEquals(Integer.valueOf(300), sslConfig.getMaxConnections());
assertEquals(Integer.valueOf(300), sslConfig.getMaxRouteConnections());
assertEquals(Integer.valueOf(3000), sslConfig.getTimeout());
assertEquals(Integer.valueOf(3000), sslConfig.getConnectTimeout());
assertEquals(Integer.valueOf(2), sslConfig.getMaxRetryCount());
assertEquals(1, sslConfig.getSslKeyStores().size());
SSLKeyStore sslKeyStore = sslConfig.getKeyStore("keystore1");
assertThat(sslKeyStore).isNotNull();
// assertEquals("keystore1", sslKeyStore.getId());
// assertEquals("test.keystore", sslKeyStore.getFilePath());
// assertEquals("123456", sslKeyStore.getKeystorePass());
// assertEquals("123456", sslKeyStore.getCertPass());
// assertEquals(1, sslKeyStore.getProtocols().length);
// assertEquals("SSLv3", sslKeyStore.getProtocols()[0]);
assertThat(sslKeyStore.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(MySSLSocketFactoryBuilder.class);
assertThat(sslKeyStore.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
ForestRequest<String> request = giteeClient.index2();
assertThat(request).isNotNull();
request.getLogConfiguration().getLogHandler().setLogger(logger);
String result = (String) request.execute();
assertThat(result.startsWith("Global: ")).isTrue();
Mockito.verify(logger).info("[Forest] [Test2] 请求: \n" + "\tGET https://gitee.com/dt_flys HTTPS");
Throwable th = null;
try {
giteeClient.index3();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNotNull();
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ForestBeanRegister method registerSSLKeyStoreBean.
public BeanDefinition registerSSLKeyStoreBean(ManagedMap<String, BeanDefinition> map, ForestSSLKeyStoreProperties sslKeyStoreProperties) {
String id = sslKeyStoreProperties.getId();
if (StringUtils.isBlank(id)) {
throw new ForestRuntimeException("[Forest] Property 'id' of SSL keystore can not be empty or blank");
}
if (map.containsKey(id)) {
throw new ForestRuntimeException("[Forest] Duplicate SSL keystore id '" + id + "'");
}
BeanDefinition beanDefinition = ForestConfigurationBeanDefinitionParser.createSSLKeyStoreBean(id, sslKeyStoreProperties.getType(), sslKeyStoreProperties.getFile(), sslKeyStoreProperties.getKeystorePass(), sslKeyStoreProperties.getCertPass(), sslKeyStoreProperties.getProtocols(), sslKeyStoreProperties.getCipherSuites(), sslKeyStoreProperties.getHostnameVerifier(), sslKeyStoreProperties.getSslSocketFactoryBuilder());
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
map.put(id, beanDefinition);
return beanDefinition;
}
use of com.dtflys.forest.exceptions.ForestRuntimeException in project forest by dromara.
the class ErrorTest method testErrorCallback.
public void testErrorCallback() {
configuration.setTimeout(10);
final AtomicInteger count = new AtomicInteger(0);
final boolean[] ts = new boolean[] { false };
errorClient.testError(new OnError() {
@Override
public void onError(ForestRuntimeException ex, ForestRequest request, ForestResponse response) {
int status = response.getStatusCode();
count.incrementAndGet();
assertNotNull(ex);
assertNotNull(request);
}
});
assertEquals(1, count.get());
}
Aggregations