@Bean(name = "metadataJcrRepository") public Repository metadataJcrRepository(@Qualifier("springApplicationContext")SpringApplicationContext springApplicationContext) throws Exception { JcrRepository repo = modeShapeEngine(springApplicationContext).deploy(metadataRepoConfig()); try { Problems problems = repo.getStartupProblems(); if (problems.hasErrors()) { log.error("Problems starting the metadata ModeShape repository: {} \n{}", repo.getName(), problems); throw new RuntimeException("Problems starting the ModeShape metadata repository: " + problems); } } catch (NullPointerException e) { // This gets thrown sometimes when attempting to retrieve the startup problems. It looks // like it is probably a ModeShape bug that can happen even when the repo starts successfully. // Just log a warning about it and proceed as if everything is fine. log.warn("Retrieved a NullPointerException when attempting to check for startup errors - this is likely a ModeShape bug and can usually be ignored"); } return repo; } }
/** * Generate a JCR repository from the given configuration * */ @PostConstruct public void buildRepository() { try { LOGGER.info("Using repo config (classpath): {}", repositoryConfiguration.getURL()); getPropertiesLoader().loadSystemProperties(); final RepositoryConfiguration config = RepositoryConfiguration.read(repositoryConfiguration.getURL()); repository = modeShapeEngine.deploy(config); // next line ensures that repository starts before the factory is used. final org.modeshape.common.collection.Problems problems = repository.getStartupProblems(); for (final org.modeshape.common.collection.Problem p : problems) { LOGGER.error("ModeShape Start Problem: {}", p.getMessageString()); // TODO determine problems that should be runtime errors } } catch (final Exception e) { throw new RepositoryRuntimeException(e); } }
@FixFor( "MODE-2033" ) @Test public void shouldStartAndReturnStartupProblems() throws Exception { shutdownDefaultRepository(); repository = TestingUtil.startRepositoryWithConfig("config/repo-config-with-startup-problems.json"); Problems problems = repository.getStartupProblems(); assertEquals("Expected 2 startup errors: " + problems.toString(), 2, problems.errorCount()); repository.shutdown().get(); problems = repository.getStartupProblems(); assertEquals("Invalid startup problems:" + problems.toString(), 2, problems.size()); }