de.codecentric.boot.admin.server.domain.values.Endpoint Java Examples

The following examples show how to use de.codecentric.boot.admin.server.domain.values.Endpoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusUpdaterTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    eventStore = new InMemoryEventStore();
    repository = new EventsourcingInstanceRepository(eventStore);
    instance = Instance.create(InstanceId.of("id"))
                       .register(Registration.create("foo", wireMock.url("/health")).build());
    StepVerifier.create(repository.save(instance)).expectNextCount(1).verifyComplete();

    updater = new StatusUpdater(repository,
        InstanceWebClient.builder()
                         .connectTimeout(Duration.ofSeconds(2))
                         .readTimeout(Duration.ofSeconds(2))
                         .retries(singletonMap(Endpoint.HEALTH, 1))
                         .build()
    );
}
 
Example #2
Source File: AdminServerModule.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Construct the module with a pattern for registration metadata keys. The values of
 * the matched metadata keys will be sanitized before serializing to json.
 * @param metadataKeyPatterns pattern for metadata keys which should be sanitized
 */
public AdminServerModule(String[] metadataKeyPatterns) {
	super(AdminServerModule.class.getName());

	addDeserializer(Registration.class, new RegistrationDeserializer());
	setSerializerModifier(new RegistrationBeanSerializerModifier(new SanitizingMapSerializer(metadataKeyPatterns)));

	setMixInAnnotation(InstanceDeregisteredEvent.class, InstanceDeregisteredEventMixin.class);
	setMixInAnnotation(InstanceEndpointsDetectedEvent.class, InstanceEndpointsDetectedEventMixin.class);
	setMixInAnnotation(InstanceEvent.class, InstanceEventMixin.class);
	setMixInAnnotation(InstanceInfoChangedEvent.class, InstanceInfoChangedEventMixin.class);
	setMixInAnnotation(InstanceRegisteredEvent.class, InstanceRegisteredEventMixin.class);
	setMixInAnnotation(InstanceRegistrationUpdatedEvent.class, InstanceRegistrationUpdatedEventMixin.class);
	setMixInAnnotation(InstanceStatusChangedEvent.class, InstanceStatusChangedEventMixin.class);

	setMixInAnnotation(BuildVersion.class, BuildVersionMixin.class);
	setMixInAnnotation(Endpoint.class, EndpointMixin.class);
	setMixInAnnotation(Endpoints.class, EndpointsMixin.class);
	setMixInAnnotation(Info.class, InfoMixin.class);
	setMixInAnnotation(InstanceId.class, InstanceIdMixin.class);
	setMixInAnnotation(StatusInfo.class, StatusInfoMixin.class);
	setMixInAnnotation(Tags.class, TagsMixin.class);
}
 
Example #3
Source File: QueryIndexEndpointStrategy.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
protected Function<Endpoints, Endpoints> alignWithManagementUrl(InstanceId instanceId, String managementUrl) {
	return (endpoints) -> {
		if (!managementUrl.startsWith("https:")) {
			return endpoints;
		}
		if (endpoints.stream().noneMatch((e) -> e.getUrl().startsWith("http:"))) {
			return endpoints;
		}
		log.warn(
				"Endpoints for instance {} queried from {} are falsely using http. Rewritten to https. Consider configuring this instance to use 'server.forward-headers-strategy=native'.",
				instanceId, managementUrl);

		return Endpoints.of(
				endpoints.stream().map((e) -> Endpoint.of(e.getId(), e.getUrl().replaceFirst("http:", "https:")))
						.collect(Collectors.toList()));
	};
}
 
