@GET @Path("/subjects/{subject}/versions") @ApiOperation(value = "Get all schema versions of given subject", response = Integer.class, responseContainer = "List", tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response getAllVersions(@ApiParam(value = "subject", required = true) @PathParam("subject") String subject) { Response response; try { List<Integer> registeredSubjects = schemaRegistry.getAllVersions(subject) .stream() .map(SchemaVersionInfo::getVersion) .collect(Collectors.toList()); response = WSUtils.respondEntity(registeredSubjects, Response.Status.OK); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving all subjects", ex); response = serverError(); } return response; }
@GET @Path("/subjects/{subject}/versions") @ApiOperation(value = "Get all schema versions of given subject", response = Integer.class, responseContainer = "List", tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response getAllVersions(@ApiParam(value = "subject", required = true) @PathParam("subject") String subject) { Response response; try { List<Integer> registeredSubjects = schemaRegistry.getAllVersions(subject) .stream() .map(SchemaVersionInfo::getVersion) .collect(Collectors.toList()); response = WSUtils.respondEntity(registeredSubjects, Response.Status.OK); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving all subjects", ex); response = serverError(); } return response; }
@Test public void testNonExistingSubject() throws Exception { // check non existing subject Response nonExistingSubjectResponse = rootTarget.path("/subjects/" + testName() + "/versions") .request(MediaType.APPLICATION_JSON_TYPE) .get(); ErrorMessage errorMessage = new ObjectMapper().readValue(nonExistingSubjectResponse.readEntity(String.class), ErrorMessage.class); Assert.assertEquals(subjectNotFoundError().getStatus(), nonExistingSubjectResponse.getStatus()); Assert.assertEquals(subjectNotFoundError().getEntity(), errorMessage); }
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
@POST @Path("/subjects/{subject}") @ApiOperation(value = "Get schema information for the given schema subject and schema text", response = Schema.class, tags = OPERATION_GROUP_CONFLUENT_SR) @Timed @UnitOfWork public Response lookupSubjectVersion(@ApiParam(value = "Schema subject", required = true) @PathParam("subject") String subject, @ApiParam(value = "The schema ", required = true) String schema) { Response response; try { SchemaVersionInfo schemaVersionInfo = schemaRegistry.getSchemaVersionInfo(subject, schemaStringFromJson(schema).getSchema()); if (schemaVersionInfo != null) { response = WSUtils.respondEntity(new Schema(schemaVersionInfo.getName(), schemaVersionInfo.getVersion(), schemaVersionInfo.getId(), schemaVersionInfo.getSchemaText()), Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, subject); } } catch (InvalidSchemaException ex) { LOG.error("Given schema is invalid", ex); response = invalidSchemaError(); } catch (SchemaNotFoundException ex) { LOG.error("No schema found with subject [{}]", subject, ex); response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving schema version with subject: [{}]", subject, ex); response = serverError(); } return response; }
response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving all subjects", ex);
response = subjectNotFoundError(); } catch (Exception ex) { LOG.error("Encountered error while retrieving all subjects", ex);
.request(MediaType.APPLICATION_JSON_TYPE) .get(); Assert.assertEquals(subjectNotFoundError().getEntity(), objectMapper.readValue(invalidSubjectResponse.readEntity(String.class), ErrorMessage.class));