Search in sources :

Example 1 with Slf4jLogger

use of feign.slf4j.Slf4jLogger in project carbon-apimgt by wso2.

the class AMDefaultKeyManagerImpl method loadConfiguration.

@Override
public void loadConfiguration(KeyManagerConfiguration configuration) throws APIManagementException {
    this.configuration = configuration;
    String username = (String) configuration.getParameter(APIConstants.KEY_MANAGER_USERNAME);
    String password = (String) configuration.getParameter(APIConstants.KEY_MANAGER_PASSWORD);
    String keyManagerServiceUrl = (String) configuration.getParameter(APIConstants.AUTHSERVER_URL);
    String dcrEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT) != null) {
        dcrEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT);
    } else {
        dcrEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KeyManager.KEY_MANAGER_OPERATIONS_DCR_ENDPOINT);
    }
    String tokenEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.TOKEN_ENDPOINT) != null) {
        tokenEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.TOKEN_ENDPOINT);
    } else {
        tokenEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat("/oauth2/token");
    }
    addKeyManagerConfigsAsSystemProperties(tokenEndpoint);
    String revokeEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.REVOKE_ENDPOINT) != null) {
        revokeEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.REVOKE_ENDPOINT);
    } else {
        revokeEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat("/oauth2/revoke");
    }
    String scopeEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT) != null) {
        scopeEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT);
    } else {
        scopeEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KEY_MANAGER_OAUTH2_SCOPES_REST_API_BASE_PATH);
    }
    String introspectionEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.INTROSPECTION_ENDPOINT) != null) {
        introspectionEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.INTROSPECTION_ENDPOINT);
    } else {
        introspectionEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat("/oauth2/introspect");
    }
    String userInfoEndpoint;
    if (configuration.getParameter(APIConstants.KeyManager.USERINFO_ENDPOINT) != null) {
        userInfoEndpoint = (String) configuration.getParameter(APIConstants.KeyManager.USERINFO_ENDPOINT);
    } else {
        userInfoEndpoint = keyManagerServiceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0].concat(getTenantAwareContext().trim()).concat(APIConstants.KeyManager.KEY_MANAGER_OPERATIONS_USERINFO_ENDPOINT);
    }
    dcrClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(dcrEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(DCRClient.class, dcrEndpoint);
    authClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(tokenEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).errorDecoder(new KMClientErrorDecoder()).encoder(new FormEncoder()).target(AuthClient.class, tokenEndpoint);
    introspectionClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(introspectionEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).encoder(new FormEncoder()).target(IntrospectionClient.class, introspectionEndpoint);
    scopeClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(scopeEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(ScopeClient.class, scopeEndpoint);
    userClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(userInfoEndpoint))).encoder(new GsonEncoder()).decoder(new GsonDecoder()).logger(new Slf4jLogger()).requestInterceptor(new BasicAuthRequestInterceptor(username, password)).requestInterceptor(new TenantHeaderInterceptor(tenantDomain)).errorDecoder(new KMClientErrorDecoder()).target(UserClient.class, userInfoEndpoint);
}
Also used : UserClient(org.wso2.carbon.apimgt.impl.kmclient.model.UserClient) BasicAuthRequestInterceptor(feign.auth.BasicAuthRequestInterceptor) Slf4jLogger(feign.slf4j.Slf4jLogger) AuthClient(org.wso2.carbon.apimgt.impl.kmclient.model.AuthClient) TenantHeaderInterceptor(org.wso2.carbon.apimgt.impl.kmclient.model.TenantHeaderInterceptor) DCRClient(org.wso2.carbon.apimgt.impl.kmclient.model.DCRClient) KMClientErrorDecoder(org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder) GsonEncoder(feign.gson.GsonEncoder) ScopeClient(org.wso2.carbon.apimgt.impl.kmclient.model.ScopeClient) IntrospectionClient(org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectionClient) GsonDecoder(feign.gson.GsonDecoder) ApacheFeignHttpClient(org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient) FormEncoder(org.wso2.carbon.apimgt.impl.kmclient.FormEncoder)

Example 2 with Slf4jLogger

use of feign.slf4j.Slf4jLogger in project nutzboot by nutzam.

the class FeignStarter method afterBorn.

