fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject [fineract-cn-permitted-feign-client] 05/40: Identity acquired now via feign builder instead of autowiring because pulling in configuration via @FeignClient causes it to be used for *all* the feign clients.
Date Fri, 08 May 2020 06:40:02 GMT
This is an automated email from the ASF dual-hosted git repository.

juhan pushed a commit to branch spring_boot_2
in repository https://gitbox.apache.org/repos/asf/fineract-cn-permitted-feign-client.git

commit f7b8d32c9e677e3f7a68fff3611bb107ead67268
Author: myrle-krantz <mkrantz@mifos.org>
AuthorDate: Mon May 22 16:34:32 2017 +0200

    Identity acquired now via feign builder instead of autowiring because pulling in configuration
via @FeignClient causes it to be used for *all* the feign clients.
---
 ...entConfiguration.java => LibraryConstants.java} | 12 ++------
 .../config/PermittedFeignClientConfiguration.java  | 36 +++++++++++++++++++++-
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
b/library/src/main/java/io/mifos/permittedfeignclient/LibraryConstants.java
similarity index 63%
copy from library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
copy to library/src/main/java/io/mifos/permittedfeignclient/LibraryConstants.java
index b37a43b..f9e4493 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/LibraryConstants.java
@@ -13,17 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package io.mifos.permittedfeignclient.config;
-
-import io.mifos.anubis.config.EnableAnubis;
-import org.springframework.cloud.netflix.feign.EnableFeignClients;
-import org.springframework.context.annotation.Configuration;
+package io.mifos.permittedfeignclient;
 
 /**
  * @author Myrle Krantz
  */
-@EnableAnubis
-@EnableFeignClients(basePackages = {"io.mifos.identity.api.v1"})
-@Configuration
-public class PermittedFeignClientConfiguration {
+public interface LibraryConstants {
+  String LOGGER_NAME = "permitted-feign-client-logger";
 }
diff --git a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
b/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
index b37a43b..2e3f442 100644
--- a/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
+++ b/library/src/main/java/io/mifos/permittedfeignclient/config/PermittedFeignClientConfiguration.java
@@ -15,15 +15,49 @@
  */
 package io.mifos.permittedfeignclient.config;
 
+import feign.Client;
+import feign.Feign;
+import feign.gson.GsonDecoder;
+import feign.gson.GsonEncoder;
 import io.mifos.anubis.config.EnableAnubis;
+import io.mifos.core.api.util.AnnotatedErrorDecoder;
+import io.mifos.core.api.util.TenantedTargetInterceptor;
+import io.mifos.core.api.util.TokenedTargetInterceptor;
+import io.mifos.identity.api.v1.client.IdentityManager;
+import io.mifos.permittedfeignclient.LibraryConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.cloud.netflix.feign.EnableFeignClients;
+import org.springframework.cloud.netflix.feign.support.SpringMvcContract;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
+import javax.annotation.Nonnull;
+
 /**
  * @author Myrle Krantz
  */
 @EnableAnubis
-@EnableFeignClients(basePackages = {"io.mifos.identity.api.v1"})
 @Configuration
 public class PermittedFeignClientConfiguration {
+  @Bean(name = LibraryConstants.LOGGER_NAME)
+  public Logger logger() {
+    return LoggerFactory.getLogger(LibraryConstants.LOGGER_NAME);
+  }
+
+  @Bean
+  public IdentityManager identityManager(
+          final @Nonnull Client feignClient,
+          final @Qualifier(LibraryConstants.LOGGER_NAME) @Nonnull Logger logger) {
+    return Feign.builder()
+            .contract(new SpringMvcContract())
+            .client(feignClient) //Integrates to ribbon.
+            .errorDecoder(new AnnotatedErrorDecoder(logger, IdentityManager.class))
+            .requestInterceptor(new TenantedTargetInterceptor())
+            .requestInterceptor(new TokenedTargetInterceptor())
+            .decoder(new GsonDecoder())
+            .encoder(new GsonEncoder())
+            .target(IdentityManager.class, "https://identity-v1");
+  }
 }


Mime
View raw message