Commit d0480059 by Dave Syer

De-tangle zuul packages

The main problem here was the ZuulProperties being used everywhere. I also took the opportunity to thin out the top level zuul package and keep the web and route locator pieces in sub-packages for readability. Fixes gh-172
parent 6b01e61d
......@@ -88,6 +88,7 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Parent
if (parent != null && "bootstrap".equals(parent.getId())
&& parent instanceof ConfigurableApplicationContext) {
if (listenerAdded.putIfAbsent(childId, childId) == null) {
@SuppressWarnings("resource")
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) parent;
ctx.addApplicationListener(new ApplicationListener<DiscoveryHeartbeatEvent>() {
@Override
......
......@@ -7,6 +7,7 @@ import org.springframework.context.ApplicationEvent;
* Specifically used when eureka is in the parent bootstrap context to relay the DiscoveryHeartbeatEvent to the child. Avoids stack overflow
* @author Spencer Gibb
*/
@SuppressWarnings("serial")
public class EurekaHeartbeatEvent extends ApplicationEvent {
private final Object value;
......
......@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.annotation.Import;
/**
......
......@@ -21,6 +21,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jmx.export.annotation.ManagedAttribute;
......
......@@ -16,6 +16,7 @@
package org.springframework.cloud.netflix.zuul;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.context.ApplicationEvent;
/**
......
......@@ -22,11 +22,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter;
import org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter;
import org.springframework.cloud.netflix.zuul.filters.pre.DebugFilter;
import org.springframework.cloud.netflix.zuul.filters.pre.FormBodyWrapperFilter;
import org.springframework.cloud.netflix.zuul.filters.pre.Servlet30WrapperFilter;
import org.springframework.cloud.netflix.zuul.web.ZuulController;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
......
......@@ -29,9 +29,12 @@ import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEven
import org.springframework.cloud.netflix.eureka.EurekaHeartbeatEvent;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.pre.PreDecorationFilter;
import org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter;
import org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
......@@ -65,7 +68,7 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
// pre filters
@Bean
public PreDecorationFilter preDecorationFilter() {
return new PreDecorationFilter(routeLocator(), this.zuulProperties);
return new PreDecorationFilter(routeLocator(), this.zuulProperties.isAddProxyHeaders());
}
// route filters
......@@ -96,7 +99,7 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
@Configuration
@ConditionalOnClass(Endpoint.class)
protected static class RoutesEndpointConfuguration {
protected static class RoutesEndpointConfiguration {
@Autowired
private ProxyRouteLocator routeLocator;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collection;
import java.util.LinkedHashMap;
......@@ -25,10 +25,10 @@ import java.util.concurrent.atomic.AtomicReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.zuul.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collection;
......
......@@ -14,12 +14,12 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.springframework.cloud.netflix.zuul.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
/**
* @author Dave Syer
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.filters;
import java.util.ArrayList;
import java.util.LinkedHashMap;
......
......@@ -22,9 +22,9 @@ import java.net.URL;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.cloud.netflix.zuul.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.ProxyRouteLocator.ProxyRouteSpec;
import org.springframework.cloud.netflix.zuul.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator.ProxyRouteSpec;
import org.springframework.util.StringUtils;
import com.netflix.zuul.ZuulFilter;
......@@ -35,11 +35,11 @@ public class PreDecorationFilter extends ZuulFilter {
private ProxyRouteLocator routeLocator;
private ZuulProperties properties;
private boolean addProxyHeaders;
public PreDecorationFilter(ProxyRouteLocator routeLocator, ZuulProperties properties) {
public PreDecorationFilter(ProxyRouteLocator routeLocator, boolean addProxyHeaders) {
this.routeLocator = routeLocator;
this.properties = properties;
this.addProxyHeaders = addProxyHeaders;
}
@Override
......@@ -77,7 +77,7 @@ public class PreDecorationFilter extends ZuulFilter {
ctx.setRouteHost(null);
ctx.addOriginResponseHeader("X-Zuul-ServiceId", location);
}
if (this.properties.isAddProxyHeaders()) {
if (this.addProxyHeaders) {
ctx.addZuulRequestHeader(
"X-Forwarded-Host",
ctx.getRequest().getServerName() + ":"
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......
......@@ -14,11 +14,12 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.web;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
/**
......@@ -40,7 +41,7 @@ public class ZuulHandlerMapping extends AbstractUrlHandlerMapping {
setOrder(-200);
}
protected void registerHandlers() {
public void registerHandlers() {
Collection<String> routes = this.routeLocator.getRoutePaths();
if (routes.isEmpty()) {
this.logger.warn("No routes found from ProxyRouteLocator");
......
......@@ -28,6 +28,7 @@ import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......
......@@ -29,6 +29,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......
......@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.netflix.zuul;
package org.springframework.cloud.netflix.zuul.filters;
import java.util.Map;
......@@ -22,8 +22,10 @@ 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.ProxyRouteLocator.ProxyRouteSpec;
import org.springframework.cloud.netflix.zuul.ZuulProperties.ZuulRoute;
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;
......
......@@ -16,23 +16,23 @@
package org.springframework.cloud.netflix.zuul.filters.pre;
import static org.junit.Assert.assertEquals;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.List;
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.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.ZuulProperties;
import org.springframework.cloud.netflix.zuul.ZuulProperties.ZuulRoute;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.mock.web.MockHttpServletRequest;
import com.netflix.util.Pair;
import com.netflix.zuul.context.RequestContext;
import static org.junit.Assert.assertEquals;
import static org.mockito.MockitoAnnotations.initMocks;
/**
* @author Dave Syer
*/
......@@ -53,7 +53,7 @@ public class PreDecorationFilterTests {
public void init() {
initMocks(this);
this.routeLocator = new ProxyRouteLocator(this.discovery, this.properties);
this.filter = new PreDecorationFilter(this.routeLocator, this.properties);
this.filter = new PreDecorationFilter(this.routeLocator, true);
RequestContext ctx = RequestContext.getCurrentContext();
ctx.setRequest(this.request);
}
......
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