Commit 63e6c813 by Dave Syer

Remove guava usages (fixes gh-154)

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