/** * Adds a service configuration to the test setup. If the service object already exists it is * simply reverted to its original state. * * @param serviceClass The class of the service * @param workspace The optional workspace for the service, may be <code>null</code> * @param geoServer The GeoServer configuration object. */ public <T extends ServiceInfo> void addService( Class<T> serviceClass, String workspace, GeoServer geoServer) { Catalog catalog = geoServer.getCatalog(); List<XStreamServiceLoader> loaders = GeoServerExtensions.extensions(XStreamServiceLoader.class); for (XStreamServiceLoader loader : loaders) { if (serviceClass.equals(loader.getServiceClass())) { // create a new one T created = (T) loader.create(geoServer); // grab the old one, if it exists T old = null; WorkspaceInfo ws = null; if (workspace != null) { ws = catalog.getWorkspaceByName(workspace); old = geoServer.getService(ws, serviceClass); } else { old = geoServer.getService(serviceClass); } if (old != null) { // update the old copy OwsUtils.copy(created, old, serviceClass); geoServer.save(old); } else { // add the new one created.setWorkspace(ws); geoServer.add(created); } break; } } }
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); } } }