Search in sources :

Example 1 with SchemaNotFoundException

use of org.springframework.cloud.stream.schema.SchemaNotFoundException in project spring-cloud-stream by spring-cloud.

the class ConfluentSchemaRegistryClient method fetch.

@Override
public String fetch(SchemaReference schemaReference) {
    String path = String.format("/subjects/%s/versions/%d", schemaReference.getSubject(), schemaReference.getVersion());
    HttpHeaders headers = new HttpHeaders();
    headers.put("Accept", ACCEPT_HEADERS);
    headers.add("Content-Type", "application/vnd.schemaregistry.v1+json");
    HttpEntity<String> request = new HttpEntity<>("", headers);
    try {
        ResponseEntity<Map> response = this.template.exchange(this.endpoint + path, HttpMethod.GET, request, Map.class);
        return (String) response.getBody().get("schema");
    } catch (HttpStatusCodeException e) {
        if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new SchemaNotFoundException(String.format("Could not find schema for reference: %s", schemaReference));
        } else {
            throw e;
        }
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) SchemaNotFoundException(org.springframework.cloud.stream.schema.SchemaNotFoundException) Map(java.util.Map)

Example 2 with SchemaNotFoundException

use of org.springframework.cloud.stream.schema.SchemaNotFoundException in project spring-cloud-stream by spring-cloud.

the class ConfluentSchemaRegistryClient method fetch.

@Override
public String fetch(int id) {
    String path = String.format("/schemas/ids/%d", id);
    HttpHeaders headers = new HttpHeaders();
    headers.put("Accept", ACCEPT_HEADERS);
    headers.add("Content-Type", "application/vnd.schemaregistry.v1+json");
    HttpEntity<String> request = new HttpEntity<>("", headers);
    try {
        ResponseEntity<Map> response = this.template.exchange(this.endpoint + path, HttpMethod.GET, request, Map.class);
        return (String) response.getBody().get("schema");
    } catch (HttpStatusCodeException e) {
        if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new SchemaNotFoundException(String.format("Could not find schema with id: %s", id));
        } else {
            throw e;
        }
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) SchemaNotFoundException(org.springframework.cloud.stream.schema.SchemaNotFoundException) Map(java.util.Map)

Aggregations

Map (java.util.Map)2 SchemaNotFoundException (org.springframework.cloud.stream.schema.SchemaNotFoundException)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)2