Skip to content

Commit

Permalink
Add ETag info to CatalogService example
Browse files Browse the repository at this point in the history
  • Loading branch information
royclarkson committed Feb 1, 2023
1 parent d30f1e2 commit 2bb3198
Showing 1 changed file with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.cloud.servicebroker.model.catalog.Plan;
import org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition;
import org.springframework.cloud.servicebroker.service.CatalogService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -22,21 +24,41 @@ public Mono<Catalog> getCatalog() {
@Override
public Mono<ServiceDefinition> getServiceDefinition(String serviceId) {
return Mono.just(ServiceDefinition.builder()
.id(serviceId)
.name("example")
.description("A simple example")
.bindable(true)
.tags("example", "tags")
.plans(getPlan())
.build());
.id(serviceId)
.name("example")
.description("A simple example")
.bindable(true)
.tags("example", "tags")
.plans(getPlan())
.build());
}

@Override
public Mono<ResponseEntity<Catalog>> getResponseEntityCatalog(HttpHeaders httpHeaders) {
// Use this method to handle catalog caching and ETag support.
// The example below is a basic ETag comparison and response.
if ("useful-etag-value".equals(httpHeaders.getIfNoneMatch())) {
return Mono.just(ResponseEntity
.status(304)
.eTag("useful-etag-value")
.build());
}
else {
return getCatalog()
.map(catalog -> ResponseEntity
.status(200)
.eTag("different-etag-value")
.body(catalog));
}
}

private Plan getPlan() {
return Plan.builder()
.id("simple-plan")
.name("standard")
.description("A simple plan")
.free(true)
.build();
.id("simple-plan")
.name("standard")
.description("A simple plan")
.free(true)
.build();
}

}

0 comments on commit 2bb3198

Please sign in to comment.