Search in sources :

Example 21 with GsonDecoder

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

the class DefaultScopeRegistrationImpl method getScope.

private Scope getScope(Response response) throws IOException {
    Scope scope = new Scope();
    ScopeInfo scopeInfoResponse = (ScopeInfo) new GsonDecoder().decode(response, ScopeInfo.class);
    scope.setName(scopeInfoResponse.getName());
    scope.setDescription(scopeInfoResponse.getDescription());
    if (scopeInfoResponse.getBindings() != null) {
        scope.setBindings(scopeInfoResponse.getBindings());
    } else {
        scope.setBindings(Collections.emptyList());
    }
    return scope;
}
Also used : Scope(org.wso2.carbon.apimgt.core.models.Scope) GsonDecoder(feign.gson.GsonDecoder) ScopeInfo(org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)

Example 22 with GsonDecoder

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

the class MesosClient method getInstance.

public static MesosIf getInstance(String url) {
    GsonDecoder decoder = new GsonDecoder(GSON);
    GsonEncoder encoder = new GsonEncoder(GSON);
    return Feign.builder().encoder(encoder).decoder(decoder).errorDecoder(new MesosErrorDecoder()).requestInterceptor(new MesosHeadersInterceptor()).target(MesosIf.class, url);
}
Also used : GsonEncoder(feign.gson.GsonEncoder) GsonDecoder(feign.gson.GsonDecoder)

Example 23 with GsonDecoder

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

the class EtcdClient method getInstance.

public static Etcd getInstance(String url) {
    GsonDecoder decoder = new GsonDecoder(GSON);
    GsonEncoder encoder = new GsonEncoder(GSON);
    return Feign.builder().encoder(encoder).decoder(decoder).errorDecoder(new EtcdErrorDecoder()).requestInterceptor(new EtcdHeadersInterceptor()).target(Etcd.class, url);
}
Also used : GsonEncoder(feign.gson.GsonEncoder) GsonDecoder(feign.gson.GsonDecoder)

Example 24 with GsonDecoder

use of feign.gson.GsonDecoder in project feign by OpenFeign.

the class MockClientSequentialTest method setup.

@Before
public void setup() throws IOException {
    try (InputStream input = getClass().getResourceAsStream("/fixtures/contributors.json")) {
        byte[] data = toByteArray(input);
        RequestHeaders headers = RequestHeaders.builder().add("Name", "netflix").build();
        mockClientSequential = new MockClient(true);
        githubSequential = Feign.builder().decoder(new AssertionDecoder(new GsonDecoder())).client(mockClientSequential.add(RequestKey.builder(HttpMethod.GET, "/repos/netflix/feign/contributors").headers(headers).build(), HttpsURLConnection.HTTP_OK, data).add(HttpMethod.GET, "/repos/netflix/feign/contributors?client_id=55", HttpsURLConnection.HTTP_NOT_FOUND).add(HttpMethod.GET, "/repos/netflix/feign/contributors?client_id=7 7", HttpsURLConnection.HTTP_INTERNAL_ERROR, new ByteArrayInputStream(data)).add(HttpMethod.GET, "/repos/netflix/feign/contributors", Response.builder().status(HttpsURLConnection.HTTP_OK).headers(RequestHeaders.EMPTY).body(data))).target(new MockTarget<>(GitHub.class));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GsonDecoder(feign.gson.GsonDecoder) Before(org.junit.Before)

Example 25 with GsonDecoder

use of feign.gson.GsonDecoder 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)25 IOException (java.io.IOException)11 Response (feign.Response)9 GsonEncoder (feign.gson.GsonEncoder)9 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)5 DCRClientInfo (org.wso2.carbon.apimgt.core.auth.dto.DCRClientInfo)4 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)4 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)3 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)3 ClientException (com.chinaunicom.etcd.v2.exception.ClientException)2 ServerException (com.chinaunicom.etcd.v2.exception.ServerException)2 Feign (feign.Feign)2 Slf4jLogger (feign.slf4j.Slf4jLogger)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2