Search in sources :

Example 1 with TypedProperties

use of org.jumpmind.properties.TypedProperties in project symmetric-ds by JumpMind.

the class MailService method getJavaMailProperties.

protected Properties getJavaMailProperties(TypedProperties typedProp) {
    Properties prop = new Properties();
    prop.setProperty(JAVAMAIL_HOST_NAME, typedProp.get(ParameterConstants.SMTP_HOST, "localhost"));
    prop.setProperty(JAVAMAIL_PORT_NUMBER, typedProp.get(ParameterConstants.SMTP_PORT, "25"));
    prop.setProperty(JAVAMAIL_PORT_NUMBER_SSL, typedProp.get(ParameterConstants.SMTP_PORT, "25"));
    prop.setProperty(JAVAMAIL_FROM, typedProp.get(ParameterConstants.SMTP_FROM, "root@localhost"));
    prop.setProperty(JAVAMAIL_USE_STARTTLS, String.valueOf(typedProp.is(ParameterConstants.SMTP_USE_STARTTLS, false)));
    prop.setProperty(JAVAMAIL_USE_AUTH, String.valueOf(typedProp.is(ParameterConstants.SMTP_USE_AUTH, false)));
    prop.setProperty(JAVAMAIL_TRUST_HOST, typedProp.is(ParameterConstants.SMTP_ALLOW_UNTRUSTED_CERT, false) ? "*" : "");
    prop.setProperty(JAVAMAIL_TRUST_HOST_SSL, typedProp.is(ParameterConstants.SMTP_ALLOW_UNTRUSTED_CERT, false) ? "*" : "");
    return prop;
}
Also used : Properties(java.util.Properties) TypedProperties(org.jumpmind.properties.TypedProperties)

Example 2 with TypedProperties

use of org.jumpmind.properties.TypedProperties in project symmetric-ds by JumpMind.

the class SymmetricEngineHolder method install.

public ISymmetricEngine install(Properties passedInProperties) throws Exception {
    TypedProperties properties = new TypedProperties(passedInProperties);
    String password = properties.getProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD);
    if (StringUtils.isNotBlank(password) && !password.startsWith(SecurityConstants.PREFIX_ENC)) {
        try {
            ISecurityService service = SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties);
            properties.setProperty(BasicDataSourcePropertyConstants.DB_POOL_PASSWORD, SecurityConstants.PREFIX_ENC + service.encrypt(password));
        } catch (Exception ex) {
            log.warn("Could not encrypt password", ex);
        }
    }
    String engineName = validateRequiredProperties(properties);
    passedInProperties.setProperty(ParameterConstants.ENGINE_NAME, engineName);
    if (engines.get(engineName) != null) {
        try {
            engines.get(engineName).stop();
        } catch (Exception e) {
            log.error("", e);
        }
        engines.remove(engineName);
    }
    File enginesDir = new File(AbstractCommandLauncher.getEnginesDir());
    File symmetricProperties = new File(enginesDir, engineName + ".properties");
    FileOutputStream fileOs = null;
    try {
        fileOs = new FileOutputStream(symmetricProperties);
        properties.store(fileOs, "Updated by SymmetricDS Pro");
    } catch (IOException ex) {
        throw new RuntimeException("Failed to write symmetric.properties to engine directory", ex);
    } finally {
        IOUtils.closeQuietly(fileOs);
    }
    ISymmetricEngine engine = null;
    try {
        String registrationUrl = properties.getProperty(ParameterConstants.REGISTRATION_URL);
        if (StringUtils.isNotBlank(registrationUrl)) {
            Collection<ServerSymmetricEngine> all = getEngines().values();
            for (ISymmetricEngine currentEngine : all) {
                if (currentEngine.getParameterService().getSyncUrl().equals(registrationUrl)) {
                    String serverNodeGroupId = currentEngine.getParameterService().getNodeGroupId();
                    String clientNodeGroupId = properties.getProperty(ParameterConstants.NODE_GROUP_ID);
                    String externalId = properties.getProperty(ParameterConstants.EXTERNAL_ID);
                    IConfigurationService configurationService = currentEngine.getConfigurationService();
                    ITriggerRouterService triggerRouterService = currentEngine.getTriggerRouterService();
                    List<NodeGroup> groups = configurationService.getNodeGroups();
                    boolean foundGroup = false;
                    for (NodeGroup nodeGroup : groups) {
                        if (nodeGroup.getNodeGroupId().equals(clientNodeGroupId)) {
                            foundGroup = true;
                        }
                    }
                    if (!foundGroup) {
                        configurationService.saveNodeGroup(new NodeGroup(clientNodeGroupId));
                    }
                    boolean foundLink = false;
                    List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(serverNodeGroupId, false);
                    for (NodeGroupLink nodeGroupLink : links) {
                        if (nodeGroupLink.getTargetNodeGroupId().equals(clientNodeGroupId)) {
                            foundLink = true;
                        }
                    }
                    if (!foundLink) {
                        configurationService.saveNodeGroupLink(new NodeGroupLink(serverNodeGroupId, clientNodeGroupId, NodeGroupLinkAction.W));
                        triggerRouterService.syncTriggers();
                    }
                    IRegistrationService registrationService = currentEngine.getRegistrationService();
                    if (!registrationService.isAutoRegistration() && !registrationService.isRegistrationOpen(clientNodeGroupId, externalId)) {
                        Node node = new Node(properties);
                        registrationService.openRegistration(node);
                    }
                }
            }
        }
        engine = create(symmetricProperties.getAbsolutePath());
        if (engine != null) {
            engineCount++;
            engine.start();
        } else {
            FileUtils.deleteQuietly(symmetricProperties);
            log.warn("The engine could not be created.  It will not be started");
        }
        return engine;
    } catch (RuntimeException ex) {
        if (engine != null) {
            engine.destroy();
        }
        FileUtils.deleteQuietly(symmetricProperties);
        throw ex;
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) IRegistrationService(org.jumpmind.symmetric.service.IRegistrationService) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) IOException(java.io.IOException) TypedProperties(org.jumpmind.properties.TypedProperties) IOException(java.io.IOException) ISecurityService(org.jumpmind.security.ISecurityService) FileOutputStream(java.io.FileOutputStream) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) File(java.io.File) NodeGroup(org.jumpmind.symmetric.model.NodeGroup)

