use of feign.gson.GsonDecoder in project feign by OpenFeign.
the class WikipediaExample method main.
public static void main(String... args) throws InterruptedException {
Gson gson = new GsonBuilder().registerTypeAdapter(new TypeToken<Response<Page>>() {
}.getType(), pagesAdapter).create();
Wikipedia wikipedia = Feign.builder().decoder(new GsonDecoder(gson)).logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC).options(new Request.Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, true)).target(Wikipedia.class, "https://en.wikipedia.org");
System.out.println("Let's search for PTAL!");
Iterator<Page> pages = lazySearch(wikipedia, "PTAL");
while (pages.hasNext()) {
System.out.println(pages.next().title);
}
}
use of feign.gson.GsonDecoder 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();
}
use of feign.gson.GsonDecoder 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);
}
use of feign.gson.GsonDecoder in project pravega by pravega.
the class MetronomeClient method getInstance.
/*
* The generalized version of the method that allows more in-depth customizations via
* {@link RequestInterceptor}s.
*
* @param endpoint URL of Metronome
*/
public static Metronome getInstance(String endpoint, RequestInterceptor... interceptors) {
Feign.Builder b = Feign.builder().client(LoginClient.getClientHostVerificationDisabled()).logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC).encoder(new GsonEncoder(ModelUtils.GSON)).decoder(new GsonDecoder(ModelUtils.GSON)).retryer(new Retryer.Default(SECONDS.toMillis(1), SECONDS.toMillis(5), 5)).errorDecoder(new MetronomeErrorDecoder());
if (interceptors != null) {
b.requestInterceptors(asList(interceptors));
}
b.requestInterceptor(new MetronomeHeadersInterceptor());
return b.target(Metronome.class, endpoint);
}
use of feign.gson.GsonDecoder in project pravega by pravega.
the class AuthEnabledMarathonClient method getInstance.
private static Marathon getInstance(String endpoint, RequestInterceptor... interceptors) {
Feign.Builder b = Feign.builder().client(LoginClient.getClientHostVerificationDisabled()).logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC).encoder(new GsonEncoder(ModelUtils.GSON)).decoder(new GsonDecoder(ModelUtils.GSON)).errorDecoder(new MarathonErrorDecoder()).retryer(new Retryer.Default(SECONDS.toMillis(1), SECONDS.toMillis(5), 5));
if (interceptors != null) {
b.requestInterceptors(asList(interceptors));
}
b.requestInterceptor(new MarathonHeadersInterceptor());
return b.target(Marathon.class, endpoint);
}
Aggregations