Example #4
Source File: ProbeEndpointsStrategy.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
protected Mono<Endpoints> convert(List<DetectedEndpoint> endpoints) {
	if (endpoints.isEmpty()) {
		return Mono.empty();
	}

	Map<String, List<DetectedEndpoint>> endpointsById = endpoints.stream()
			.collect(groupingBy((e) -> e.getDefinition().getId()));
	List<Endpoint> result = endpointsById.values().stream().map((endpointList) -> {
		endpointList.sort(comparingInt((e) -> this.endpoints.indexOf(e.getDefinition())));
		if (endpointList.size() > 1) {
			log.warn("Duplicate endpoints for id '{}' detected. Omitting: {}",
					endpointList.get(0).getDefinition().getId(), endpointList.subList(1, endpointList.size()));
		}
		return endpointList.get(0).getEndpoint();
	}).collect(Collectors.toList());
	return Mono.just(Endpoints.of(result));
}
 
Example #5
Source File: Instance.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
private Instance(InstanceId id, long version, @Nullable Registration registration, boolean registered,
		StatusInfo statusInfo, Instant statusTimestamp, Info info, Endpoints endpoints,
		@Nullable BuildVersion buildVersion, Tags tags, List<InstanceEvent> unsavedEvents) {
	Assert.notNull(id, "'id' must not be null");
	Assert.notNull(endpoints, "'endpoints' must not be null");
	Assert.notNull(info, "'info' must not be null");
	Assert.notNull(statusInfo, "'statusInfo' must not be null");
	this.id = id;
	this.version = version;
	this.registration = registration;
	this.registered = registered;
	this.statusInfo = statusInfo;
	this.statusTimestamp = statusTimestamp;
	this.info = info;
	this.endpoints = (registered && (registration != null))
			? endpoints.withEndpoint(Endpoint.HEALTH, registration.getHealthUrl()) : endpoints;
	this.unsavedEvents = unsavedEvents;
	this.buildVersion = buildVersion;
	this.tags = tags;
}
 
Example #6
Source File: InfoUpdater.java    From Moss with Apache License 2.0 6 votes vote down vote up
protected Mono<Instance> doUpdateInfo(Instance instance) {
    if (instance.getStatusInfo().isOffline() || instance.getStatusInfo().isUnknown()) {
        return Mono.empty();
    }
    if (!instance.getEndpoints().isPresent(Endpoint.INFO)) {
        return Mono.empty();
    }

    log.debug("Update info for {}", instance);
    return instanceWebClient.instance(instance)
                            .get()
                            .uri(Endpoint.INFO)
                            .exchange()
                            .log(log.getName(), Level.FINEST)
                            .flatMap(response -> convertInfo(instance, response))
                            .onErrorResume(ex -> Mono.just(convertInfo(instance, ex)))
                            .map(instance::withInfo);
}
 
Example #7
Source File: ProbeEndpointsStrategy.java    From Moss with Apache License 2.0 6 votes vote down vote up
private Mono<Endpoints> convert(List<DetectedEndpoint> endpoints) {
    if (endpoints.isEmpty()) {
        return Mono.empty();
    }

    Map<String, List<DetectedEndpoint>> endpointsById = endpoints.stream()
                                                                 .collect(groupingBy(e -> e.getDefinition()
                                                                                           .getId()));
    List<Endpoint> result = endpointsById.values().stream().map(endpointList -> {
        endpointList.sort(comparingInt(e -> this.endpoints.indexOf(e.getDefinition())));
        if (endpointList.size() > 1) {
            log.warn("Duplicate endpoints for id '{}' detected. Omitting: {}",
                endpointList.get(0).getDefinition().getId(),
                endpointList.subList(1, endpointList.size())
            );
        }
        return endpointList.get(0).getEndpoint();
    }).collect(Collectors.toList());
    return Mono.just(Endpoints.of(result));
}
 
Example #8
Source File: StatusUpdater.java    From Moss with Apache License 2.0 6 votes vote down vote up
protected Mono<Instance> doUpdateStatus(Instance instance) {
    if (!instance.isRegistered()) {
        return Mono.empty();
    }

    log.debug("Update status for {}", instance);
    return instanceWebClient.instance(instance)
                            .get()
                            .uri(Endpoint.HEALTH)
                            .exchange()
                            .log(log.getName(), Level.FINEST)
                            .flatMap(this::convertStatusInfo)
                            .doOnError(ex -> logError(instance, ex))
                            .onErrorResume(this::handleError)
                            .map(instance::withStatusInfo);
}
 
