feign.slf4j.Slf4jLogger Java Examples

The following examples show how to use feign.slf4j.Slf4jLogger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarathonClient.java    From marathon-client with Apache License 2.0 7 votes vote down vote up
/**
 * The generalized version of the method that allows more in-depth customizations via
 * {@link RequestInterceptor}s.
 *
 * @param endpoint
 * 		URL of Marathon
 * @param interceptors optional request interceptors
 * @return Marathon client
 */
public static Marathon getInstance(String endpoint, RequestInterceptor... interceptors) {

	Builder b = Feign.builder()
			.encoder(new GsonEncoder(ModelUtils.GSON))
			.decoder(new GsonDecoder(ModelUtils.GSON))
			.errorDecoder(new MarathonErrorDecoder());
	if (interceptors != null)
		b.requestInterceptors(asList(interceptors));
	String debugOutput = System.getenv(DEBUG_JSON_OUTPUT);
	if ("System.out".equals(debugOutput)) {
		System.setProperty("org.slf4j.simpleLogger.logFile", "System.out");
		System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
		b.logger(new Slf4jLogger()).logLevel(Logger.Level.FULL);
	} else if (debugOutput != null) {
		b.logger(new Logger.JavaLogger().appendToFile(debugOutput)).logLevel(Logger.Level.FULL);
	}
	b.requestInterceptor(new MarathonHeadersInterceptor());
	return b.target(Marathon.class, endpoint);
}
 
Example #2
Source File: StoreClient.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public StoreClient(RequestInterceptor requestInterceptor) {

        Feign.Builder builder = Feign.builder().client(new OkHttpClient(
                org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient())).logger(new
                Slf4jLogger())
                .logLevel(Logger.Level.FULL)
                .requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
        String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getStoreEndpoint());

        apis = builder.target(APICollectionApi.class, basePath);
        individualApi = builder.target(APIIndividualApi.class, basePath);
        applications = builder.target(ApplicationCollectionApi.class, basePath);
        individualApplication = builder.target(ApplicationIndividualApi.class, basePath);
        subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
        individualSubscription = builder.target(SubscriptionIndividualApi.class, basePath);
        subscriptionMultitpleApi = builder.target(SubscriptionMultitpleApi.class, basePath);
        tags = builder.target(TagCollectionApi.class, basePath);
        individualTier = builder.target(ThrottlingTierIndividualApi.class, basePath);
        tiers = builder.retryer(new Retryer.Default(100L, TimeUnit.SECONDS.toMillis(1L), 1))
                .options(new Request.Options(10000, 5000))
                .target(ThrottlingTierCollectionApi.class, basePath);

    }
 
Example #3
Source File: PublisherClient.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * PublisherClient constructor - Initialize a PublisherClient instance
 *
 */
public PublisherClient(RequestInterceptor requestInterceptor) {
    Feign.Builder builder = Feign.builder().client(new OkHttpClient(
            org.wso2.carbon.apimgt.integration.client.util.Utils.getSSLClient())).logger(new
            Slf4jLogger())
            .logLevel(Logger.Level.FULL)
            .requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
    String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getPublisherEndpoint());

    api = builder.target(APIIndividualApi.class, basePath);
    apis = builder.target(APICollectionApi.class, basePath);
    document = builder.target(DocumentIndividualApi.class, basePath);
    application = builder.target(ApplicationIndividualApi.class, basePath);
    environments = builder.target(EnvironmentCollectionApi.class, basePath);
    subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
    tiers = builder.target(ThrottlingTierCollectionApi.class, basePath);
}
 
Example #4
Source File: VertxHttpOptionsTest.java    From feign-vertx with Apache License 2.0 6 votes vote down vote up
/**
 * Test the Feign Request Options version of the Vert.x Feign Client.
 * This proves regression is not broken for existing use-cases.
 * @param context Test Context
 */
