private void checkSchemaText(String schemaText) throws InvalidSchemaException { if(schemaText == null || schemaText.trim().isEmpty()) { throw new InvalidSchemaException(); } }
@Override public byte[] getFingerprint(String schemaText) throws InvalidSchemaException { try { return MessageDigest.getInstance(MD5).digest(schemaText.getBytes(UTF_8)); } catch (Exception e) { throw new InvalidSchemaException(e); } }
@Override public byte[] getFingerprint(String schemaText) throws InvalidSchemaException, SchemaNotFoundException { try { // generates fingerprint of canonical form of the given schema. Schema schema = new Schema.Parser().parse(getResultantSchema(schemaText)); return MessageDigest.getInstance("MD5").digest(normalize(schema).getBytes()); } catch (IOException e) { throw new InvalidSchemaException("Given schema is invalid", e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
@Override public byte[] getFingerprint(String schemaText) throws InvalidSchemaException, SchemaNotFoundException { try { // generates fingerprint of canonical form of the given schema. Schema schema = new Schema.Parser().parse(getResultantSchema(schemaText)); return MessageDigest.getInstance("MD5").digest(normalize(schema).getBytes()); } catch (IOException e) { throw new InvalidSchemaException("Given schema is invalid", e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
private List<SchemaVersionKey> getIncludedSchemaVersions(String schemaText) throws InvalidSchemaException { JsonNode jsonNode = null; try { jsonNode = new ObjectMapper().readTree(schemaText); } catch (IOException e) { throw new InvalidSchemaException(e); } JsonNode includeSchemaNodes = jsonNode.get("includeSchemas"); List<SchemaVersionKey> includedSchemaVersions = new ArrayList<>(); if (includeSchemaNodes != null) { if (!includeSchemaNodes.isArray()) { throw new InvalidSchemaException("includeSchemas should be an array of strings"); } for (JsonNode includeSchema : includeSchemaNodes) { String name = includeSchema.get("name").asText(); JsonNode versionNode = includeSchema.get("version"); int version = versionNode != null ? versionNode.asInt() : SchemaVersionKey.LATEST_VERSION; includedSchemaVersions.add(new SchemaVersionKey(name, version)); } } return includedSchemaVersions; } }
private List<SchemaVersionKey> getIncludedSchemaVersions(String schemaText) throws InvalidSchemaException { JsonNode jsonNode = null; try { jsonNode = new ObjectMapper().readTree(schemaText); } catch (IOException e) { throw new InvalidSchemaException(e); } JsonNode includeSchemaNodes = jsonNode.get("includeSchemas"); List<SchemaVersionKey> includedSchemaVersions = new ArrayList<>(); if (includeSchemaNodes != null) { if (!includeSchemaNodes.isArray()) { throw new InvalidSchemaException("includeSchemas should be an array of strings"); } for (JsonNode includeSchema : includeSchemaNodes) { String name = includeSchema.get("name").asText(); JsonNode versionNode = includeSchema.get("version"); int version = versionNode != null ? versionNode.asInt() : SchemaVersionKey.LATEST_VERSION; includedSchemaVersions.add(new SchemaVersionKey(name, version)); } } return includedSchemaVersions; } }
private SchemaIdVersion handleSchemaIdVersionResponse(SchemaMetadataInfo schemaMetadataInfo, Response response) throws IncompatibleSchemaException, InvalidSchemaException { int status = response.getStatus(); String msg = response.readEntity(String.class); if (status == Response.Status.BAD_REQUEST.getStatusCode() || status == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) { CatalogResponse catalogResponse = readCatalogResponse(msg); if (CatalogResponse.ResponseMessage.INCOMPATIBLE_SCHEMA.getCode() == catalogResponse.getResponseCode()) { throw new IncompatibleSchemaException(catalogResponse.getResponseMessage()); } else if (CatalogResponse.ResponseMessage.INVALID_SCHEMA.getCode() == catalogResponse.getResponseCode()) { throw new InvalidSchemaException(catalogResponse.getResponseMessage()); } else { throw new RuntimeException(catalogResponse.getResponseMessage()); } } Integer version = readEntity(msg, Integer.class); SchemaVersionInfo schemaVersionInfo = doGetSchemaVersionInfo(new SchemaVersionKey(schemaMetadataInfo.getSchemaMetadata() .getName(), version)); return new SchemaIdVersion(schemaMetadataInfo.getId(), version, schemaVersionInfo.getId()); }