diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java index 952db10b..7edd7645 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java @@ -52,12 +52,12 @@ public class SpringClientFactory { loadBalancer = getNamedLoadBalancer(restClientName, clientConfig.getClass()); } if (client instanceof AbstractLoadBalancerAwareClient) { - ((AbstractLoadBalancerAwareClient) client).setLoadBalancer(loadBalancer); + ((AbstractLoadBalancerAwareClient) client).setLoadBalancer(loadBalancer); } } catch (Throwable e) { String message = "Unable to InitializeAndAssociateNFLoadBalancer set for RestClient:" + restClientName; - log.warn(message, e); + log.warn(message); throw new ClientException(ClientException.ErrorType.CONFIGURATION, message, e); } @@ -74,11 +74,11 @@ public class SpringClientFactory { * * @throws RuntimeException if an error occurs in creating the client. */ - public synchronized IClient getNamedClient(String name) { + public synchronized IClient getNamedClient(String name) { return getNamedClient(name, DefaultClientConfigImpl.class); } - public synchronized C namedClient(String name, Class clientClass) { + public synchronized > C namedClient(String name, Class clientClass) { return clientClass.cast(getNamedClient(name, DefaultClientConfigImpl.class)); } @@ -87,7 +87,7 @@ public class SpringClientFactory { * * @throws RuntimeException if an error occurs in creating the client. */ - public synchronized IClient getNamedClient(String name, Class configClass) { + public synchronized IClient getNamedClient(String name, Class configClass) { if (simpleClientMap.get(name) != null) { return simpleClientMap.get(name); } @@ -103,7 +103,7 @@ public class SpringClientFactory { * * @throws ClientException if any error occurs, or if the client with the same name already exists */ - public synchronized IClient createNamedClient(String name, Class configClass) throws ClientException { + public synchronized IClient createNamedClient(String name, Class configClass) throws ClientException { IClientConfig config = getNamedConfig(name, configClass); return registerClientFromProperties(name, config); } @@ -183,10 +183,9 @@ public class SpringClientFactory { * @param className Class name of the object * @param clientConfig IClientConfig object used for initialization. */ - @SuppressWarnings("unchecked") public Object instantiateInstanceWithClientConfig(String className, IClientConfig clientConfig) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - Class clazz = Class.forName(className); + Class clazz = Class.forName(className); if (IClientConfigAware.class.isAssignableFrom(clazz)) { IClientConfigAware obj = (IClientConfigAware) clazz.newInstance(); obj.initWithNiwsConfig(clientConfig); diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java index 806dbe22..9d3f8efc 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java @@ -21,7 +21,7 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; /** * Preprocessor that configures defaults for eureka-discovered ribbon clients. - * Such as: @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses, + * Such as: @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses, * NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more * * @author Spencer Gibb @@ -58,6 +58,7 @@ public class EurekaRibbonClientPreprocessor implements RibbonClientPreprocessor setProp(serviceId, DeploymentContextBasedVipAddresses.key(), serviceId); setProp(serviceId, NFLoadBalancerRuleClassName.key(), ZoneAvoidanceRule.class.getName()); + // TODO: use bean name indirection to get this filter to be a @Bean setProp(serviceId, NIWSServerListFilterClassName.key(), ZonePreferenceServerListFilter.class.getName()); setProp(serviceId, EnableZoneAffinity.key(), "true");