Search in sources :

Example 1 with GsonEncoder

use of feign.gson.GsonEncoder in project nutzboot by nutzam.

the class FeignStarter method getEncoder.

protected Encoder getEncoder(FeignInject fc, Field field) {
    String encoderStr = Strings.sBlank(fc.encoder(), conf.get(PROP_ENCODER, ""));
    switch(encoderStr) {
        case "":
        case "raw":
            break;
        case "nutzjson":
            JsonFormat jf = JsonFormat.full();
            String jfStr = Strings.sBlank(fc.jsonFormat(), conf.get(PROP_JSON_FORMAT, ""));
            if (!Strings.isBlank(jfStr)) {
                if (jfStr.startsWith("{")) {
                    jf = Json.fromJson(JsonFormat.class, jfStr);
                } else if (jfStr.startsWith("ioc:")) {
                    jf = ioc.get(JsonFormat.class, jfStr.substring(4));
                } else {
                    try {
                        jf = (JsonFormat) JsonFormat.class.getMethod(jfStr).invoke(null);
                    } catch (Exception e) {
                        log.infof("invaild JsonFormat=[%s] at %s", jfStr, field);
                    }
                }
            }
            return new NutzJsonEncoder(jf);
        case "jackson":
            return new JacksonEncoder();
        case "gson":
            return new GsonEncoder();
        case "jaxb":
            JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder().withMarshallerJAXBEncoding("UTF-8").withMarshallerSchemaLocation(getSchemaString(fc.schema())).build();
            return new JAXBEncoder(jaxbFactory);
        default:
            if (encoderStr.startsWith("ioc"))
                return ioc.get(Encoder.class, encoderStr.substring(4));
            break;
    }
    return null;
}
Also used : JAXBContextFactory(feign.jaxb.JAXBContextFactory) JsonFormat(org.nutz.json.JsonFormat) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) Encoder(feign.codec.Encoder) JacksonEncoder(feign.jackson.JacksonEncoder) GsonEncoder(feign.gson.GsonEncoder) JAXBEncoder(feign.jaxb.JAXBEncoder) JacksonEncoder(feign.jackson.JacksonEncoder)

Example 2 with GsonEncoder

use of feign.gson.GsonEncoder in project mesosFramework by zhizuqiu.

the class EtcdClient method getEnableUrl.

public static String getEnableUrl(List<String> urls) {
    String url;
    Etcd etcd;
    GsonDecoder decoder = new GsonDecoder(GSON);
    GsonEncoder encoder = new GsonEncoder(GSON);
    if (urls == null) {
        return null;
    }
    for (String url1 : urls) {
        url = url1;
        etcd = Feign.builder().encoder(encoder).decoder(decoder).errorDecoder(new EtcdErrorDecoder()).requestInterceptor(new EtcdHeadersInterceptor()).target(Etcd.class, url);
        try {
            etcd.getEtcdVersion();
            return url;
        } catch (Exception e) {
            logger.info("connect url[" + url1 + "] error! message:" + e.getMessage());
        }
    }
    return null;
}
Also used : GsonEncoder(feign.gson.GsonEncoder) GsonDecoder(feign.gson.GsonDecoder) IOException(java.io.IOException) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ServerException(com.chinaunicom.etcd.v2.exception.ServerException)

Example 3 with GsonEncoder

use of feign.gson.GsonEncoder in project mesosFramework by zhizuqiu.

the class EtcdClient method getInstance.

public static Etcd getInstance(List<String> urls) {
    if (urls == null) {
        return null;
    }
    Etcd etcd;
    GsonDecoder decoder = new GsonDecoder(GSON);
    GsonEncoder encoder = new GsonEncoder(GSON);
    for (String url : urls) {
        etcd = Feign.builder().encoder(encoder).decoder(decoder).errorDecoder(new EtcdErrorDecoder()).requestInterceptor(new EtcdHeadersInterceptor()).target(Etcd.class, url);
        try {
            etcd.getEtcdVersion();
            return etcd;
        } catch (Exception e) {
            logger.info("connect url[" + url + "] error! message:" + e.getMessage());
        }
    }
    logger.error("get etcd instance error!");
    return null;
}
Also used : GsonEncoder(feign.gson.GsonEncoder) GsonDecoder(feign.gson.GsonDecoder) IOException(java.io.IOException) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ServerException(com.chinaunicom.etcd.v2.exception.ServerException)

Example 4 with GsonEncoder

use of feign.gson.GsonEncoder in project carbon-apimgt by wso2.

the class KeyManagersApiServiceImpl method keyManagersDiscoverPost.

@Override
public Response keyManagersDiscoverPost(String url, String type, MessageContext messageContext) throws APIManagementException {
    if (StringUtils.isNotEmpty(url)) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        OpenIDConnectDiscoveryClient openIDConnectDiscoveryClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(url))).encoder(new GsonEncoder(gson)).decoder(new GsonDecoder(gson)).errorDecoder(new KMClientErrorDecoder()).target(OpenIDConnectDiscoveryClient.class, url);
        OpenIdConnectConfiguration openIdConnectConfiguration = openIDConnectDiscoveryClient.getOpenIdConnectConfiguration();
        if (openIdConnectConfiguration != null) {
            KeyManagerWellKnownResponseDTO keyManagerWellKnownResponseDTO = KeyManagerMappingUtil.fromOpenIdConnectConfigurationToKeyManagerConfiguration(openIdConnectConfiguration);
            keyManagerWellKnownResponseDTO.getValue().setWellKnownEndpoint(url);
            keyManagerWellKnownResponseDTO.getValue().setType(type);
            return Response.ok().entity(keyManagerWellKnownResponseDTO).build();
        }
    }
    return Response.ok(new KeyManagerWellKnownResponseDTO()).build();
}
Also used : KMClientErrorDecoder(org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder) GsonEncoder(feign.gson.GsonEncoder) OpenIdConnectConfiguration(org.wso2.carbon.apimgt.impl.kmclient.model.OpenIdConnectConfiguration) OpenIDConnectDiscoveryClient(org.wso2.carbon.apimgt.impl.kmclient.model.OpenIDConnectDiscoveryClient) GsonBuilder(com.google.gson.GsonBuilder) KeyManagerWellKnownResponseDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO) GsonDecoder(feign.gson.GsonDecoder) Gson(com.google.gson.Gson) ApacheFeignHttpClient(org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient)

Example 5 with GsonEncoder

use of feign.gson.GsonEncoder 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)

Aggregations

GsonEncoder (feign.gson.GsonEncoder)10 GsonDecoder (feign.gson.GsonDecoder)8 ClientException (com.chinaunicom.etcd.v2.exception.ClientException)2 ServerException (com.chinaunicom.etcd.v2.exception.ServerException)2 Feign (feign.Feign)2 IOException (java.io.IOException)2 ApacheFeignHttpClient (org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient)2 KMClientErrorDecoder (org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Response (feign.Response)1 Retryer (feign.Retryer)1 BasicAuthRequestInterceptor (feign.auth.BasicAuthRequestInterceptor)1 Encoder (feign.codec.Encoder)1 JacksonEncoder (feign.jackson.JacksonEncoder)1 JAXBContextFactory (feign.jaxb.JAXBContextFactory)1 JAXBEncoder (feign.jaxb.JAXBEncoder)1 Slf4jLogger (feign.slf4j.Slf4jLogger)1 JsonFormat (org.nutz.json.JsonFormat)1 FormEncoder (org.wso2.carbon.apimgt.impl.kmclient.FormEncoder)1