Package org.geowebcache.diskquota.jdbc

Examples of org.geowebcache.diskquota.jdbc.JDBCConfiguration$ConnectionPoolConfiguration


    public void testDiskQuotaStorage() throws Exception {
        // normal state, quota is not enabled by default
        GWC gwc = GWC.get();
        ConfigurableQuotaStoreProvider provider = GeoServerExtensions.bean(ConfigurableQuotaStoreProvider.class);
        DiskQuotaConfig quota = gwc.getDiskQuotaConfig();
        JDBCConfiguration jdbc = gwc.getJDBCDiskQuotaConfig();
        assertFalse("Disk quota is enabled??", quota.isEnabled());
        assertNull("jdbc quota config should be missing", jdbc);
        assertTrue(getActualStore(provider) instanceof DummyQuotaStore);
       
        // enable disk quota in H2 mode
        quota.setEnabled(true);
        quota.setQuotaStore("H2");
        gwc.saveDiskQuotaConfig(quota, null);
        GeoServerDataDirectory dd = GeoServerExtensions.bean(GeoServerDataDirectory.class);
        File jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
        assertNull("jdbc config should not be there", jdbcConfigFile);
        File h2DefaultStore = dd.findFile("gwc/diskquota_page_store_h2");
        assertNotNull("jdbc store should be there", h2DefaultStore);
        assertTrue(getActualStore(provider) instanceof JDBCQuotaStore);
       
        // disable again and clean up
        quota.setEnabled(false);
        gwc.saveDiskQuotaConfig(quota, null);
        FileUtils.deleteDirectory(h2DefaultStore);
       
        // now enable it in JDBC mode, with H2 local storage
        quota.setEnabled(true);
        quota.setQuotaStore("JDBC");
        jdbc = new JDBCConfiguration();
        jdbc.setDialect("H2");
        ConnectionPoolConfiguration pool = new ConnectionPoolConfiguration();
        pool.setDriver("org.h2.Driver");
        pool.setUrl("jdbc:h2:./target/quota-h2");
        pool.setUsername("sa");
        pool.setPassword("");
        pool.setMinConnections(1);
        pool.setMaxConnections(1);
        pool.setMaxOpenPreparedStatements(50);
        jdbc.setConnectionPool(pool);
        gwc.saveDiskQuotaConfig(quota, jdbc);
        jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
        assertNotNull("jdbc config should be there", jdbcConfigFile);
        assertNull("jdbc store should be there", dd.findDataFile("gwc/diskquota_page_store_h2"));
        File newQuotaStore = new File("./target/quota-h2.data.db");
View Full Code Here


            int idx = beanName.indexOf("QuotaDialect");
            if(idx > 0) {
                dialectNames.add(beanName.substring(0, idx));
            }
        }
        JDBCConfiguration config = jdbcQuotaConfigModel.getObject();
        IModel<String> dialectModel = new PropertyModel<String>(jdbcQuotaConfigModel, "dialect");
        DropDownChoice<String> dialectChooser = new DropDownChoice<String>("dialectChooser", dialectModel, dialectNames);
        dialectChooser.setRequired(true);
        jdbcContainer.add(dialectChooser);
       
        // add a chooser for the connection type
        List<String> connectionTypes = Arrays.asList("JNDI", "PRIVATE_POOL");
        Model<String> connectionTypeModel = new Model<String>();
        if(config.getJNDISource() == null) {
            connectionTypeModel.setObject("PRIVATE_POOL");
        } else {
            connectionTypeModel.setObject("JNDI");
        }
        final DropDownChoice<String> connectionTypeChooser = new DropDownChoice<String>("connectionTypeChooser",
                connectionTypeModel, connectionTypes, new LocalizedChoiceRenderer(this));
        connectionTypeChooser.setOutputMarkupId(true);
        jdbcContainer.add(connectionTypeChooser);
       
        // make the JDBC configuration visible only when the user chose a JDBC store
        quotaStoreChooser.add(new AjaxFormComponentUpdatingBehavior("onChange") {
           
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                jdbcContainer.setVisible("JDBC".equals(quotaStoreChooser.getModelObject()));
                target.addComponent(quotaStoreContainer);
            }
        });
       
        // a container for jndi and local private pool options
        final WebMarkupContainer connectionTypeContainer = new WebMarkupContainer("connectionTypeContainer");
        connectionTypeContainer.setOutputMarkupId(true);
        jdbcContainer.add(connectionTypeContainer);
       
        // add a field for editing the JNDI connection parameters
        final WebMarkupContainer jndiContainer = new WebMarkupContainer("jndiLocationContainer");
        jndiContainer.setVisible(config.getJNDISource() != null);
        connectionTypeContainer.add(jndiContainer);
        IModel<String> jndiModel = new PropertyModel<String>(jdbcQuotaConfigModel, "jNDISource");
        TextField<String> jndiLocation = new TextField<String>("jndiLocation", jndiModel);
        jndiLocation.setRequired(true);
        jndiContainer.add(jndiLocation);
       
        // and a panel to edit the private jdbc pool
        IModel<JDBCConfiguration.ConnectionPoolConfiguration> poolConfigurationModel =
                new PropertyModel<JDBCConfiguration.ConnectionPoolConfiguration>(jdbcQuotaConfigModel, "connectionPool");
        final JDBCConnectionPoolPanel privatePoolPanel = new JDBCConnectionPoolPanel("connectionPoolConfigurator", poolConfigurationModel);
        privatePoolPanel.setVisible(config.getJNDISource() == null);
        connectionTypeContainer.add(privatePoolPanel);
       
        // make the two ways to configure the JDBC store show up as alternatives
        connectionTypeChooser.add(new AjaxFormComponentUpdatingBehavior("onChange") {
           
View Full Code Here

            diskQuotaConfig = gwc.getDiskQuotaConfig().clone();
        }
       
        // same as above, but we don't need to create a copy of the JDBC quota config since
        // that config is just used to instantiate the quota store, and then gets promptly discarted
        final JDBCConfiguration jdbcQuotaConfiguration;
        if(gwc.getJDBCDiskQuotaConfig() == null) {
            jdbcQuotaConfiguration = new JDBCConfiguration();
            JDBCConfiguration.ConnectionPoolConfiguration configuration = new JDBCConfiguration.ConnectionPoolConfiguration();
            configuration.setMinConnections(1);
            configuration.setMaxConnections(10);
            configuration.setConnectionTimeout(10000);
            configuration.setMaxOpenPreparedStatements(50);
            jdbcQuotaConfiguration.setConnectionPool(configuration);
        } else {
            jdbcQuotaConfiguration = gwc.getJDBCDiskQuotaConfig();
        }

        final Form<Map<String, Serializable>> form;
        form = new Form<Map<String, Serializable>>("form");
        add(form);

        final IModel<DiskQuotaConfig> diskQuotaModel = new Model<DiskQuotaConfig>(diskQuotaConfig);
        final IModel<JDBCConfiguration> jdbcQuotaModel = new Model<JDBCConfiguration>(jdbcQuotaConfiguration);

        final DiskQuotaConfigPanel diskQuotaConfigPanel = new DiskQuotaConfigPanel(
                "diskQuotaPanel", diskQuotaModel, jdbcQuotaModel);
       
        if (diskQuotaModuleDisabled) {
            diskQuotaConfigPanel.setEnabled(false);
            super.warn(new ResourceModel("DiskQuotaSettingsPage.disabledWarning").getObject());
        }
       
        form.add(diskQuotaConfigPanel);

        form.add(new Button("submit") {
            private static final long serialVersionUID = 1L;

            @Override
            public void onSubmit() {
                GWC gwc = getGWC();
                if (!diskQuotaModuleDisabled) {
                    StorageUnit chosenUnit = diskQuotaConfigPanel.getStorageUnit();
                    // REVISIT: it seems Wicket is sending back a plain string instead of a
                    String chosenQuotaStr = String.valueOf(diskQuotaConfigPanel.getQuotaValue());
                    Double chosenQuota;
                    try {
                        chosenQuota = Double.valueOf(chosenQuotaStr);
                    } catch (NumberFormatException e) {
                        form.error(chosenQuotaStr + " is not a valid floating point number");// TODO:
                        // localize
                        return;
                    }
                    if (chosenQuota.doubleValue() <= 0D) {
                        form.error("Quota has to be > 0");
                        return;
                    }
                    DiskQuotaConfig dqConfig = diskQuotaModel.getObject();
                    JDBCConfiguration jdbcConfig = jdbcQuotaModel.getObject();
                    if(dqConfig.getQuotaStore() != null && dqConfig.getQuotaStore().equals("JDBC")) {
                        try {
                            gwc.testQuotaConfiguration(jdbcConfig);
                        } catch(Exception e) {
                            LOGGER.log(Level.SEVERE, "Error instantiating the JDBC configuration", e);
View Full Code Here

        clone.setPassword(encoded);
        clone.setUrl(original.getUrl());
        clone.setUsername(original.getUsername());
        clone.setValidationQuery(original.getValidationQuery());

        JDBCConfiguration result = new JDBCConfiguration();
        result.setConnectionPool(clone);
        result.setDialect(configuration.getDialect());
        result.setJNDISource(configuration.getJNDISource());
        return result;
    }
View Full Code Here

    private QuotaStore loadJDBCQuotaStore(ApplicationContext applicationContext,
            String quotaStoreName) throws ConfigurationException, IOException {
        // special case for the JDBC quota store, allows us to unencrypt passwords before
        // creating the GUI
        JDBCConfiguration config = jdbcConfigManager.getJDBCDiskQuotaConfig();
        JDBCQuotaStoreFactory factory = new JDBCQuotaStoreFactory();
        factory.setApplicationContext(applicationContext);
        return factory.getJDBCStore(applicationContext, config);
    }
View Full Code Here

    public synchronized void saveDiskQuotaConfig(DiskQuotaConfig config,
            JDBCConfiguration jdbcConfig) throws ConfigurationException, IOException,
            InterruptedException {
        File configFile = new File(storageFinder.getDefaultPath(), "geowebcache-diskquota-jdbc.xml");
        if ("JDBC".equals(config.getQuotaStore())) {
            JDBCConfiguration encrypted = passwordHelper.encryptPassword(jdbcConfig);
            JDBCConfiguration.store(encrypted, configFile);
        } else {
            if (configFile.exists() && !configFile.delete()) {
                LOGGER.log(Level.SEVERE, "Failed to delete " + configFile
                        + ", this might cause misbehavior on GeoServer restart");
View Full Code Here

        File configFile = new File(storageFinder.getDefaultPath(), "geowebcache-diskquota-jdbc.xml");
        if (!configFile.exists()) {
            return null;
        }
        try {
            JDBCConfiguration configuration = JDBCConfiguration.load(configFile);
            return passwordHelper.unencryptPassword(configuration);
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Failed to load geowebcache-diskquota-jdbc.xml", e);
            return null;
        }
View Full Code Here

    @Override
    public void handlePostChanged(GeoServerSecurityManager securityManager) {
        // we can't know if the password encoder changed, so we check if the encrypted pwd changed
        // (unfortunately some password encoders change the encrypted password every time they are called...)
        try {
            JDBCConfiguration config = getJDBCDiskQuotaConfig();
            if(config != null) {
                File configFile = new File(storageFinder.getDefaultPath(), "geowebcache-diskquota-jdbc.xml");
                if(!configFile.exists()) {
                    return;
                }
                JDBCConfiguration c1 = JDBCConfiguration.load(configFile);
                if(c1 == null || c1.getConnectionPool() == null) {
                    return;
                }
                String originalEncrypted = c1.getConnectionPool().getPassword();
                if(originalEncrypted == null) {
                    return;
                }
                JDBCConfiguration c2 = passwordHelper.unencryptPassword(c1);
                JDBCConfiguration c3 = passwordHelper.encryptPassword(c2);
                String newEncrypted = c3.getConnectionPool().getPassword();
                if(!originalEncrypted.equals(newEncrypted)) {
                    JDBCConfiguration.store(c3, configFile);
                }
            }
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.geowebcache.diskquota.jdbc.JDBCConfiguration$ConnectionPoolConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.