Example #9
Source File: InstanceEndpointsDetectedEventMixinTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
	String json = new JSONObject().put("instance", "test123").put("version", 12345678L)
			.put("timestamp", 1587751031.000000000).put("type", "ENDPOINTS_DETECTED")
			.put("endpoints",
					new JSONArray().put(new JSONObject().put("id", "info").put("url", "http://localhost:8080/info"))
							.put(new JSONObject().put("id", "health").put("url", "http://localhost:8080/health")))
			.toString();

	InstanceEndpointsDetectedEvent event = objectMapper.readValue(json, InstanceEndpointsDetectedEvent.class);
	assertThat(event).isNotNull();
	assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
	assertThat(event.getVersion()).isEqualTo(12345678L);
	assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
	assertThat(event.getEndpoints()).containsExactlyInAnyOrder(Endpoint.of("info", "http://localhost:8080/info"),
			Endpoint.of("health", "http://localhost:8080/health"));
}
 
Example #10
Source File: InstanceExchangeFilterFunctionsTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
void should_add_default_logfile_accept_headers() {
	ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
			.attribute(ATTRIBUTE_ENDPOINT, Endpoint.LOGFILE).build();

	Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (req) -> {
		assertThat(req.headers().getAccept()).containsExactly(MediaType.TEXT_PLAIN);
		return Mono.just(ClientResponse.create(HttpStatus.OK).build());
	});

	StepVerifier.create(response).expectNextCount(1).verifyComplete();
}
 
Example #11
Source File: StatusUpdaterTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
	this.wireMock.start();
	this.eventStore = new InMemoryEventStore();
	this.repository = new EventsourcingInstanceRepository(this.eventStore);
	this.instance = Instance.create(InstanceId.of("id"))
			.register(Registration.create("foo", this.wireMock.url("/health")).build());
	StepVerifier.create(this.repository.save(this.instance)).expectNextCount(1).verifyComplete();

	this.updater = new StatusUpdater(this.repository,
			InstanceWebClient.builder().filter(rewriteEndpointUrl())
					.filter(retry(0, singletonMap(Endpoint.HEALTH, 1)))
					.filter(timeout(Duration.ofSeconds(2), emptyMap())).build());
}
 
Example #12
Source File: StatusUpdater.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
protected Mono<Instance> doUpdateStatus(Instance instance) {
	if (!instance.isRegistered()) {
		return Mono.empty();
	}

	log.debug("Update status for {}", instance);
	return this.instanceWebClient.instance(instance).get().uri(Endpoint.HEALTH).exchange()
			.log(log.getName(), Level.FINEST).flatMap(this::convertStatusInfo)
			.doOnError((ex) -> logError(instance, ex)).onErrorResume(this::handleError)
			.map(instance::withStatusInfo);
}
 
Example #13
Source File: InfoUpdaterTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
	this.eventStore = new InMemoryEventStore();
	this.repository = new EventsourcingInstanceRepository(this.eventStore);
	this.updater = new InfoUpdater(this.repository,
			InstanceWebClient.builder().filter(rewriteEndpointUrl())
					.filter(retry(0, singletonMap(Endpoint.INFO, 1)))
					.filter(timeout(Duration.ofSeconds(2), emptyMap())).build());
	this.wireMock.start();
}
 
Example #14
Source File: InstanceExchangeFilterFunctions.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public static InstanceExchangeFilterFunction logfileAcceptWorkaround() {
	return (instance, request, next) -> {
		if (request.attribute(ATTRIBUTE_ENDPOINT).map(Endpoint.LOGFILE::equals).orElse(false)) {
			List<MediaType> newAcceptHeaders = Stream
					.concat(request.headers().getAccept().stream(), Stream.of(MediaType.ALL))
					.collect(Collectors.toList());
			request = ClientRequest.from(request).headers((h) -> h.setAccept(newAcceptHeaders)).build();
		}
		return next.exchange(request);
	};
}
 
