Search in sources :

Example 1 with DiscoveryRepresentation

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)));
    }
}
Also used : AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) DiscoveryRepresentation(org.neo4j.server.rest.repr.DiscoveryRepresentation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)1 DiscoveryRepresentation (org.neo4j.server.rest.repr.DiscoveryRepresentation)1