Package org.apache.synapse.commons

Examples of org.apache.synapse.commons.SynapseCommonsException


    }

    public void addMBean(String name, Object mBean) {

        if (name == null || "".equals(name)) {
            throw new SynapseCommonsException("DataSource MBean name cannot be found.", log);
        }

        if (mBean == null) {
            throw new SynapseCommonsException("DataSource MBean  cannot be found.", log);
        }

        if (!(mBean instanceof DBPoolView)) {
            throw new SynapseCommonsException("Given MBean instance is not matched" +
                    "with the expected MBean - 'DBPoolView'", log);
        }
        dataSourcesMBeans.put(name, (DBPoolView) mBean);
        MBeanRegistrar.getInstance().registerMBean(mBean,
                MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name);
View Full Code Here


                MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name);
    }

    public Object getMBean(String name) {
        if (name == null || "".equals(name)) {
            throw new SynapseCommonsException("DataSource MBean name cannot be found.", log);
        }
        return dataSourcesMBeans.get(name);
    }
View Full Code Here

        try {
            Context context = new InitialContext(jndiEnv);
            return find(dsName, context);

        } catch (NamingException e) {
            throw new SynapseCommonsException("Error looking up DataSource : " + dsName +
                    " using JNDI properties : " + jndiEnv, e, log);
        }
    }
View Full Code Here

        try {
            Object dataSourceO = context.lookup(dsName);
            if (dataSourceO != null && dataSourceO instanceof DataSource) {
                return (DataSource) dataSourceO;
            } else {
                throw new SynapseCommonsException("DataSource : " + dsName + " not found " +
                        "when looking up using JNDI properties : " + context.getEnvironment(), log);
            }

        } catch (NamingException e) {
            throw new SynapseCommonsException("Error looking up DataSource : " + dsName
                    + " using JNDI" + " properties : " + context, e, log);
        }
    }
View Full Code Here

                context.rebind(dataSourceName, ref);
            } catch (NamingException e) {
                String msg = " Error binding name ' " + dataSourceName + " ' to " +
                        "the DataSource(BasicDataSource) reference";
                throw new SynapseCommonsException(msg, e, log);
            }

        } else if (DataSourceInformation.PER_USER_POOL_DATA_SOURCE.equals(dsType)) {

            // Construct DriverAdapterCPDS reference
            String className = (String) information.getParameter(
                    DataSourceConstants.PROP_CPDS_ADAPTER +
                            DataSourceConstants.DOT_STRING +
                            DataSourceConstants.PROP_CPDS_CLASS_NAME);
            String factory = (String) information.getParameter(
                    DataSourceConstants.PROP_CPDS_ADAPTER +
                            DataSourceConstants.DOT_STRING +
                            DataSourceConstants.PROP_CPDS_FACTORY);
            String name = (String) information.getParameter(
                    DataSourceConstants.PROP_CPDS_ADAPTER +
                            DataSourceConstants.DOT_STRING +
                            DataSourceConstants.PROP_CPDS_NAME);

            Reference cpdsRef =
                    new Reference(className, factory, null);

            cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_DRIVER, driver));
            cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_URL, url));
            cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_USER, user));
            cpdsRef.add(new StringRefAddr(SecurityConstants.PROP_PASSWORD,
                    password));

            try {
                context.rebind(name, cpdsRef);
            } catch (NamingException e) {
                String msg = "Error binding name '" + name + "' to " +
                        "the DriverAdapterCPDS reference";
                throw new SynapseCommonsException(msg, e, log);
            }

            // Construct PerUserPoolDataSource reference
            Reference ref =
                    new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
                            "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory",
                            null);

            ref.add(new BinaryRefAddr(
                    DataSourceConstants.PROP_JNDI_ENV,
                    MiscellaneousUtil.serialize(jndiEvn)));
            ref.add(new StringRefAddr(
                    DataSourceConstants.PROP_DATA_SOURCE_NAME, name));
            ref.add(new StringRefAddr(
                    DataSourceConstants.PROP_DEFAULT_MAX_ACTIVE, maxActive));
            ref.add(new StringRefAddr(
                    DataSourceConstants.PROP_DEFAULT_MAX_IDLE, maxIdle));
            ref.add(new StringRefAddr(
                    DataSourceConstants.PROP_DEFAULT_MAX_WAIT, maxWait));

            //set default jndiProperties for reference
            setCommonParameters(ref, information);

            try {

                if (log.isDebugEnabled()) {
                    log.debug("Registering a DataSource with name : " +
                            dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn);
                }

                context.rebind(dataSourceName, ref);
            } catch (NamingException e) {
                String msg = "Error binding name ' " + dataSourceName + " ' to " +
                        "the PerUserPoolDataSource reference";
                throw new SynapseCommonsException(msg, e, log);
            }

        } else {
            throw new SynapseCommonsException("Unsupported data source type : " + dsType, log);
        }
        cachedNameList.add(dataSourceName);
    }
View Full Code Here

        InitialContext context = getCachedInitialContext(name);
        try {
            context.unbind(name);
        } catch (NamingException e) {
            throw new SynapseCommonsException("Error removing a Datasource with name : " +
                    name + " from the JNDI context : " + initialContext, e);
        }
        cachedNameList.remove(name);
    }
View Full Code Here

                try {
                    assert context != null;
                    context = context.createSubcontext(path1);
                    if (context == null) {
                        throw new SynapseCommonsException("sub context " + path1 + " could not" +
                                " be created", log);
                    }

                } catch (NamingException e) {
                    throw new SynapseCommonsException("Unable to create sub context : " + path1,
                            e, log);
                }
            }
        }
    }
View Full Code Here

        return initialized;
    }

    private void validateInitialized() {
        if (!isInitialized()) {
            throw new SynapseCommonsException("Datasource repository has not been initialized " +
                    "yet", log);
        }
    }
View Full Code Here

        }
    }

    private void validateDSName(String dataSourceName) {
        if (dataSourceName == null || "".equals(dataSourceName)) {
            throw new SynapseCommonsException("Invalid DataSource configuration !! -" +
                    "DataSource Name cannot be found ", log);
        }
    }
View Full Code Here

        }
    }

    private void validateInitialContext(InitialContext initialContext) {
        if (initialContext == null) {
            throw new SynapseCommonsException("InitialContext cannot be found.", log);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.commons.SynapseCommonsException

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.