Skip to content

Commit

Permalink
Allow configuring the protocol on Cloudfoundry
Browse files Browse the repository at this point in the history
closes #1269
  • Loading branch information
imod authored and joshiste committed Oct 11, 2019
1 parent 27bf67f commit e6e4069
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public CloudFoundryApplicationFactory(InstanceProperties instance,
this.cfApplicationProperties = cfApplicationProperties;
}

@Override
protected String getServiceBaseUrl() {
if (cfApplicationProperties.getUris().isEmpty()) {
return super.getServiceBaseUrl();
}
@Override
protected String getServiceBaseUrl() {
if (cfApplicationProperties.getUris().isEmpty()) {
return super.getServiceBaseUrl();
}

String uri = cfApplicationProperties.getUris().get(0);
return "http://" + uri;
}
String uri = cfApplicationProperties.getUris().get(0);
String schema = this.getMetadata().getOrDefault("serviceSchema", "http");
return schema + "://" + uri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,57 @@
import org.springframework.boot.autoconfigure.web.ServerProperties;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.HashMap;
import java.util.Map;

public class CloudFoundryApplicationFactoryTest {
private InstanceProperties instanceProperties = new InstanceProperties();
private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties();
private PathMappedEndpoints pathMappedEndpoints = mock(PathMappedEndpoints.class);
private WebEndpointProperties webEndpoint = new WebEndpointProperties();
private CloudFoundryApplicationProperties cfApplicationProperties = new CloudFoundryApplicationProperties();
private CloudFoundryApplicationFactory factory = new CloudFoundryApplicationFactory(instanceProperties, management,
server, pathMappedEndpoints, webEndpoint, () -> singletonMap("contributor", "test"), cfApplicationProperties);
private Map<String, String> metadata = new HashMap<>();

private CloudFoundryApplicationFactory factory = new CloudFoundryApplicationFactory(instanceProperties, management,
server, pathMappedEndpoints, webEndpoint, () -> metadata, cfApplicationProperties);

@Before
public void setup() {
instanceProperties.setName("test");
metadata.put("contributor", "test");
}

@Test
public void should_use_application_uri() {

when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
cfApplicationProperties.setUris(singletonList("application/Uppercase"));

Application app = factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");
}

@Test
public void should_use_application_uri_with_defined_service_schema() {

@Before
public void setup() {
instanceProperties.setName("test");
}
metadata.put("serviceSchema", "https");

@Test
public void should_use_application_uri() {
when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
cfApplicationProperties.setUris(singletonList("application/Uppercase"));
when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
cfApplicationProperties.setUris(singletonList("application/Uppercase"));

Application app = factory.createApplication();
Application app = factory.createApplication();

assertThat(app.getManagementUrl()).isEqualTo("http://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://application/Uppercase/");
}
assertThat(app.getManagementUrl()).isEqualTo("https://application/Uppercase/actuator");
assertThat(app.getHealthUrl()).isEqualTo("https://application/Uppercase/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("https://application/Uppercase/");
}

}
4 changes: 4 additions & 0 deletions spring-boot-admin-docs/src/main/asciidoc/client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,8 @@ spring.boot.admin.client.password
user.password
| Credentials being used to access the endpoints.
|
| serviceSchema
| schema used by SBA server to access the client/instance on CloudFoundry
| http
|===

Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ eureka:
metadata-map:
applicationId: ${vcap.application.application_id}
instanceId: ${vcap.application.instance_index}
serviceSchema: https
----

0 comments on commit e6e4069

Please sign in to comment.