@Override
  public Schema getLatestSchema(String topic) throws SchemaRegistryException {
    String schemaUrl = this.url + GET_RESOURCE_BY_TYPE + topic;

    LOG.debug("Fetching from URL : " + schemaUrl);

    GetMethod get = new GetMethod(schemaUrl);

    int statusCode;
    String schemaString;
    HttpClient httpClient = this.borrowClient();
    try {
      statusCode = httpClient.executeMethod(get);
      schemaString = get.getResponseBodyAsString();
    } catch (HttpException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      get.releaseConnection();
      this.httpClientPool.returnObject(httpClient);
    }

    if (statusCode != HttpStatus.SC_OK) {
      throw new SchemaRegistryException(
          String.format("Latest schema for topic %s cannot be retrieved. Status code = %d", topic, statusCode));
    }

    Schema schema;
    try {
      schema = new Schema.Parser().parse(schemaString);
    } catch (Throwable t) {
      throw new SchemaRegistryException(String.format("Latest schema for topic %s cannot be retrieved", topic), t);
    }

    return schema;
  }
@ Override public Schema getLatestSchema ( String topic ) throws SchemaRegistryException { String schemaUrl = this . url + GET_RESOURCE_BY_TYPE + topic ; LOG . debug ( "Fetching from URL : " + schemaUrl ) ; GetMethod get = new GetMethod ( schemaUrl ) ; int statusCode ; String schemaString ; HttpClient httpClient = this . borrowClient ( ) ; try { statusCode = httpClient . executeMethod ( get ) ; schemaString = get . getResponseBodyAsString ( ) ; } catch ( HttpException e ) { throw new RuntimeException ( e ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } finally { get . releaseConnection ( ) ; this . httpClientPool . returnObject ( httpClient ) ; } if ( statusCode != HttpStatus . SC_OK ) { throw new SchemaRegistryException ( String . format ( "Latest schema for topic %s cannot be retrieved. Status code = %d" , topic , statusCode ) ) ; } Schema schema ; try { schema = new Schema . Parser ( ) . parse ( schemaString ) ; } catch ( Throwable t ) { throw new SchemaRegistryException ( String . format ( "Latest schema for topic %s cannot be retrieved" , topic ) , t ) ; } return schema ; }
Get the latest schema of a topic.

@param topic topic name
@return the latest schema
@throws SchemaRegistryException if failed to retrieve schema.