@Test
public void testRequestOptions(TestContext context) {
  IcecreamServiceApi client = VertxFeign
          .builder()
          .vertx(vertx)
          .options(new Request.Options(5000,5000) ) // Plain old Feign Request.Options (regression)
          .decoder(new JacksonDecoder(TestUtils.MAPPER))
          .logger(new Slf4jLogger())
          .logLevel(Logger.Level.FULL)
          .target(IcecreamServiceApi.class, "http://localhost:8089");

  stubFor(get(urlEqualTo("/icecream/flavors"))
          .withHeader("Accept", equalTo("application/json"))
          .withHeader("Accept-Encoding", absent()) // Test that Accept-Encoding is missing (since we're using Request.Options)
          .willReturn(aResponse()
                  .withStatus(200)
                  .withHeader("Content-Type", "application/json")
                  .withBody(flavorsStr)));

  testClient(client, context);
}
 
Example #5
Source File: BackendServiceFactory.java    From jrestless-examples with Apache License 2.0 6 votes vote down vote up
@Inject
public BackendServiceFactory(InjectionManager serviceLocator) {
	awsLambdaClient = new AWSLambdaClient();
	awsLambdaClient.configureRegion(BACKEND_SERVICE_REGION);
	backendService = Feign.builder()
			.client(FeignLambdaServiceInvokerClient.builder()
					.setRegion(BACKEND_SERVICE_REGION)
					.setFunctionName(BACKEND_SERVICE_FUNCTION_NAME)
					.build())
			.decoder(new JacksonDecoder())
			.encoder(new JacksonEncoder())
			.logger(new Slf4jLogger())
			.target(new LambdaServiceFunctionTarget<BackendService>(BackendService.class) {
				@Override
				public Request apply(RequestTemplate input) {
					// TODO inject the context directly => requires the context to be bound as proxy
					Context lambdaContext = serviceLocator.getInstance(Context.class);
					// propagate the AWS request ID => the called service can log the original AWS request ID
					input.header("X-Base-Aws-Request-Id", lambdaContext.getAwsRequestId());
					return super.apply(input);
				}
			});
}
 
Example #6
Source File: SimulatedDeviceFactory.java    From hawkbit-examples with Eclipse Public License 1.0 6 votes vote down vote up
private AbstractSimulatedDevice createDdiDevice(final String id, final String tenant, final int pollDelaySec,
        final URL baseEndpoint, final String gatewayToken) {

    final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jackson2HalModule());

    final RootControllerResourceClient controllerResource = Feign.builder()
            .requestInterceptor(new GatewayTokenInterceptor(gatewayToken))
            .contract(new IgnoreMultipleConsumersProducersSpringMvcContract()).logLevel(Level.HEADERS)
            .decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper))).encoder(new JacksonEncoder())
            .logger(new Slf4jLogger()).decode404()
            .target(RootControllerResourceClient.class, baseEndpoint.toString());

    return new DDISimulatedDevice(id, tenant, pollDelaySec, controllerResource, deviceUpdater, gatewayToken);
}
 
Example #7
Source File: BookControllerFeignClientBuilder.java    From tutorials with MIT License 5 votes vote down vote up
private static <T> T createClient(Class<T> type, String uri) {
    return Feign.builder()
        .client(new OkHttpClient())
        .encoder(new GsonEncoder())
        .decoder(new GsonDecoder())
        .logger(new Slf4jLogger(type))
        .logLevel(Logger.Level.FULL)
        .target(type, uri);
}
 
Example #8
Source File: GameClientResolver.java    From codenjoy with GNU General Public License v3.0 5 votes vote down vote up
private GameServerClient buildGameServerClient(String server) {
    return Feign.builder()
            .client(new OkHttpClient())
            .encoder(new JacksonEncoder())
            .decoder(new JacksonDecoder())
            .errorDecoder(new ClientErrorDecoder())
            .logger(new Slf4jLogger(GameServerClient.class))
            .logLevel(Level.BASIC)
            .requestInterceptor(new BasicAuthRequestInterceptor(gameProperties.getBasicAuthUser(),
                    Hash.md5(gameProperties.getBasicAuthPassword())))
            .target(GameServerClient.class, gameProperties.getSchema() + "://" + server);
}
 
