Commit 63e6c813 by Dave Syer

Remove guava usages (fixes gh-154)

parent 29bee28d
...@@ -16,26 +16,18 @@ ...@@ -16,26 +16,18 @@
package org.springframework.cloud.netflix.eureka; package org.springframework.cloud.netflix.eureka;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications; import com.netflix.discovery.shared.Applications;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -78,15 +70,11 @@ public class EurekaDiscoveryClient implements DiscoveryClient { ...@@ -78,15 +70,11 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
List<InstanceInfo> infos = this.discovery.getInstancesByVipAddress(serviceId, List<InstanceInfo> infos = this.discovery.getInstancesByVipAddress(serviceId,
false); false);
Iterable<ServiceInstance> instances = transform(infos, List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
new Function<InstanceInfo, ServiceInstance>() { for (InstanceInfo info : infos) {
@Nullable instances.add(new EurekaServiceInstance(info));
@Override
public ServiceInstance apply(@Nullable InstanceInfo info) {
return new EurekaServiceInstance(info);
} }
}); return instances;
return Lists.newArrayList(instances);
} }
static class EurekaServiceInstance implements ServiceInstance { static class EurekaServiceInstance implements ServiceInstance {
...@@ -118,18 +106,16 @@ public class EurekaDiscoveryClient implements DiscoveryClient { ...@@ -118,18 +106,16 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
if (applications == null) { if (applications == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return Lists.newArrayList(filter( List<Application> registered = applications.getRegisteredApplications();
transform(applications.getRegisteredApplications(), List<String> names = new ArrayList<String>();
new Function<Application, String>() { for (Application app : registered) {
@Nullable
@Override
public String apply(@Nullable Application app) {
if (app.getInstances().isEmpty()) { if (app.getInstances().isEmpty()) {
return null; continue;
} }
return app.getName().toLowerCase(); names.add(app.getName().toLowerCase());
} }
}), Predicates.notNull())); return names;
} }
@Override @Override
...@@ -138,21 +124,13 @@ public class EurekaDiscoveryClient implements DiscoveryClient { ...@@ -138,21 +124,13 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
if (applications == null) { if (applications == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
Iterable<ServiceInstance> instances = transform( List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
concat(transform(applications.getRegisteredApplications(), for (Application app : applications.getRegisteredApplications()) {
new Function<Application, List<InstanceInfo>>() { for (InstanceInfo info : app.getInstances()) {
@Override instances.add(new EurekaServiceInstance(info));
public List<InstanceInfo> apply(@Nullable Application app) {
return app.getInstances();
} }
})), new Function<InstanceInfo, ServiceInstance>() {
@Nullable
@Override
public ServiceInstance apply(@Nullable InstanceInfo info) {
return new EurekaServiceInstance(info);
} }
}); return instances;
return Lists.newArrayList(instances);
} }
} }
...@@ -24,8 +24,8 @@ import javax.net.ssl.HttpsURLConnection; ...@@ -24,8 +24,8 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.util.ReflectionUtils;
import com.google.common.base.Throwables;
import com.netflix.client.ClientException; import com.netflix.client.ClientException;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer; import com.netflix.loadbalancer.ILoadBalancer;
...@@ -66,7 +66,8 @@ public class FeignRibbonClient implements Client { ...@@ -66,7 +66,8 @@ public class FeignRibbonClient implements Client {
if (ex.getCause() instanceof IOException) { if (ex.getCause() instanceof IOException) {
throw IOException.class.cast(ex.getCause()); throw IOException.class.cast(ex.getCause());
} }
throw Throwables.propagate(ex); ReflectionUtils.rethrowRuntimeException(ex);
return null;
} }
} }
......
...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.feign.support; ...@@ -19,6 +19,7 @@ package org.springframework.cloud.netflix.feign.support;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Collection; import java.util.Collection;
import javax.inject.Provider; import javax.inject.Provider;
...@@ -32,14 +33,12 @@ import org.springframework.http.HttpOutputMessage; ...@@ -32,14 +33,12 @@ import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import com.google.common.base.Charsets;
import static org.springframework.cloud.netflix.feign.support.FeignUtils.getHttpHeaders;
import feign.RequestTemplate; import feign.RequestTemplate;
import feign.codec.EncodeException; import feign.codec.EncodeException;
import feign.codec.Encoder; import feign.codec.Encoder;
import static org.springframework.cloud.netflix.feign.support.FeignUtils.getHttpHeaders;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -89,7 +88,7 @@ public class SpringEncoder implements Encoder { ...@@ -89,7 +88,7 @@ public class SpringEncoder implements Encoder {
throw new EncodeException("Error converting request body", ex); throw new EncodeException("Error converting request body", ex);
} }
request.body(outputMessage.getOutputStream().toByteArray(), request.body(outputMessage.getOutputStream().toByteArray(),
Charsets.UTF_8); // TODO: set charset Charset.forName("UTF-8")); // TODO: set charset
return; return;
} }
} }
......
...@@ -22,8 +22,8 @@ import java.util.concurrent.TimeUnit; ...@@ -22,8 +22,8 @@ import java.util.concurrent.TimeUnit;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest; import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest;
import org.springframework.util.ReflectionUtils;
import com.google.common.base.Throwables;
import com.netflix.loadbalancer.ILoadBalancer; import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerStats; import com.netflix.loadbalancer.ServerStats;
...@@ -74,7 +74,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -74,7 +74,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
} }
catch (Exception ex) { catch (Exception ex) {
recordStats(context, tracer, serverStats, null, ex); recordStats(context, tracer, serverStats, null, ex);
Throwables.propagate(ex); ReflectionUtils.rethrowRuntimeException(ex);
} }
return null; return null;
} }
...@@ -128,7 +128,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -128,7 +128,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
} }
public Server getServer() { public Server getServer() {
return server; return this.server;
} }
} }
......
...@@ -19,9 +19,10 @@ package org.springframework.cloud.netflix.zuul.filters.post; ...@@ -19,9 +19,10 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import lombok.extern.apachecommons.CommonsLog; import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ReflectionUtils;
import com.google.common.base.Throwables;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
...@@ -75,7 +76,7 @@ public class SendErrorFilter extends ZuulFilter { ...@@ -75,7 +76,7 @@ public class SendErrorFilter extends ZuulFilter {
} }
} }
catch (Exception ex) { catch (Exception ex) {
Throwables.propagate(ex); ReflectionUtils.rethrowRuntimeException(ex);
} }
return null; return null;
} }
......
...@@ -25,7 +25,8 @@ import java.util.zip.GZIPInputStream; ...@@ -25,7 +25,8 @@ import java.util.zip.GZIPInputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.google.common.base.Throwables; import org.springframework.util.ReflectionUtils;
import com.netflix.config.DynamicBooleanProperty; import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicIntProperty; import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory; import com.netflix.config.DynamicPropertyFactory;
...@@ -76,7 +77,7 @@ public class SendResponseFilter extends ZuulFilter { ...@@ -76,7 +77,7 @@ public class SendResponseFilter extends ZuulFilter {
writeResponse(); writeResponse();
} }
catch (Exception ex) { catch (Exception ex) {
Throwables.propagate(ex); ReflectionUtils.rethrowRuntimeException(ex);
} }
return null; return null;
} }
......
...@@ -29,7 +29,6 @@ import org.springframework.http.MediaType; ...@@ -29,7 +29,6 @@ import org.springframework.http.MediaType;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import com.google.common.base.Throwables;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.http.HttpServletRequestWrapper; import com.netflix.zuul.http.HttpServletRequestWrapper;
...@@ -83,14 +82,10 @@ public class FormBodyWrapperFilter extends ZuulFilter { ...@@ -83,14 +82,10 @@ public class FormBodyWrapperFilter extends ZuulFilter {
RequestContext ctx = RequestContext.getCurrentContext(); RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest(); HttpServletRequest request = ctx.getRequest();
if (request instanceof HttpServletRequestWrapper) { if (request instanceof HttpServletRequestWrapper) {
try { HttpServletRequest wrapped = (HttpServletRequest) ReflectionUtils.getField(
HttpServletRequest wrapped = (HttpServletRequest) this.requestField this.requestField, request);
.get(request); ReflectionUtils.setField(this.requestField, request,
this.requestField.set(request, new FormBodyRequestWrapper(wrapped)); new FormBodyRequestWrapper(wrapped));
}
catch (IllegalAccessException ex) {
Throwables.propagate(ex);
}
} }
else { else {
ctx.setRequest(new FormBodyRequestWrapper(request)); ctx.setRequest(new FormBodyRequestWrapper(request));
......
...@@ -33,7 +33,6 @@ import javax.servlet.http.Part; ...@@ -33,7 +33,6 @@ import javax.servlet.http.Part;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import com.google.common.base.Throwables;
import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.http.HttpServletRequestWrapper; import com.netflix.zuul.http.HttpServletRequestWrapper;
...@@ -53,7 +52,7 @@ public class Servlet30WrapperFilter extends ZuulFilter { ...@@ -53,7 +52,7 @@ public class Servlet30WrapperFilter extends ZuulFilter {
} }
protected Field getRequestField() { protected Field getRequestField() {
return requestField; return this.requestField;
} }
@Override @Override
...@@ -76,15 +75,10 @@ public class Servlet30WrapperFilter extends ZuulFilter { ...@@ -76,15 +75,10 @@ public class Servlet30WrapperFilter extends ZuulFilter {
RequestContext ctx = RequestContext.getCurrentContext(); RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest(); HttpServletRequest request = ctx.getRequest();
if (request instanceof HttpServletRequestWrapper) { if (request instanceof HttpServletRequestWrapper) {
try { request = (HttpServletRequest) ReflectionUtils.getField(this.requestField,
request = (HttpServletRequest) this.requestField.get(request); request);
}
catch (IllegalAccessException ex) {
Throwables.propagate(ex);
}
} }
ctx.setRequest(new Servlet30RequestWrapper(request)); ctx.setRequest(new Servlet30RequestWrapper(request));
// ctx.setResponse(new HttpServletResponseWrapper(ctx.getResponse()));
return null; return null;
} }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package org.springframework.cloud.netflix.archaius; package org.springframework.cloud.netflix.archaius;
import com.google.common.collect.Sets; import java.util.Collections;
import com.netflix.config.ConfigurationManager;
import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener; import org.apache.commons.configuration.event.ConfigurationListener;
...@@ -27,6 +27,8 @@ import org.springframework.boot.test.EnvironmentTestUtils; ...@@ -27,6 +27,8 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.netflix.config.ConfigurationManager;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
...@@ -58,17 +60,20 @@ public class ArchaiusAutoConfigurationTests { ...@@ -58,17 +60,20 @@ public class ArchaiusAutoConfigurationTests {
public void environmentChangeEventPropagated() { public void environmentChangeEventPropagated() {
this.context = new AnnotationConfigApplicationContext( this.context = new AnnotationConfigApplicationContext(
ArchaiusAutoConfiguration.class); ArchaiusAutoConfiguration.class);
ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() { ConfigurationManager.getConfigInstance().addConfigurationListener(
new ConfigurationListener() {
@Override @Override
public void configurationChanged(ConfigurationEvent event) { public void configurationChanged(ConfigurationEvent event) {
if (event.getPropertyName().equals("my.prop")) { if (event.getPropertyName().equals("my.prop")) {
propertyValue = event.getPropertyValue(); ArchaiusAutoConfigurationTests.this.propertyValue = event
.getPropertyValue();
} }
} }
}); });
EnvironmentTestUtils.addEnvironment(context, "my.prop=my.newval"); EnvironmentTestUtils.addEnvironment(this.context, "my.prop=my.newval");
context.publishEvent(new EnvironmentChangeEvent(Sets.newHashSet("my.prop"))); this.context.publishEvent(new EnvironmentChangeEvent(Collections
assertEquals("my.newval", propertyValue); .singleton("my.prop")));
assertEquals("my.newval", this.propertyValue);
} }
} }
...@@ -71,21 +71,21 @@ public class HystrixOnlyTests { ...@@ -71,21 +71,21 @@ public class HystrixOnlyTests {
@Test @Test
public void testHystrixHealth() { public void testHystrixHealth() {
Map map = getHealth(); Map<?, ?> map = getHealth();
assertTrue("Missing hystrix health key", map.containsKey("hystrix")); assertTrue("Missing hystrix health key", map.containsKey("hystrix"));
Map hystrix = (Map) map.get("hystrix"); Map<?, ?> hystrix = (Map<?, ?>) map.get("hystrix");
assertEquals("Wrong hystrix status", "UP", hystrix.get("status")); assertEquals("Wrong hystrix status", "UP", hystrix.get("status"));
} }
@Test @Test
public void testNoDiscoveryHealth() { public void testNoDiscoveryHealth() {
Map map = getHealth(); Map<?, ?> map = getHealth();
// There is explicitly no discovery, so there should be no discovery health key // There is explicitly no discovery, so there should be no discovery health key
assertFalse("Incorrect existing discovery health key", assertFalse("Incorrect existing discovery health key",
map.containsKey("discovery")); map.containsKey("discovery"));
} }
private Map getHealth() { private Map<?, ?> getHealth() {
return new TestRestTemplate().getForObject("http://localhost:" + this.port return new TestRestTemplate().getForObject("http://localhost:" + this.port
+ "/admin/health", Map.class); + "/admin/health", Map.class);
} }
......
...@@ -32,9 +32,9 @@ import org.springframework.http.HttpRequest; ...@@ -32,9 +32,9 @@ import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.support.HttpRequestWrapper; import org.springframework.http.client.support.HttpRequestWrapper;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import com.google.common.base.Throwables;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -99,7 +99,7 @@ public class RibbonInterceptorTests { ...@@ -99,7 +99,7 @@ public class RibbonInterceptorTests {
return request.apply(this.instance); return request.apply(this.instance);
} }
catch (Exception ex) { catch (Exception ex) {
Throwables.propagate(ex); ReflectionUtils.rethrowRuntimeException(ex);
} }
return null; return null;
} }
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
package org.springframework.cloud.netflix.ribbon.eureka; package org.springframework.cloud.netflix.ribbon.eureka;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
import com.google.common.collect.ImmutableMap;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.DefaultClientConfigImpl; import com.netflix.client.config.DefaultClientConfigImpl;
...@@ -72,8 +72,8 @@ public class DomainExtractingServerListTests { ...@@ -72,8 +72,8 @@ public class DomainExtractingServerListTests {
assertEquals("hostPort was wrong", HOST_NAME + ":" + PORT, des.getHostPort()); assertEquals("hostPort was wrong", HOST_NAME + ":" + PORT, des.getHostPort());
} }
protected DomainExtractingServer assertDomainExtractingServer(List<DiscoveryEnabledServer> servers, protected DomainExtractingServer assertDomainExtractingServer(
String zone) { List<DiscoveryEnabledServer> servers, String zone) {
Server actualServer = servers.get(0); Server actualServer = servers.get(0);
assertTrue("server was not a DomainExtractingServer", assertTrue("server was not a DomainExtractingServer",
actualServer instanceof DomainExtractingServer); actualServer instanceof DomainExtractingServer);
...@@ -105,8 +105,7 @@ public class DomainExtractingServerListTests { ...@@ -105,8 +105,7 @@ public class DomainExtractingServerListTests {
given(server.getInstanceInfo()).willReturn(instanceInfo); given(server.getInstanceInfo()).willReturn(instanceInfo);
given(server.getHost()).willReturn(HOST_NAME); given(server.getHost()).willReturn(HOST_NAME);
given(instanceInfo.getMetadata()).willReturn( given(instanceInfo.getMetadata()).willReturn(
ImmutableMap.<String, String> builder().put("instanceId", INSTANCE_ID) Collections.<String, String> singletonMap("instanceId", INSTANCE_ID));
.build());
given(instanceInfo.getHostName()).willReturn(HOST_NAME); given(instanceInfo.getHostName()).willReturn(HOST_NAME);
given(instanceInfo.getIPAddr()).willReturn(IP_ADDR); given(instanceInfo.getIPAddr()).willReturn(IP_ADDR);
given(instanceInfo.getPort()).willReturn(PORT); given(instanceInfo.getPort()).willReturn(PORT);
......
...@@ -16,20 +16,17 @@ ...@@ -16,20 +16,17 @@
package org.springframework.cloud.netflix.zuul.filters; package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator.ProxyRouteSpec; import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator.ProxyRouteSpec;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute; import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import com.google.common.collect.Lists;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
...@@ -204,9 +201,9 @@ public class ProxyRouteLocatorTests { ...@@ -204,9 +201,9 @@ public class ProxyRouteLocatorTests {
public void testIgnoreRoutes() { public void testIgnoreRoutes() {
ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery, ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery,
this.properties); this.properties);
this.properties.setIgnoredServices(Lists.newArrayList(IGNOREDSERVICE)); this.properties.setIgnoredServices(Collections.singletonList(IGNOREDSERVICE));
given(this.discovery.getServices()) given(this.discovery.getServices()).willReturn(
.willReturn(Lists.newArrayList(IGNOREDSERVICE)); Collections.singletonList(IGNOREDSERVICE));
Map<String, String> routesMap = routeLocator.getRoutes(); Map<String, String> routesMap = routeLocator.getRoutes();
String serviceId = routesMap.get(getMapping(IGNOREDSERVICE)); String serviceId = routesMap.get(getMapping(IGNOREDSERVICE));
assertNull("routes did not ignore " + IGNOREDSERVICE, serviceId); assertNull("routes did not ignore " + IGNOREDSERVICE, serviceId);
...@@ -216,7 +213,8 @@ public class ProxyRouteLocatorTests { ...@@ -216,7 +213,8 @@ public class ProxyRouteLocatorTests {
public void testAutoRoutes() { public void testAutoRoutes() {
ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery, ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery,
this.properties); this.properties);
given(this.discovery.getServices()).willReturn(Lists.newArrayList(MYSERVICE)); given(this.discovery.getServices()).willReturn(
Collections.singletonList(MYSERVICE));
Map<String, String> routesMap = routeLocator.getRoutes(); Map<String, String> routesMap = routeLocator.getRoutes();
assertNotNull("routesMap was null", routesMap); assertNotNull("routesMap was null", routesMap);
assertFalse("routesMap was empty", routesMap.isEmpty()); assertFalse("routesMap was empty", routesMap.isEmpty());
...@@ -230,7 +228,8 @@ public class ProxyRouteLocatorTests { ...@@ -230,7 +228,8 @@ public class ProxyRouteLocatorTests {
this.properties.getRoutes().put(MYSERVICE, route); this.properties.getRoutes().put(MYSERVICE, route);
ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery, ProxyRouteLocator routeLocator = new ProxyRouteLocator(this.discovery,
this.properties); this.properties);
given(this.discovery.getServices()).willReturn(Lists.newArrayList(MYSERVICE)); given(this.discovery.getServices()).willReturn(
Collections.singletonList(MYSERVICE));
Map<String, String> routesMap = routeLocator.getRoutes(); Map<String, String> routesMap = routeLocator.getRoutes();
assertNotNull("routesMap was null", routesMap); assertNotNull("routesMap was null", routesMap);
assertFalse("routesMap was empty", routesMap.isEmpty()); assertFalse("routesMap was empty", routesMap.isEmpty());
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.cloud.netflix.eureka.server; package org.springframework.cloud.netflix.eureka.server;
import java.util.Collections;
import javax.servlet.Filter; import javax.servlet.Filter;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
...@@ -30,7 +32,6 @@ import org.springframework.context.annotation.Import; ...@@ -30,7 +32,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.google.common.collect.Lists;
import com.sun.jersey.spi.container.servlet.ServletContainer; import com.sun.jersey.spi.container.servlet.ServletContainer;
/** /**
...@@ -57,8 +58,8 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -57,8 +58,8 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
EurekaServerConfigBean.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*"); EurekaServerConfigBean.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");
bean.addInitParameter("com.sun.jersey.config.property.packages", bean.addInitParameter("com.sun.jersey.config.property.packages",
"com.netflix.discovery;com.netflix.eureka"); "com.netflix.discovery;com.netflix.eureka");
bean.setUrlPatterns(Lists.newArrayList(EurekaServerConfigBean.DEFAULT_PREFIX bean.setUrlPatterns(Collections
+ "/*")); .singletonList(EurekaServerConfigBean.DEFAULT_PREFIX + "/*"));
return bean; return bean;
} }
......
...@@ -18,22 +18,17 @@ package org.springframework.cloud.netflix.eureka.server.event; ...@@ -18,22 +18,17 @@ package org.springframework.cloud.netflix.eureka.server.event;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import lombok.extern.apachecommons.CommonsLog; import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.server.advice.LeaseManagerLite; import org.springframework.cloud.netflix.eureka.server.advice.LeaseManagerLite;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Application;
import com.netflix.eureka.PeerAwareInstanceRegistry; import com.netflix.eureka.PeerAwareInstanceRegistry;
import com.netflix.eureka.lease.Lease; import com.netflix.eureka.lease.Lease;
import static com.google.common.collect.Iterables.tryFind;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -73,22 +68,19 @@ public class LeaseManagerMessageBroker implements LeaseManagerLite<InstanceInfo> ...@@ -73,22 +68,19 @@ public class LeaseManagerMessageBroker implements LeaseManagerLite<InstanceInfo>
+ isReplication); + isReplication);
List<Application> applications = PeerAwareInstanceRegistry.getInstance() List<Application> applications = PeerAwareInstanceRegistry.getInstance()
.getSortedApplications(); .getSortedApplications();
Optional<Application> app = tryFind(applications, new Predicate<Application>() { for (Application input : applications) {
@Override if (input.getName().equals(appName)) {
public boolean apply(@Nullable Application input) { InstanceInfo instance = null;
return input.getName().equals(appName); for (InstanceInfo info : input.getInstances()) {
if (info.getHostName().equals(serverId)) {
instance = info;
break;
} }
});
if (app.isPresent()) {
Optional<InstanceInfo> info = tryFind(app.get().getInstances(),
new Predicate<InstanceInfo>() {
@Override
public boolean apply(@Nullable InstanceInfo input) {
return input.getHostName().equals(serverId);
} }
});
this.ctxt.publishEvent(new EurekaInstanceRenewedEvent(this, appName, this.ctxt.publishEvent(new EurekaInstanceRenewedEvent(this, appName,
serverId, info.orNull(), isReplication)); serverId, instance, isReplication));
break;
}
} }
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment