All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vgregion.ssl.jms.ActiveMqSslConnectionFactory Maven / Gradle / Ivy

There is a newer version: 3.24
Show newest version
/**
 * Copyright 2010 Västra Götalandsregionen
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of version 2.1 of the GNU Lesser General Public
 *   License as published by the Free Software Foundation.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 *   Boston, MA 02111-1307  USA
 */

package se.vgregion.ssl.jms;

import org.apache.activemq.ActiveMQSslConnectionFactory;
import org.apache.activemq.transport.Transport;
import se.vgregion.ssl.ConvenientSslContextFactory;

import javax.jms.JMSException;

public final class ActiveMqSslConnectionFactory extends ActiveMQSslConnectionFactory {
    private String trustStore;
    private String trustStorePassword;
    private String keyStore;
    private String keyStorePassword;

    protected Transport createTransport() throws JMSException {
        // If the given URI is non-ssl, let superclass handle it.
        if (!brokerURL.getScheme().equals("ssl")) {
            return super.createTransport();
        }

        ConvenientSslContextFactory convenientSslContextFactory = new ConvenientSslContextFactory(trustStore,
                trustStorePassword, keyStore, keyStorePassword);

        if (keyManager == null && notEmpty(keyStore)) {
            keyManager = convenientSslContextFactory.getKeyManagers();
        }

        if (trustManager == null && notEmpty(trustStore)) {
            trustManager = convenientSslContextFactory.getTrustManagers();
        }

        return super.createTransport();
    }

    private boolean notEmpty(String string) {
        return string != null && !string.equals("");
    }

    public String getTrustStore() {
        return trustStore;
    }

    public void setTrustStore(String trustStore) {
        this.trustStore = trustStore;
    }

    public String getTrustStorePassword() {
        return trustStorePassword;
    }

    public void setTrustStorePassword(String trustStorePassword) {
        this.trustStorePassword = trustStorePassword;
    }

    public String getKeyStore() {
        return keyStore;
    }

    public void setKeyStore(String keyStore) {
        this.keyStore = keyStore;
    }

    public String getKeyStorePassword() {
        return keyStorePassword;
    }

    public void setKeyStorePassword(String keyStorePassword) {
        this.keyStorePassword = keyStorePassword;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy