public Map<String, Serializable> getConnectionParameters() { return delegate.getConnectionParameters(); }
GeoServerExtensions.bean(GeoServerEnvironment.class); if (source.getConnectionParameters() != null && !source.getConnectionParameters().isEmpty()) { target.getConnectionParameters().clear(); target.getConnectionParameters().putAll(source.getConnectionParameters()); } else { if (source != null && source.getConnectionParameters() != null) { for (Entry<String, Serializable> param : source.getConnectionParameters().entrySet()) { String key = param.getKey(); Object value = param.getValue(); target.getConnectionParameters().put(key, (Serializable) value);
/** Takes care of keeping the stores namespace URI in synch with namespace changes */ public void handlePostModifyEvent(CatalogPostModifyEvent event) { if (event.getSource() instanceof NamespaceInfo) { NamespaceInfo ns = (NamespaceInfo) event.getSource(); String namespaceURI = ns.getURI(); WorkspaceInfo ws = catalog.getWorkspaceByName(ns.getPrefix()); if (ws != null) { List<DataStoreInfo> stores = catalog.getDataStoresByWorkspace(ws); if (stores.size() > 0) { for (DataStoreInfo store : stores) { String oldURI = (String) store.getConnectionParameters().get("namespace"); if (oldURI != null && !namespaceURI.equals(oldURI)) { store.getConnectionParameters().put("namespace", namespaceURI); catalog.save(store); } } } } } // synchronize isolation if needed syncIsolation(event.getSource()); }
Serializable value = (Serializable) entry.getValue(); dataStore.getConnectionParameters().put(key, value); dataStore.getConnectionParameters().put("namespace", ns.getURI());
/** * Returns the datastore factory used to create underlying resources for a datastore. * * <p>This method first uses {@link DataStoreInfo#getType()} to obtain the datastore. In the * event of a failure it falls back on {@link DataStoreInfo#getConnectionParameters()}. * * @param info The data store metadata. * @return The datastore factory, or null if no such factory could be found, or the factory is * not available. * @throws IOException Any I/O errors. */ public DataAccessFactory getDataStoreFactory(DataStoreInfo info) throws IOException { DataAccessFactory factory = null; DataStoreInfo expandedStore = clone(info, true); if (info.getType() != null) { factory = DataStoreUtils.aquireFactory(expandedStore.getType()); } if (factory == null && expandedStore.getConnectionParameters() != null) { Map<String, Serializable> params = getParams(expandedStore.getConnectionParameters(), catalog.getResourceLoader()); factory = DataStoreUtils.aquireFactory(params); } return factory; }
@Test public void testModifyDataStore() throws Exception { testAddDataStore(); DataStoreInfo ds = catalog.getDataStoreByName("acme", "foostore"); assertTrue(ds.getConnectionParameters().isEmpty()); ds.getConnectionParameters().put("foo", "bar"); catalog.save(ds); File f = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/datastore.xml"); Document dom = dom(f); assertXpathExists("/dataStore/connectionParameters/entry[@key='foo']", dom); }
@Test public void testWfsCascadeEntityExpansion() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); DataStoreInfo ds = cb.buildDataStore("wfs-xxe"); URL url = getClass().getResource("wfs1.1.0Capabilities-xxe.xml"); ds.getConnectionParameters().put(WFSDataStoreFactory.URL.key, url); // required or the store won't fetch caps from a file ds.getConnectionParameters().put("TESTING", Boolean.TRUE); final ResourcePool rp = getCatalog().getResourcePool(); try { rp.getDataStore(ds); fail("Store creation should have failed to to XXE attack"); } catch (Exception e) { String message = e.getMessage(); assertThat(message, containsString("Entity resolution disallowed")); assertThat(message, containsString("file:///file/not/there")); } }
ds.getConnectionParameters().put("host", "${jdbc.host}"); ds.getConnectionParameters().put("port", "${jdbc.port}"); assertTrue(ds.getConnectionParameters().get("host").equals("${jdbc.host}")); assertTrue(ds.getConnectionParameters().get("port").equals("${jdbc.port}")); .getConnectionParameters() .get("host") .equals(gsEnvironment.resolveValue("${jdbc.host}"))); assertTrue( expandedDs .getConnectionParameters() .get("port") .equals(gsEnvironment.resolveValue("${jdbc.port}"))); } else { assertTrue(expandedDs.getConnectionParameters().get("host").equals("${jdbc.host}")); assertTrue(expandedDs.getConnectionParameters().get("port").equals("${jdbc.port}"));
@Test public void testGetParamsFixesDatabaseFilePath() { Catalog catalog = getCatalog(); ResourcePool pool = new ResourcePool(catalog); DataStoreInfo ds = getCatalog().getFactory().createDataStore(); ds.getConnectionParameters().put("database", "file:data/test.gpkg"); Map newParams = pool.getParams(ds.getConnectionParameters(), getResourceLoader()); GeoServerDataDirectory dataDir = new GeoServerDataDirectory(getResourceLoader()); String absolutePath = dataDir.get("data/test.gpkg").dir().getAbsolutePath(); assertNotEquals(newParams.get("database"), "file:data/test.gpkg"); assertTrue(((String) newParams.get("database")).contains(absolutePath)); }
@Test public void testLookupFreshlyAdded() { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); String nsURI = catalog.getDefaultNamespace().getURI(); URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("freshOffTheBoat"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI); catalog.save(storeInfo); CatalogRepository repository = getCatalog().getResourcePool().getRepository(); DataStore store = repository.dataStore(new NameImpl("freshOffTheBoat")); assertNotNull(store); } }
expandedStore.getConnectionParameters();
cxParams.put(PropertyDataStoreFactory.DIRECTORY.key, propDir); cxParams.put(PropertyDataStoreFactory.NAMESPACE.key, ns.getURI()); expect(ds.getConnectionParameters()).andReturn(cxParams).anyTimes();
@Test public void testChangeNamespaceURI() { Catalog cat = createMock(Catalog.class); cat.addListener((CatalogListener) anyObject()); expectLastCall(); NamespaceInfo ns = createNiceMock(NamespaceInfo.class); expect(ns.getPrefix()).andReturn("foo"); expect(ns.getURI()).andReturn("http://foo.org"); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); expect(cat.getWorkspaceByName("foo")).andReturn(ws); DataStoreInfo ds = createNiceMock(DataStoreInfo.class); expect(cat.getDataStoresByWorkspace(ws)).andReturn(Arrays.asList(ds)); HashMap params = new HashMap(); params.put("namespace", "http://bar.org"); expect(ds.getConnectionParameters()).andReturn(params).anyTimes(); cat.save(hasNamespace("http://foo.org")); expectLastCall(); CatalogPostModifyEvent e = createNiceMock(CatalogPostModifyEvent.class); expect(e.getSource()).andReturn(ns).anyTimes(); expect(ns.getPrefix()).andReturn("foo"); expect(cat.getWorkspaceByName("foo")).andReturn(ws); replay(ds, ws, ns, e, cat); new NamespaceWorkspaceConsistencyListener(cat).handlePostModifyEvent(e); verify(cat); }
File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("store"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI); catalog.save(storeInfo);
store.setEnabled(true); store.getConnectionParameters().put(PropertyDataStoreFactory.DIRECTORY.key, storeDir); store.getConnectionParameters().put(PropertyDataStoreFactory.NAMESPACE.key, uri); catalog.add(store);
ds.setEnabled(true); Map params = ds.getConnectionParameters(); params.put("dbtype", "h2"); File dbFile =
protected void clone(final DataStoreInfo source, DataStoreInfo target) { target.setDescription(source.getDescription()); target.setEnabled(source.isEnabled()); target.setName(source.getName()); target.setWorkspace(source.getWorkspace()); target.setType(source.getType()); target.getConnectionParameters().clear(); target.getConnectionParameters().putAll(source.getConnectionParameters()); }
void updateParameters(DataStoreInfo info, NamespaceInfo namespace, DataStoreFactorySpi factory, File uploadedFile) { Map connectionParameters = info.getConnectionParameters(); updateParameters(connectionParameters, factory, uploadedFile); connectionParameters.put( "namespace", namespace.getURI() ); // ensure the parameters are valid if ( !factory.canProcess( connectionParameters ) ) { //TODO: log the parameters at the debug level throw new RestletException( "Unable to configure datastore, bad parameters.", Status.SERVER_ERROR_INTERNAL ); } }
public DataStoreInfo createStore(ImportData data, WorkspaceInfo workspace, Catalog catalog) throws IOException { Map<String,Serializable> params = createConnectionParameters(data); if (params == null) { return null; } CatalogBuilder cb = new CatalogBuilder(catalog); cb.setWorkspace(workspace); DataStoreInfo store = cb.buildDataStore(data.getName()); store.setType(factory().getDisplayName()); store.getConnectionParameters().putAll(params); return store; }
@Override public void visit(DataStoreInfo dataStore) { DataStoreInfo otherDataStore = otherCatalog.getDataStore(dataStore.getId()); if (!(Objects.equals(dataStore, otherDataStore) && Objects.equals(dataStore.getType(), otherDataStore.getType()) && checkEquals(dataStore.getMetadata(), otherDataStore.getMetadata()) && checkEquals( dataStore.getConnectionParameters(), otherDataStore.getConnectionParameters()))) { differences.add(new InfoDiff(dataStore, otherDataStore)); } }