@Test public void testAddWorkspaceLocalService() throws Exception { File dataDirRoot = getTestData().getDataDirectoryRoot(); WorkspaceInfo ws = getCatalog().getDefaultWorkspace(); ServiceInfo s = geoServer.getFactory().createService(); s.setName("foo"); s.setWorkspace(ws); File f = new File(dataDirRoot, "workspaces" + "/" + ws.getName() + "/service.xml"); assertFalse(f.exists()); geoServer.add(s); assertTrue(f.exists()); }
void loadServices(File directory, List<XStreamServiceLoader> loaders, GeoServer geoServer) { for (XStreamServiceLoader<ServiceInfo> l : loaders) { try { ServiceInfo s = l.load(geoServer, directory); if (directory != null && s.getWorkspace() == null) continue; geoServer.add(s); LOGGER.info( "Loaded service '" + s.getId() + "', " + (s.isEnabled() ? "enabled" : "disabled")); } catch (Throwable t) { LOGGER.log( Level.SEVERE, "Failed to load the service configuration in directory: " + directory.getPath(), t); } } }
protected void readConfiguration(GeoServer geoServer, XStreamPersister xp) throws Exception { // look for services.xml, if it exists assume we are dealing with // an old data directory File f = resourceLoader.find("services.xml"); if (f == null) { // assume 2.x style f = resourceLoader.find("global.xml"); if (f != null) { GeoServerInfo global = depersist(xp, f, GeoServerInfo.class); geoServer.setGlobal(global); } // load logging f = resourceLoader.find("logging.xml"); if (f != null) { LoggingInfo logging = depersist(xp, f, LoggingInfo.class); geoServer.setLogging(logging); } // load workspace specific settings File workspaces = resourceLoader.find("workspaces"); if (workspaces != null) { for (File dir : workspaces.listFiles()) { if (!dir.isDirectory() && !dir.isHidden()) continue; f = resourceLoader.find(dir, "settings.xml"); if (f != null) { SettingsInfo settings = depersist(xp, f, SettingsInfo.class); geoServer.add(settings); } } } // load services final List<XStreamServiceLoader> loaders = GeoServerExtensions.extensions(XStreamServiceLoader.class); loadServices(null, loaders, geoServer); // load services specific to workspace if (workspaces != null) { for (File dir : workspaces.listFiles()) { if (!dir.isDirectory() && !dir.isHidden()) continue; loadServices(dir, loaders, geoServer); } } } else { // add listener now as a converter which will convert from the old style // data directory to the new GeoServerPersister p = new GeoServerPersister(resourceLoader, xp); geoServer.addListener(p); // import old style services.xml new LegacyConfigurationImporter(geoServer).imprt(resourceLoader.getBaseDirectory()); geoServer.removeListener(p); // rename the services.xml file f.renameTo(new File(f.getParentFile(), "services.xml.old")); } }