Example #15
Source File: InstanceExchangeFilterFunctions.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public static InstanceExchangeFilterFunction setDefaultAcceptHeader() {
	return (instance, request, next) -> {
		if (request.headers().getAccept().isEmpty()) {
			Boolean isRequestForLogfile = request.attribute(ATTRIBUTE_ENDPOINT).map(Endpoint.LOGFILE::equals)
					.orElse(false);
			List<MediaType> acceptedHeaders = isRequestForLogfile ? DEFAULT_LOGFILE_ACCEPT_MEDIATYPES
					: DEFAULT_ACCEPT_MEDIATYPES;
			request = ClientRequest.from(request).headers((headers) -> headers.setAccept(acceptedHeaders)).build();
		}
		return next.exchange(request);
	};
}
 
Example #16
Source File: InstanceExchangeFilterFunctions.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public static InstanceExchangeFilterFunction rewriteEndpointUrl() {
	return (instance, request, next) -> {
		if (request.url().isAbsolute()) {
			log.trace("Absolute URL '{}' for instance {} not rewritten", request.url(), instance.getId());
			if (request.url().toString().equals(instance.getRegistration().getManagementUrl())) {
				request = ClientRequest.from(request).attribute(ATTRIBUTE_ENDPOINT, Endpoint.ACTUATOR_INDEX)
						.build();
			}
			return next.exchange(request);
		}

		UriComponents requestUrl = UriComponentsBuilder.fromUri(request.url()).build();
		if (requestUrl.getPathSegments().isEmpty()) {
			return Mono.error(new ResolveEndpointException("No endpoint specified"));
		}

		String endpointId = requestUrl.getPathSegments().get(0);
		Optional<Endpoint> endpoint = instance.getEndpoints().get(endpointId);

		if (!endpoint.isPresent()) {
			return Mono.error(new ResolveEndpointException("Endpoint '" + endpointId + "' not found"));
		}

		URI rewrittenUrl = rewriteUrl(requestUrl, endpoint.get().getUrl());
		log.trace("URL '{}' for Endpoint {} of instance {} rewritten to {}", requestUrl, endpoint.get().getId(),
				instance.getId(), rewrittenUrl);
		request = ClientRequest.from(request).attribute(ATTRIBUTE_ENDPOINT, endpoint.get().getId())
				.url(rewrittenUrl).build();
		return next.exchange(request);
	};
}
 
Example #17
Source File: EndpointsMixinTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
	String json = new JSONArray().put(new JSONObject().put("id", "info").put("url", "http://localhost:8080/info"))
			.put(new JSONObject().put("id", "health").put("url", "http://localhost:8080/health")).toString();

	Endpoints endpoints = objectMapper.readValue(json, Endpoints.class);
	assertThat(endpoints).isNotNull();
	assertThat(endpoints).containsExactlyInAnyOrder(Endpoint.of("info", "http://localhost:8080/info"),
			Endpoint.of("health", "http://localhost:8080/health"));
}
 
Example #18
Source File: InfoUpdater.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
protected Mono<Instance> doUpdateInfo(Instance instance) {
	if (instance.getStatusInfo().isOffline() || instance.getStatusInfo().isUnknown()) {
		return Mono.empty();
	}
	if (!instance.getEndpoints().isPresent(Endpoint.INFO)) {
		return Mono.empty();
	}

	log.debug("Update info for {}", instance);
	return this.instanceWebClient.instance(instance).get().uri(Endpoint.INFO).exchange()
			.log(log.getName(), Level.FINEST).flatMap((response) -> convertInfo(instance, response))
			.onErrorResume((ex) -> Mono.just(convertInfo(instance, ex))).map(instance::withInfo);
}
 