Example #9
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
 static LinshareAPIForUserTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForUserTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForUserTesting.class, linshare.getUrl());
}
 
Example #10
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPIForTechnicalAccountTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForTechnicalAccountTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForTechnicalAccountTesting.class, linshare.getUrl());
}
 
Example #11
Source File: LinshareExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPIForAdminTesting from(LinshareFixture.Credential credential) {

    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credential.getUsername(), credential.getPassword()))
        .logger(new Slf4jLogger(LinshareAPIForAdminTesting.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(CombinedDecoder.builder()
            .defaultDecoder(new JacksonDecoder())
            .registerSingleTypeDecoder(new ByteArrayDecoder())
            .build())
        .target(LinshareAPIForAdminTesting.class, linshare.getUrl());
}
 
Example #12
Source File: LinshareAPI.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static LinshareAPI from(LinshareConfiguration configuration) {
    return Feign.builder()
        .requestInterceptor(
            new BasicAuthRequestInterceptor(
                configuration.getUuid().toString(),
                configuration.getPassword()))
        .logger(new Slf4jLogger(LinshareAPI.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new FormEncoder(new JacksonEncoder()))
        .decoder(new JacksonDecoder())
        .target(LinshareAPI.class, configuration.getUrl().toString());
}
 
Example #13
Source File: ConfigurationClient.java    From james-project with Apache License 2.0 5 votes vote down vote up
static ConfigurationClient from(Host mockServerHttpHost) {
    return Feign.builder()
        .logger(new Slf4jLogger(ConfigurationClient.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new JacksonEncoder(OBJECT_MAPPER))
        .decoder(new JacksonDecoder(OBJECT_MAPPER))
        .target(ConfigurationClient.class, "http://" + mockServerHttpHost.asString());
}
 
Example #14
Source File: RabbitMQManagementAPI.java    From james-project with Apache License 2.0 5 votes vote down vote up
static RabbitMQManagementAPI from(RabbitMQConfiguration configuration) {
    RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
    return Feign.builder()
        .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new String(credentials.getPassword())))
        .logger(new Slf4jLogger(RabbitMQManagementAPI.class))
        .logLevel(Logger.Level.FULL)
        .encoder(new JacksonEncoder())
        .decoder(new JacksonDecoder())
        .retryer(new Retryer.Default())
        .errorDecoder(RETRY_500)
        .target(RabbitMQManagementAPI.class, configuration.getManagementUri().toString());
}
 
Example #15
Source File: OAuthRequestInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an interceptor that authenticates all requests.
 */
public OAuthRequestInterceptor() {
    String username = APIMConfigReader.getInstance().getConfig().getUsername();
    String password = APIMConfigReader.getInstance().getConfig().getPassword();
    dcrClient = Feign.builder().client(new OkHttpClient(Utils.getSSLClient())).logger(new Slf4jLogger())
            .logLevel(Logger.Level.FULL).requestInterceptor(new BasicAuthRequestInterceptor(username,
                    password))
            .contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
            .target(DCRClient.class, Utils.replaceProperties(
                    APIMConfigReader.getInstance().getConfig().getDcrEndpoint()));
}
 
Example #16
Source File: Application.java    From hawkbit-examples with Eclipse Public License 1.0 5 votes vote down vote up
private static MgmtSoftwareModuleClientResource uploadSoftwareModule(
        final ClientConfigurationProperties configuration) {
    final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .registerModule(new Jackson2HalModule());
    return Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract()).decode404()
            .requestInterceptor(
                    new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword()))
            .logger(new Slf4jLogger()).encoder(new FeignMultipartEncoder())
            .decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)))
            .target(MgmtSoftwareModuleClientResource.class, configuration.getUrl());
}
 
