@Override protected void registerSubjectInBackend(final String subjectName, final SubjectConfig config) { final File subjectDir = new File(rootDir, subjectName); if (subjectDir.exists()) { throw new RuntimeException( "Cannot create a FileSubject, directory already exists: " + subjectDir.getAbsolutePath()); } if (!subjectDir.mkdir()) { throw new RuntimeException("Cannot create a FileSubject dir: " + subjectDir.getAbsolutePath()); } createNewFileInDir(subjectDir, SCHEMA_IDS); File subjectProperties = createNewFileInDir(subjectDir, SUBJECT_PROPERTIES); Properties props = new Properties(); props.putAll(RepositoryUtil.safeConfig(config).asMap()); writePropertyFile(subjectProperties, props); }
@GET @Path("{subject}/config") public String subjectConfig(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Properties props = new Properties(); props.putAll(s.getConfig().asMap()); return getRenderer(mediaType).renderProperties(props, "Configuration of subject " + subject); }
@Override protected void registerSubjectInBackend(final String subjectName, final SubjectConfig config) { final File subjectDir = new File(rootDir, subjectName); if (subjectDir.exists()) { throw new RuntimeException( "Cannot create a FileSubject, directory already exists: " + subjectDir.getAbsolutePath()); } if (!subjectDir.mkdir()) { throw new RuntimeException("Cannot create a FileSubject dir: " + subjectDir.getAbsolutePath()); } createNewFileInDir(subjectDir, SCHEMA_IDS); File subjectProperties = createNewFileInDir(subjectDir, SUBJECT_PROPERTIES); Properties props = new Properties(); props.putAll(RepositoryUtil.safeConfig(config).asMap()); writePropertyFile(subjectProperties, props); }
@GET @Path("{subject}/config") public String subjectConfig(@HeaderParam("Accept") String mediaType, @PathParam("subject") String subject) { Subject s = repo.lookup(subject); if (null == s) { throw new NotFoundException(MessageStrings.SUBJECT_DOES_NOT_EXIST_ERROR); } Properties props = new Properties(); props.putAll(s.getConfig().asMap()); return getRenderer(mediaType).renderProperties(props, "Configuration of subject " + subject); }
@Override protected void registerSubjectInBackend(final String subjectName, final SubjectConfig config) { // If the Subject is not in the local cache, we acquire the lock to create it acquireLock(); try { zkClient.create().forPath(subjectName); // N.B.: There is a possibility that the Subject was already created by // another repository instance. If the create operation above didn't throw, // then we need to initialize the Subject. // Create schema IDs file zkClient.create().forPath(subjectName + "/" + SCHEMA_IDS); // Create properties file Properties props = new Properties(); props.putAll(RepositoryUtil.safeConfig(config).asMap()); StringWriter sw = new StringWriter(); props.store(sw, "Schema Repository Subject Properties"); byte[] content = sw.toString().getBytes(); zkClient.create().forPath(subjectName + "/" + SUBJECT_PROPERTIES, content); } catch (KeeperException.NodeExistsException e) { // The Subject was already created by another repository instance, we will // just fetch it, below, instead of creating a new one. } catch (Exception e) { logger.error("An exception occurred while accessing ZK!", e); throw new RuntimeException(e); } finally { releaseLock(); } }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Override public Subject register(String subject, SubjectConfig config) { Form form = new Form(); for(Map.Entry<String, String> entry : RepositoryUtil.safeConfig(config).asMap().entrySet()) { form.putSingle(entry.getKey(), entry.getValue()); } String regSubjectName = webResource.path(subject).type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form); return new RESTSubject(regSubjectName); }
@Test public void testBuilderHashAndEquals() { SubjectConfig empty = SubjectConfig.emptyConfig(); Assert.assertEquals(empty, empty); SubjectConfig conf = new SubjectConfig.Builder().build(); Assert.assertEquals(empty, conf); SubjectConfig conf2 = new SubjectConfig.Builder() .set("repo.validators", null) .build(); // Explicitly setting empty or null validators is NOT the same as no validators // due to the default subject validators functionality (see Issue 38) Assert.assertNotEquals(conf, conf2); Assert.assertNotEquals(conf2, empty); Assert.assertNotEquals(conf.hashCode(), conf2.hashCode()); Assert.assertFalse(conf.equals(null)); Assert.assertFalse(conf.equals(new Object())); Assert.assertEquals(conf.hashCode(), empty.hashCode()); String k = "key"; String v = "val"; SubjectConfig custom = new SubjectConfig.Builder() .set(k, v).build(); SubjectConfig custom2 = new SubjectConfig.Builder() .set(custom.asMap()).build(); SubjectConfig custom3 = new SubjectConfig.Builder() .set(custom.asMap()).addValidator("foo").build(); Assert.assertEquals(custom, custom2); Assert.assertFalse(custom.equals(custom3)); Assert.assertFalse(custom.equals(conf)); Assert.assertEquals(custom.hashCode(), custom2.hashCode()); }