Example #19
Source File: Instance.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public Instance withEndpoints(Endpoints endpoints) {
	Assert.notNull(endpoints, "'endpoints' must not be null");
	Endpoints endpointsWithHealth = (this.registration != null)
			? endpoints.withEndpoint(Endpoint.HEALTH, this.registration.getHealthUrl()) : endpoints;
	if (Objects.equals(this.endpoints, endpointsWithHealth)) {
		return this;
	}
	return this.apply(new InstanceEndpointsDetectedEvent(this.id, this.nextVersion(), endpoints), true);
}
 
Example #20
Source File: InstanceExchangeFilterFunctions.java    From Moss with Apache License 2.0 5 votes vote down vote up
public static ExchangeFilterFunction setDefaultAcceptHeader() {
    return (request, next) -> {
        if (request.headers().getAccept().isEmpty()) {
            Boolean isRequestForLogfile = request.attribute(ATTRIBUTE_ENDPOINT)
                                                 .map(Endpoint.LOGFILE::equals)
                                                 .orElse(false);
            List<MediaType> acceptedHeaders = isRequestForLogfile ? DEFAULT_LOGFILE_ACCEPT_MEDIATYPES : DEFAULT_ACCEPT_MEDIATYPES;
            return next.exchange(ClientRequest.from(request)
                                              .headers(headers -> headers.setAccept(acceptedHeaders))
                                              .build());
        }
        return next.exchange(request);
    };
}
 
Example #21
Source File: InstanceExchangeFilterFunctionsTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
void should_rewirte_url_and_add_endpoint_attribute() {
	ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("health/database"))
			.attribute(ATTRIBUTE_INSTANCE, this.instance).build();

	Mono<ClientResponse> response = this.filter.filter(this.instance, request, (req) -> {
		assertThat(req.url()).isEqualTo(URI.create(this.registration.getHealthUrl() + "/database"));
		assertThat(req.attribute(ATTRIBUTE_ENDPOINT)).hasValue(Endpoint.HEALTH);
		return Mono.just(ClientResponse.create(HttpStatus.OK).build());
	});

	StepVerifier.create(response).expectNextCount(1).verifyComplete();
}
 
Example #22
Source File: InstanceExchangeFilterFunctionsTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
void should_set_endpoint_attribute_for_management_url() {
	ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("http://test/actuator"))
			.attribute(ATTRIBUTE_INSTANCE, this.instance).build();

	Mono<ClientResponse> response = this.filter.filter(this.instance, request, (req) -> {
		assertThat(req.attribute(ATTRIBUTE_ENDPOINT)).hasValue(Endpoint.ACTUATOR_INDEX);
		return Mono.just(ClientResponse.create(HttpStatus.OK).build());
	});

	StepVerifier.create(response).expectNextCount(1).verifyComplete();
}
 
Example #23
Source File: InstanceExchangeFilterFunctionsTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
void should_add_accept_all_to_headers_for_logfile() {
	ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
			.attribute(ATTRIBUTE_ENDPOINT, Endpoint.LOGFILE).header(ACCEPT, TEXT_PLAIN_VALUE).build();

	Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (req) -> {
		assertThat(req.headers().getAccept()).containsExactly(MediaType.TEXT_PLAIN, MediaType.ALL);
		return Mono.just(ClientResponse.create(HttpStatus.OK).build());
	});

	StepVerifier.create(response).expectNextCount(1).verifyComplete();
}
 
Example #24
Source File: InfoUpdaterTest.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    eventStore = new InMemoryEventStore();
    repository = new EventsourcingInstanceRepository(eventStore);
    updater = new InfoUpdater(repository,
        InstanceWebClient.builder()
                         .retries(singletonMap(Endpoint.INFO, 1))
                         .connectTimeout(Duration.ofSeconds(2))
                         .readTimeout(Duration.ofSeconds(2))
                         .build()
    );
}
 
