use of org.neo4j.server.rest.repr.DiscoveryRepresentation in project neo4j by neo4j.
the class DiscoveryService method getDiscoveryDocument.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getDiscoveryDocument(@Context UriInfo uriInfo) throws URISyntaxException {
String managementUri = config.get(ServerSettings.management_api_path).getPath() + "/";
String dataUri = config.get(ServerSettings.rest_api_path).getPath() + "/";
Optional<AdvertisedSocketAddress> boltAddress = config.enabledBoltConnectors().stream().findFirst().map(boltConnector -> config.get(boltConnector.advertised_address));
if (boltAddress.isPresent()) {
AdvertisedSocketAddress advertisedSocketAddress = boltAddress.get();
if (advertisedSocketAddress.getHostname().equals("localhost")) {
// Use the port specified in the config, but not the host
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, new AdvertisedSocketAddress(uriInfo.getBaseUri().getHost(), advertisedSocketAddress.getPort())));
} else {
// Use the config verbatim since it seems sane
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, advertisedSocketAddress));
}
} else {
// There's no config, compute possible endpoint using host header and default bolt port.
return outputFormat.ok(new DiscoveryRepresentation(managementUri, dataUri, new AdvertisedSocketAddress(uriInfo.getBaseUri().getHost(), 7687)));
}
}
Aggregations