Unverified Commit ee067ed3 by Spencer Gibb

Merge branch 'raiRaiyan-gh-2303'

parents d7c13ada b57dedb7
......@@ -24,5 +24,6 @@ import com.netflix.appinfo.InstanceInfo;
*/
public interface CloudEurekaInstanceConfig extends EurekaInstanceConfig {
void setNonSecurePort(int port);
void setSecurePort(int securePort);
InstanceInfo.InstanceStatus getInitialStatus();
}
......@@ -126,13 +126,21 @@ public class EurekaClientAutoConfiguration {
String hostname = eurekaPropertyResolver.getProperty("hostname");
boolean preferIpAddress = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("preferIpAddress"));
boolean isSecurePortEnabled = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("securePortEnabled"));
int nonSecurePort = Integer.valueOf(propertyResolver.getProperty("server.port", propertyResolver.getProperty("port", "8080")));
int managementPort = Integer.valueOf(propertyResolver.getProperty("management.port", String.valueOf(nonSecurePort)));
String managementContextPath = propertyResolver.getProperty("management.contextPath", propertyResolver.getProperty("server.contextPath", "/"));
EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils);
instance.setNonSecurePort(nonSecurePort);
instance.setInstanceId(getDefaultInstanceId(propertyResolver));
instance.setPreferIpAddress(preferIpAddress);
if(isSecurePortEnabled) {
int securePort = Integer.valueOf(propertyResolver.getProperty("server.port", propertyResolver.getProperty("port", "8080")));
instance.setSecurePort(securePort);
}
if (managementPort != nonSecurePort && managementPort != 0) {
if (StringUtils.hasText(hostname)) {
instance.setHostname(hostname);
......@@ -148,6 +156,7 @@ public class EurekaClientAutoConfiguration {
if (StringUtils.hasText(healthCheckUrlPath)) {
instance.setHealthCheckUrlPath(healthCheckUrlPath);
}
String scheme = instance.getSecurePortEnabled() ? "https" : "http";
URL base = new URL(scheme, instance.getHostname(), managementPort, managementContextPath);
instance.setStatusPageUrl(new URL(base, StringUtils.trimLeadingCharacter(instance.getStatusPageUrlPath(), '/')).toString());
......
......@@ -36,6 +36,7 @@ import org.springframework.core.Ordered;
* @author Spencer Gibb
* @author Jon Schneider
* @author Jakub Narloch
* @author raiyan
*/
public class EurekaAutoServiceRegistration implements AutoServiceRegistration, SmartLifecycle, Ordered {
......@@ -61,9 +62,15 @@ public class EurekaAutoServiceRegistration implements AutoServiceRegistration, S
@Override
public void start() {
// only set the port if the nonSecurePort is 0 and this.port != 0
if (this.port.get() != 0 && this.registration.getNonSecurePort() == 0) {
this.registration.setNonSecurePort(this.port.get());
// only set the port if the nonSecurePort or securePort is 0 and this.port != 0
if (this.port.get() != 0) {
if (this.registration.getNonSecurePort() == 0) {
this.registration.setNonSecurePort(this.port.get());
}
if (this.registration.getSecurePort() == 0 && this.registration.isSecure()) {
this.registration.setSecurePort(this.port.get());
}
}
// only initialize if nonSecurePort is greater than 0 and it isn't already running
......
......@@ -193,6 +193,14 @@ public class EurekaRegistration implements Registration, Closeable {
return this.instanceConfig.getNonSecurePort();
}
public void setSecurePort(int port) {
this.instanceConfig.setSecurePort(port);
}
public int getSecurePort() {
return this.instanceConfig.getSecurePort();
}
@Override
public void close() throws IOException {
this.eurekaClient.shutdown();
......
......@@ -92,6 +92,23 @@ public class EurekaClientAutoConfigurationTests {
}
@Test
public void securePortPeriods() {
testSecurePort("server.port");
}
@Test
public void securePortUnderscores() {
testSecurePort("SERVER_PORT");
}
@Test
public void securePort() {
testSecurePort("PORT");
assertEquals("eurekaClient",
this.context.getBeanDefinition("eurekaClient").getFactoryMethodName());
}
@Test
public void managementPort() {
EnvironmentTestUtils.addEnvironment(this.context, "server.port=8989",
"management.port=9999");
......@@ -331,6 +348,13 @@ public class EurekaClientAutoConfigurationTests {
assertEquals(8888, getInstanceConfig().getNonSecurePort());
}
private void testSecurePort(String propName) {
EnvironmentTestUtils.addEnvironment(this.context, "eureka.instance.securePortEnabled=true");
addEnvironment(this.context, propName + ":8443");
setupContext();
assertEquals(8443, getInstanceConfig().getSecurePort());
}
private EurekaInstanceConfigBean getInstanceConfig() {
return this.context.getBean(EurekaInstanceConfigBean.class);
}
......
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