Search in sources :

Example 1 with SpringAnnotationWrapper

use of com.github.df.restypass.spring.wrapper.SpringAnnotationWrapper in project RestyPass by darren-fu.

the class RestyCommandContext method initContextForService.

/**
 * 为service创建Resty配置
 *
 * @param serviceClz the service clz
 */
public void initContextForService(Class serviceClz) {
    RestyService restyService = (RestyService) serviceClz.getDeclaredAnnotation(RestyService.class);
    if (restyService == null) {
        return;
    }
    String serviceName = restyService.serviceName();
    // class->@RestyService
    this.storeRestyService(serviceClz, restyService);
    AsyncHttpClientConfig httpClientConfig = AsyncHttpConfigFactory.createConfig(restyService.connectTimeout(), restyService.requestTimeout());
    HttpClientWrapper clientHolder = new HttpClientWrapper(httpClientConfig);
    httpClientPool.putIfAbsent(serviceName, clientHolder);
    SpringAnnotationWrapper wrapper = new SpringAnnotationWrapper();
    RestyCommandConfig commandProperties = new RestyCommandConfig.DefaultRestyCommandConfig();
    processRestyServiceAnnotation(restyService, commandProperties);
    for (Method method : serviceClz.getMethods()) {
        // 存储 httpMethod 和 restyCommandConfig
        RestyMethod restyMethod = method.getDeclaredAnnotation(RestyMethod.class);
        if (restyMethod != null) {
            storeRestyMethod(method, restyMethod);
            processRestyMethodAnnotation(restyMethod, commandProperties);
        }
        commandPropertiesMap.putIfAbsent(method, commandProperties);
        // 存储 httpMethod 和 requestTemplate
        RestyRequestTemplate restyRequestTemplate = wrapper.processAnnotation(serviceClz, method);
        requestTemplateMap.putIfAbsent(method, restyRequestTemplate);
        serviceMethodTable.put(serviceName, restyRequestTemplate.getPath(), method);
    }
    log.info("RestyCommandContext初始化成功!");
}
Also used : HttpClientWrapper(com.github.df.restypass.http.client.HttpClientWrapper) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) RestyMethod(com.github.df.restypass.annotation.RestyMethod) Method(java.lang.reflect.Method) RestyMethod(com.github.df.restypass.annotation.RestyMethod) RestyService(com.github.df.restypass.annotation.RestyService) SpringAnnotationWrapper(com.github.df.restypass.spring.wrapper.SpringAnnotationWrapper)

Aggregations

RestyMethod (com.github.df.restypass.annotation.RestyMethod)1 RestyService (com.github.df.restypass.annotation.RestyService)1 HttpClientWrapper (com.github.df.restypass.http.client.HttpClientWrapper)1 SpringAnnotationWrapper (com.github.df.restypass.spring.wrapper.SpringAnnotationWrapper)1 Method (java.lang.reflect.Method)1 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)1