Search in sources :

Example 61 with ForestRuntimeException

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;
}
Also used : ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) ForestMethod(com.dtflys.forest.reflection.ForestMethod) Method(java.lang.reflect.Method)

Example 62 with ForestRuntimeException

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();
}
Also used : ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) SSLKeyStore(com.dtflys.forest.ssl.SSLKeyStore) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with ForestRuntimeException

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;
}
Also used : ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 64 with ForestRuntimeException

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());
}
Also used : ForestResponse(com.dtflys.forest.http.ForestResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) OnError(com.dtflys.forest.callback.OnError) ForestRequest(com.dtflys.forest.http.ForestRequest)

Aggregations

ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)64 Test (org.junit.Test)14 Map (java.util.Map)9 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)7 MetaRequest (com.dtflys.forest.reflection.MetaRequest)6 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)5 MappingParameter (com.dtflys.forest.mapping.MappingParameter)5 Method (java.lang.reflect.Method)5 Parameter (java.lang.reflect.Parameter)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 SSLKeyStore (com.dtflys.forest.ssl.SSLKeyStore)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MalformedURLException (java.net.MalformedURLException)4 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)4 ForestConverter (com.dtflys.forest.converter.ForestConverter)3 ForestRequest (com.dtflys.forest.http.ForestRequest)3 Interceptor (com.dtflys.forest.interceptor.Interceptor)3