Allow init params to be set on ProxyStreamServlet. (#2335)
* Allow init params to be set on ProxyStreamServlet. Fixes gh-2301 * Added unit test for #gh-2301
This commit is contained in:
committed by
Ryan Baxter
parent
7f97a61ed5
commit
f809c119bd
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,6 +52,7 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Roy Clarkson
|
||||
* @author Fahim Farook
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(HystrixDashboardProperties.class)
|
||||
@@ -87,10 +88,13 @@ public class HystrixDashboardConfiguration {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean proxyStreamServlet() {
|
||||
ProxyStreamServlet proxyStreamServlet = new ProxyStreamServlet();
|
||||
proxyStreamServlet.setEnableIgnoreConnectionCloseHeader(dashboardProperties
|
||||
.isEnableIgnoreConnectionCloseHeader());
|
||||
return new ServletRegistrationBean(proxyStreamServlet, "/proxy.stream");
|
||||
final ProxyStreamServlet proxyStreamServlet = new ProxyStreamServlet();
|
||||
proxyStreamServlet.setEnableIgnoreConnectionCloseHeader(
|
||||
this.dashboardProperties.isEnableIgnoreConnectionCloseHeader());
|
||||
final ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
proxyStreamServlet, "/proxy.stream");
|
||||
registration.setInitParameters(this.dashboardProperties.getInitParameters());
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,10 +15,14 @@
|
||||
*/
|
||||
package org.springframework.cloud.netflix.hystrix.dashboard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author Roy Clarkson
|
||||
* @author Fahim Farook
|
||||
*/
|
||||
@ConfigurationProperties("hystrix.dashboard")
|
||||
public class HystrixDashboardProperties {
|
||||
@@ -28,6 +32,13 @@ public class HystrixDashboardProperties {
|
||||
* the Hystrix response stream
|
||||
*/
|
||||
private boolean enableIgnoreConnectionCloseHeader = false;
|
||||
|
||||
/**
|
||||
* Initialization parameters for {@link ProxyStreamServlet}. ProxyStreamServlet itself
|
||||
* is not dependent on any initialization parameters, but could be used for adding web
|
||||
* container specific configurations. i.e. wl-dispatch-policy for WebLogic.
|
||||
*/
|
||||
private Map<String, String> initParameters = new HashMap<>();
|
||||
|
||||
public boolean isEnableIgnoreConnectionCloseHeader() {
|
||||
return enableIgnoreConnectionCloseHeader;
|
||||
@@ -38,4 +49,7 @@ public class HystrixDashboardProperties {
|
||||
this.enableIgnoreConnectionCloseHeader = enableIgnoreConnectionCloseHeader;
|
||||
}
|
||||
|
||||
public Map<String, String> getInitParameters() {
|
||||
return this.initParameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +16,39 @@
|
||||
|
||||
package org.springframework.cloud.netflix.hystrix.dashboard;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* @author Roy Clarkson
|
||||
* @author Fahim Farook
|
||||
*/
|
||||
public class HystrixDashboardConfigurationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normal() {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -87,5 +104,17 @@ public class HystrixDashboardConfigurationTests {
|
||||
assertThat(response.getHeader("Content-Type"), is("text/proxy.stream"));
|
||||
assertThat(response.getHeader("Connection"), is("close"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void initParameters() {
|
||||
this.context = new SpringApplicationBuilder(HystrixDashboardConfiguration.class)
|
||||
.properties("hystrix.dashboard.init-parameters.wl-dispatch-polixy=work-manager-hystrix")
|
||||
.web(false).bannerMode(Mode.OFF).run();
|
||||
final ServletRegistrationBean registration = this.context.getBean(ServletRegistrationBean.class);
|
||||
assertNotNull(registration);
|
||||
|
||||
final Map<String, String> initParameters = registration.getInitParameters();
|
||||
assertNotNull(initParameters);
|
||||
assertThat(initParameters.get("wl-dispatch-polixy"), is("work-manager-hystrix"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user