@SuppressWarnings({ "unchecked", "rawtypes" })
public Object afterBorn(Object obj, String beanName) {
    try {
        Mirror mirror = Mirror.me(obj);
        for (Field field : obj.getClass().getDeclaredFields()) {
            FeignInject fc = field.getAnnotation(FeignInject.class);
            if (fc == null)
                continue;
            String url = Strings.sBlank(conf.get(PROP_URL), "http://127.0.0.1:8080");
            Encoder encoder = getEncoder(fc, field);
            Decoder decoder = getDecoder(fc, field);
            Client client = getClient(fc, field, url);
            Logger.Level level = Level.valueOf(conf.get(PROP_LOGLEVEL, "BASIC").toUpperCase());
            Class apiType = field.getType();
            Logger logger = new Slf4jLogger(apiType);
            boolean useHystrix = "true".equals(Strings.sBlank(fc.useHystrix(), conf.get(PROP_HYSTRIX_ENABLE)));
            Feign.Builder builder = useHystrix ? HystrixFeign.builder() : Feign.builder();
            if (encoder != null)
                builder.encoder(encoder);
            if (decoder != null)
                builder.decoder(decoder);
            if (client != null)
                builder.client(client);
            builder.logger(logger);
            builder.logLevel(level);
            Object t = null;
            if (useHystrix) {
                t = ((HystrixFeign.Builder) builder).target(apiType, url, getIocBean(apiType, fc.fallback()));
            } else {
                t = builder.target(apiType, url);
            }
            mirror.setValue(obj, field.getName(), t);
        }
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    return obj;
}
Also used : Slf4jLogger(feign.slf4j.Slf4jLogger) Decoder(feign.codec.Decoder) JacksonDecoder(feign.jackson.JacksonDecoder) JAXBDecoder(feign.jaxb.JAXBDecoder) GsonDecoder(feign.gson.GsonDecoder) Logger(feign.Logger) Slf4jLogger(feign.slf4j.Slf4jLogger) FeignInject(org.nutz.boot.starter.feign.annotation.FeignInject) Level(feign.Logger.Level) HystrixFeign(feign.hystrix.HystrixFeign) Field(java.lang.reflect.Field) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) Encoder(feign.codec.Encoder) JacksonEncoder(feign.jackson.JacksonEncoder) HystrixFeign(feign.hystrix.HystrixFeign) Feign(feign.Feign) Client(feign.Client) OkHttpClient(feign.okhttp.OkHttpClient) RibbonClient(feign.ribbon.RibbonClient) EurekaClient(com.netflix.discovery.EurekaClient) ApacheHttpClient(feign.httpclient.ApacheHttpClient) LBClient(feign.ribbon.LBClient) Mirror(org.nutz.lang.Mirror)

Example 3 with Slf4jLogger

use of feign.slf4j.Slf4jLogger in project Java-Tutorial by gpcodervn.

the class FeignClientCreator method getService.

public static <T> T getService(Class<T> clazz) {
    okhttp3.OkHttpClient okHttpClient = new okhttp3.OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).addInterceptor(new AuthInterceptor()).addNetworkInterceptor(new LoggingInterceptor()).build();
    OkHttpClient feignOkHttp = new OkHttpClient(okHttpClient);
    return Feign.builder().client(feignOkHttp).encoder(new FormEncoder(new GsonEncoder())).decoder(new GsonDecoder()).logger(new Slf4jLogger(clazz)).errorDecoder(new MyErrorDecoder()).logLevel(Logger.Level.FULL).target(clazz, BASE_URL);
}
Also used : LoggingInterceptor(com.gpcoder.interceptor.LoggingInterceptor) OkHttpClient(feign.okhttp.OkHttpClient) GsonEncoder(feign.gson.GsonEncoder) MyErrorDecoder(com.gpcoder.handler.MyErrorDecoder) Slf4jLogger(feign.slf4j.Slf4jLogger) AuthInterceptor(com.gpcoder.interceptor.AuthInterceptor) GsonDecoder(feign.gson.GsonDecoder) FormEncoder(feign.form.FormEncoder)

Aggregations

GsonDecoder (feign.gson.GsonDecoder)3 GsonEncoder (feign.gson.GsonEncoder)3 Slf4jLogger (feign.slf4j.Slf4jLogger)3 OkHttpClient (feign.okhttp.OkHttpClient)2 MyErrorDecoder (com.gpcoder.handler.MyErrorDecoder)1 AuthInterceptor (com.gpcoder.interceptor.AuthInterceptor)1 LoggingInterceptor (com.gpcoder.interceptor.LoggingInterceptor)1 EurekaClient (com.netflix.discovery.EurekaClient)1 Client (feign.Client)1 Feign (feign.Feign)1 Logger (feign.Logger)1 Level (feign.Logger.Level)1 BasicAuthRequestInterceptor (feign.auth.BasicAuthRequestInterceptor)1 Decoder (feign.codec.Decoder)1 Encoder (feign.codec.Encoder)1 FormEncoder (feign.form.FormEncoder)1 ApacheHttpClient (feign.httpclient.ApacheHttpClient)1 HystrixFeign (feign.hystrix.HystrixFeign)1 JacksonDecoder (feign.jackson.JacksonDecoder)1 JacksonEncoder (feign.jackson.JacksonEncoder)1