Example #17
Source File: VertxHttpOptionsTest.java    From feign-vertx with Apache License 2.0 5 votes vote down vote up
/**
 * Test the Vert.x HttpClientOptions version of the Vert.x Feign Client.
 * This is useful for use-cases like HTTPS/2 or gzip compressed responses.
 * @param context Test Context
 */
@Test
public void testHttpClientOptions(TestContext context) {
  // NOTE: We cannot use HTTPS/2 because Wiremock 2.1.0-beta uses Jetty 9.2.13.v20150730.
  //       Jetty 9.3 is required for HTTPS/2. So we use HttpClientOptions.TryUseCompression(true)
  //       instead to verify we're using the Vert.x HttpClientOptions object.
  HttpClientOptions options = new HttpClientOptions().
          setTryUseCompression(true). // Attribute under test, not available with Feign Request.Options
          setConnectTimeout(5000).
          setIdleTimeout(5000);

  IcecreamServiceApi client = VertxFeign
          .builder()
          .vertx(vertx)
          .options(options) // New feature! Accepts HttpClientOptions
          .decoder(new JacksonDecoder(TestUtils.MAPPER))
          .logger(new Slf4jLogger())
          .logLevel(Logger.Level.FULL)
          .target(IcecreamServiceApi.class, "http://localhost:8089");

  stubFor(get(urlEqualTo("/icecream/flavors"))
          .withHeader("Accept", equalTo("application/json"))
          .withHeader("Accept-Encoding", equalTo("deflate, gzip")) // Test setTryUseCompression(true) affected the request
          .willReturn(aResponse()
                  .withStatus(200)
                  .withHeader("Content-Type", "application/json")
                  .withBody(flavorsStr)));

  testClient(client, context);
}
 
Example #18
Source File: OneSignal.java    From OneSignal-Java-SDK with Apache License 2.0 5 votes vote down vote up
private static OneSignalComms oneSignal() {
    JacksonDecoder decoder = new JacksonDecoder(OBJECT_MAPPER);
    return Feign.builder()
            .encoder(new JacksonEncoder(OBJECT_MAPPER))
            .decoder(decoder)
            .decode404()
            .errorDecoder(new OneSignalErrorDecoder(decoder))
            .logger(new Slf4jLogger())
            .logLevel(Level.FULL)
            .target(OneSignalComms.class, "https://onesignal.com/api/v1");
}
 
Example #19
Source File: Client.java    From metacat with Apache License 2.0 5 votes vote down vote up
private Client(
    final String host,
    final feign.Client client,
    final feign.Logger.Level logLevel,
    final RequestInterceptor requestInterceptor,
    final Retryer retryer,
    final Request.Options options
) {
    final MetacatJsonLocator metacatJsonLocator = new MetacatJsonLocator();
    final ObjectMapper mapper = metacatJsonLocator
        .getPrettyObjectMapper()
        .copy()
        .registerModule(new GuavaModule())
        .registerModule(new JaxbAnnotationModule());

    log.info("Connecting to {}", host);
    this.host = host;

    feignBuilder = Feign.builder()
        .client(client)
        .logger(new Slf4jLogger())
        .logLevel(logLevel)
        .contract(new JAXRSContract())
        .encoder(new JacksonEncoder(mapper))
        .decoder(new JacksonDecoder(mapper))
        .errorDecoder(new MetacatErrorDecoder(metacatJsonLocator))
        .requestInterceptor(requestInterceptor)
        .retryer(retryer)
        .options(options);

    api = getApiClient(MetacatV1.class);
    partitionApi = getApiClient(PartitionV1.class);
    metadataApi = getApiClient(MetadataV1.class);
    resolverApi = getApiClient(ResolverV1.class);
    tagApi = getApiClient(TagV1.class);
}
 