Example #25
Source File: Instance.java    From Moss with Apache License 2.0 5 votes vote down vote up
public Instance withEndpoints(Endpoints endpoints) {
    Assert.notNull(endpoints, "'endpoints' must not be null");
    Endpoints endpointsWithHealth = this.registration != null ? endpoints.withEndpoint(
        Endpoint.HEALTH,
        this.registration.getHealthUrl()
    ) : endpoints;
    if (Objects.equals(this.endpoints, endpointsWithHealth)) {
        return this;
    }
    return this.apply(new InstanceEndpointsDetectedEvent(this.id, this.nextVersion(), endpoints), true);
}
 
Example #26
Source File: Instance.java    From Moss with Apache License 2.0 5 votes vote down vote up
private Instance(InstanceId id,
                 long version,
                 @Nullable Registration registration,
                 boolean registered,
                 StatusInfo statusInfo,
                 Instant statusTimestamp,
                 Info info,
                 Endpoints endpoints,
                 @Nullable BuildVersion buildVersion,
                 Tags tags,
                 List<InstanceEvent> unsavedEvents) {
    Assert.notNull(id, "'id' must not be null");
    Assert.notNull(endpoints, "'endpoints' must not be null");
    Assert.notNull(info, "'info' must not be null");
    Assert.notNull(statusInfo, "'statusInfo' must not be null");
    this.id = id;
    this.version = version;
    this.registration = registration;
    this.registered = registered;
    this.statusInfo = statusInfo;
    this.statusTimestamp = statusTimestamp;
    this.info = info;
    this.endpoints = registered && registration != null ? endpoints.withEndpoint(Endpoint.HEALTH,
        registration.getHealthUrl()
    ) : endpoints;
    this.unsavedEvents = unsavedEvents;
    this.buildVersion = buildVersion;
    this.tags = tags;
}
 
Example #27
Source File: EndpointMixinTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void verifySerialize() throws IOException {
	Endpoint endpoint = Endpoint.of("info", "http://localhost:8080/info");

	JsonContent<Endpoint> jsonContent = jsonTester.write(endpoint);
	assertThat(jsonContent).extractingJsonPathStringValue("$.id").isEqualTo("info");
	assertThat(jsonContent).extractingJsonPathStringValue("$.url").isEqualTo("http://localhost:8080/info");
}
 
Example #28
Source File: InstanceExchangeFilterFunctionsTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
void should_not_add_accept_all_to_headers_for_non_logfile() {
	ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
			.attribute(ATTRIBUTE_ENDPOINT, Endpoint.HTTPTRACE).header(ACCEPT, APPLICATION_JSON_VALUE).build();

	Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (req) -> {
		assertThat(req.headers().getAccept()).containsExactly(MediaType.APPLICATION_JSON);
		return Mono.just(ClientResponse.create(HttpStatus.OK).build());
	});

	StepVerifier.create(response).expectNextCount(1).verifyComplete();
}
 
Example #29
Source File: EndpointMixinTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
	String json = new JSONObject().put("id", "info").put("url", "http://localhost:8080/info").toString();

	Endpoint endpoint = objectMapper.readValue(json, Endpoint.class);
	assertThat(endpoint).isNotNull();
	assertThat(endpoint.getId()).isEqualTo("info");
	assertThat(endpoint.getUrl()).isEqualTo("http://localhost:8080/info");
}
 
Example #30
Source File: QueryIndexEndpointStrategy.java    From Moss with Apache License 2.0 5 votes vote down vote up
private Mono<Endpoints> convert(Response response) {
    List<Endpoint> endpoints = response.getLinks()
                                       .entrySet()
                                       .stream()
                                       .filter(e -> !e.getKey().equals("self") && !e.getValue().isTemplated())
                                       .map(e -> Endpoint.of(e.getKey(), e.getValue().getHref()))
                                       .collect(Collectors.toList());
    if (endpoints.isEmpty()) {
        return Mono.empty();
    } else {
        return Mono.just(Endpoints.of(endpoints));
    }
}