Example 3 with TypedProperties

use of org.jumpmind.properties.TypedProperties in project symmetric-ds by JumpMind.

the class AbstractTest method getProperties.

protected Properties getProperties(String name) {
    TypedProperties properties = new TypedProperties(getClass().getResourceAsStream("/symmetric-test.properties"));
    properties.setProperty(ParameterConstants.ENGINE_NAME, name);
    properties.setProperty(ParameterConstants.AUTO_INSERT_REG_SVR_IF_NOT_FOUND, "true");
    properties.setProperty(ParameterConstants.EXTERNAL_ID, name);
    properties.setProperty(ParameterConstants.NODE_GROUP_ID, name);
    properties.setProperty(ParameterConstants.SYNC_URL, "http://localhost:" + port + "/sync/" + name);
    properties.setProperty(ParameterConstants.REGISTRATION_URL, "http://localhost:" + registrationPort + "/sync/" + getGroupNames()[0]);
    return properties;
}
Also used : TypedProperties(org.jumpmind.properties.TypedProperties)

Example 4 with TypedProperties

use of org.jumpmind.properties.TypedProperties in project symmetric-ds by JumpMind.

the class JmxCommand method execute.

protected <T> T execute(IJmxTemplate<T> template) throws Exception {
    String host = "localhost";
    String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + System.getProperty("jmx.agent.port", "31418") + "/jmxrmi";
    JMXServiceURL serviceUrl = new JMXServiceURL(url);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
    TypedProperties properties = getTypedProperties();
    String engineName = properties.get(ParameterConstants.ENGINE_NAME, "unknown");
    try {
        MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
        return template.execute(engineName, mbeanConn);
    } finally {
        jmxConnector.close();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) TypedProperties(org.jumpmind.properties.TypedProperties) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 5 with TypedProperties

use of org.jumpmind.properties.TypedProperties in project symmetric-ds by JumpMind.

the class TypedPropertiesFactory method reload.

public TypedProperties reload() {
    PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
    factoryBean.setIgnoreResourceNotFound(true);
    factoryBean.setLocalOverride(true);
    factoryBean.setSingleton(false);
    factoryBean.setProperties(properties);
    factoryBean.setLocations(buildLocations(propertiesFile));
    try {
        TypedProperties properties = new TypedProperties(factoryBean.getObject());
        SymmetricUtils.replaceSystemAndEnvironmentVariables(properties);
        return properties;
    } catch (IOException e) {
        throw new IoException(e);
    }
}
Also used : IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) TypedProperties(org.jumpmind.properties.TypedProperties)

Aggregations

TypedProperties (org.jumpmind.properties.TypedProperties)16 File (java.io.File)4 IOException (java.io.IOException)3 ISecurityService (org.jumpmind.security.ISecurityService)2 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)2 IRegistrationService (org.jumpmind.symmetric.service.IRegistrationService)2 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Attributes (java.util.jar.Attributes)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 DataSource (javax.sql.DataSource)1 Connector (org.eclipse.jetty.server.Connector)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)1