Example #20
Source File: SpringFeignClientFactory.java    From raptor with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T create(Class<T> type) {
    RaptorMessageConverter raptorMessageConverter = getOrInstantiate(RaptorMessageConverter.class);

    Feign.Builder builder = Feign.builder()
            .encoder(new RaptorMessageEncoder(raptorMessageConverter))
            .decoder(new RaptorMessageDecoder(raptorMessageConverter))
            .errorDecoder(new RaptorErrorDecoder(raptorMessageConverter))
            .contract(new SpringMvcContract())
            .retryer(Retryer.NEVER_RETRY)
            .logger(new Slf4jLogger(type))
            .options(createOptions())
            .requestInterceptor(new HeaderTraceRequestInterceptor());

    //自定义InvocationHandlerFactory,用于自定义拦截器
    builder.invocationHandlerFactory(createInvocationHandlerFactory());

    //设置client
    builder.client(createRaptorFeignClient());

    //自定义配置
    configureUsingProperties(type, builder);

    String url = getUrl(type);
    T t = builder.target(type, url);
    log.info("Create raptor client of type [{}] by url [{}].", type.getName(), url);
    return t;
}
 
Example #21
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public ApiClient() {
  objectMapper = createObjectMapper();
  apiAuthorizations = new LinkedHashMap<String, RequestInterceptor>();
  feignBuilder = Feign.builder()
              .encoder(new FormEncoder(new JacksonEncoder(objectMapper)))
              .decoder(new JacksonDecoder(objectMapper))
              .logger(new Slf4jLogger());
}
 
Example #22
Source File: FeignLoggerFactoryTests.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultLogger() {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			SampleConfiguration1.class);
	FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
	assertThat(loggerFactory).isNotNull();
	Logger logger = loggerFactory.create(Object.class);
	assertThat(logger).isNotNull();
	assertThat(logger instanceof Slf4jLogger).isTrue();
	context.close();
}
 
Example #23
Source File: RetryingTest.java    From feign-vertx with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetrying_noMoreAttempts(TestContext context) {

  /* Given */
  stubFor(get(urlEqualTo("/icecream/flavors"))
      .withHeader("Accept", equalTo("application/json"))
      .willReturn(aResponse()
          .withStatus(503)
          .withHeader("Retry-After", "1")));

  IcecreamServiceApi client = VertxFeign
      .builder()
      .vertx(vertx)
      .decoder(new JacksonDecoder(MAPPER))
      .retryer(new Retryer.Default())
      .logger(new Slf4jLogger())
      .logLevel(Logger.Level.FULL)
      .target(IcecreamServiceApi.class, "http://localhost:8089");

  Async async = context.async();

  /* When */
  client.getAvailableFlavors().setHandler(res -> {

    /* Then */
    if (res.failed())

    /* Then */
      if (res.failed()) {
        try {
          assertThat(res.cause())
              .isInstanceOf(RetryableException.class)
              .hasMessageContaining("status 503");
          async.complete();
        } catch (Throwable exception) {
          context.fail(exception);
        }
      } else {
        context.fail("RetryableException excepted but not occurred");
      }
  });
}
 
Example #24
Source File: VertxHttpClientTest.java    From feign-vertx with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleGet_success(TestContext context) {

  /* Given */
  String flavorsStr = Arrays
      .stream(Flavor.values())
      .map(flavor -> "\"" + flavor + "\"")
      .collect(Collectors.joining(", ", "[ ", " ]"));

  String mixinsStr = Arrays
      .stream(Mixin.values())
      .map(flavor -> "\"" + flavor + "\"")
      .collect(Collectors.joining(", ", "[ ", " ]"));

  stubFor(get(urlEqualTo("/icecream/flavors"))
      .withHeader("Accept", equalTo("application/json"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "application/json")
          .withBody(flavorsStr)));

  stubFor(get(urlEqualTo("/icecream/mixins"))
      .withHeader("Accept", equalTo("application/json"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "application/json")
          .withBody(mixinsStr)));

  IcecreamServiceApi client = VertxFeign
      .builder()
      .vertx(vertx)
      .decoder(new JacksonDecoder(TestUtils.MAPPER))
      .logger(new Slf4jLogger())
      .logLevel(Logger.Level.FULL)
      .target(IcecreamServiceApi.class, "http://localhost:8089");

  Async async = context.async();

  /* When */
  Future<Collection<Flavor>> flavorsFuture = client.getAvailableFlavors();
  Future<Collection<Mixin>> mixinsFuture = client.getAvailableMixins();

  /* Then */
  CompositeFuture.all(flavorsFuture, mixinsFuture).setHandler(res -> {
    if (res.succeeded()) {
      Collection<Flavor> flavors = res.result().resultAt(0);
      Collection<Mixin> mixins = res.result().resultAt(1);

      try {
        assertThat(flavors)
            .hasSize(Flavor.values().length)
            .containsAll(Arrays.asList(Flavor.values()));
        assertThat(mixins)
            .hasSize(Mixin.values().length)
            .containsAll(Arrays.asList(Mixin.values()));
        async.complete();
      } catch (Throwable exception) {
        context.fail(exception);
      }
    } else {
      context.fail(res.cause());
    }
  });
}
 
Example #25
Source File: DockerElasticSearch.java    From james-project with Apache License 2.0 4 votes vote down vote up
public Builder(URL esURL) {
    this.esURL = esURL;
    this.requestBuilder = Feign.builder()
        .logger(new Slf4jLogger(ElasticSearchAPI.class))
        .logLevel(Logger.Level.FULL);
}
 
Example #26
Source File: FeignClientOverrideDefaultsTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@Test
public void overrideLogger() {
	Logger.JavaLogger.class.cast(this.context.getInstance("foo", Logger.class));
	Slf4jLogger.class.cast(this.context.getInstance("bar", Logger.class));
}
 
Example #27
Source File: EnableFeignClientsTests.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@Test
public void loggerDefaultCorrect() {
	Slf4jLogger.class.cast(this.context.getBeansOfType(Logger.class).get(0));
}
 
Example #28
Source File: AMDefaultKeyManagerImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Override
public void loadConfiguration(KeyManagerConfiguration configuration) throws APIManagementException {

    this.configuration = configuration;

    String consumerKey = (String) configuration.getParameter(APIConstants.KEY_MANAGER_CONSUMER_KEY);
    String consumerSecret = (String) configuration.getParameter(APIConstants.KEY_MANAGER_CONSUMER_SECRET);
    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("/api/identity/oauth2/dcr/v1.1/register");
    }
    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");
    }
    accessTokenGenerator = new AccessTokenGenerator(tokenEndpoint, revokeEndpoint, consumerKey, consumerSecret);

    dcrClient = Feign.builder()
            .client(new OkHttpClient())
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger())
            .requestInterceptor(new BearerInterceptor(accessTokenGenerator))
            .errorDecoder(new KMClientErrorDecoder())
            .target(DCRClient.class, dcrEndpoint);
    authClient = Feign.builder()
            .client(new OkHttpClient())
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger())
            .errorDecoder(new KMClientErrorDecoder())
            .encoder(new FormEncoder())
            .target(AuthClient.class, tokenEndpoint);

    introspectionClient = Feign.builder()
            .client(new OkHttpClient())
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger())
            .requestInterceptor(new BearerInterceptor(accessTokenGenerator))
            .errorDecoder(new KMClientErrorDecoder())
            .encoder(new FormEncoder())
            .target(IntrospectionClient.class, introspectionEndpoint);
    scopeClient = Feign.builder()
            .client(new OkHttpClient())
            .encoder(new GsonEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger())
            .requestInterceptor(new BearerInterceptor(accessTokenGenerator))
            .errorDecoder(new KMClientErrorDecoder())
            .target(ScopeClient.class, scopeEndpoint);
}
 
Example #29
Source File: DefaultFeignLoggerFactory.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
@Override
public Logger create(Class<?> type) {
	return this.logger != null ? this.logger : new Slf4jLogger(type);
}