Search in sources :

Example 36 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class OpenWireToAMQPTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(true, true);
    Configuration serverConfig = server.getConfiguration();
    serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(true).setAutoCreateAddresses(true).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ")));
    serverConfig.setSecurityEnabled(false);
    server.start();
    coreQueue = new SimpleString(queueName);
    server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false);
    qpidfactory = new JmsConnectionFactory("amqp://localhost:61616");
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Before(org.junit.Before)

Example 37 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project syndesis-qe by syndesisio.

the class JmsClientManager method initClient.

private JmsClient initClient() {
    if (jmsClient == null) {
        switch(protocol) {
            case "tcp":
            case "openwire":
                ActiveMQConnectionFactory jmsFactory = new ActiveMQConnectionFactory();
                jmsFactory.setBrokerURL(jmsUrl);
                jmsFactory.setUserName(jmsUser);
                jmsFactory.setPassword(jmsPass);
                jmsClient = new JmsClient(jmsFactory);
                break;
            case "amqp":
                JmsConnectionFactory jmsConnectionFactory = new JmsConnectionFactory(jmsUser, jmsPass, jmsUrl);
                jmsClient = new JmsClient(jmsConnectionFactory);
                break;
        }
    }
    return jmsClient;
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 38 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project syndesis by syndesisio.

the class AMQPConnector method createDelegateComponent.

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
@Override
protected Optional<Component> createDelegateComponent(ComponentDefinition definition, Map<String, Object> options) throws Exception {
    AMQPComponent delegate = lookupComponent();
    if (delegate == null) {
        // create and set ConnectionFactory on delegate
        final AMQPUtil.ConnectionParameters connectionParameters = new AMQPUtil.ConnectionParameters(connectionUri, username, password, brokerCertificate, clientCertificate, skipCertificateCheck);
        final JmsConnectionFactory connectionFactory = AMQPUtil.createConnectionFactory(connectionParameters);
        connectionFactory.setClientID(clientId);
        delegate = new AMQPComponent(connectionFactory);
    }
    return Optional.of(delegate);
}
Also used : AMQPComponent(org.apache.camel.component.amqp.AMQPComponent) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 39 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project syndesis by syndesisio.

the class AMQPUtil method createConnectionFactory.

public static JmsConnectionFactory createConnectionFactory(ConnectionParameters connectionParameters) {
    final JmsConnectionFactory result;
    final String connectionUri = connectionParameters.getConnectionUri();
    if (!connectionUri.contains("amqps:")) {
        result = new JmsConnectionFactory(connectionParameters.getUsername(), connectionParameters.getPassword(), connectionUri);
    } else {
        StringBuilder newConnectionUri = new StringBuilder(connectionUri);
        if (connectionParameters.isSkipCertificateCheck()) {
            if (!connectionUri.contains("transport.trustAll")) {
                LOG.warn("Skipping Certificate check for AMQP Connection {}", connectionUri);
                newConnectionUri.append(connectionUri.contains("?") ? "&" : "?").append("transport.trustAll=true&transport.verifyHost=false");
            }
        } else {
            // add amqps connection certificates
            final String clientCertificate = connectionParameters.getClientCertificate();
            if (!ObjectHelper.isEmpty(clientCertificate)) {
                // copy client certificate to a keystore using a random key
                addKeyStoreParam(newConnectionUri, clientCertificate, "amqp-client", "key");
                newConnectionUri.append("&transport.keyAlias=amqp-client");
            }
            final String brokerCertificate = connectionParameters.getBrokerCertificate();
            if (!ObjectHelper.isEmpty(brokerCertificate)) {
                // copy broker certificate to a keystore using a random key
                addKeyStoreParam(newConnectionUri, brokerCertificate, "amqp-broker", "trust");
                // possibly expose this property from connector in the future?
                newConnectionUri.append("&transport.verifyHost=false");
            }
        }
        result = new JmsConnectionFactory(connectionParameters.getUsername(), connectionParameters.getPassword(), newConnectionUri.toString());
    }
    return result;
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory)

Example 40 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project syndesis by syndesisio.

the class AMQPVerifierExtension method verifyCredentials.

private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) {
    final String connectionUri = (String) parameters.get("connectionUri");
    final String username = (String) parameters.get("username");
    final String password = (String) parameters.get("password");
    final boolean skipCertificateCheck = "true".equals(parameters.get("skipCertificateCheck"));
    final String brokerCertificate = (String) parameters.get("brokerCertificate");
    final String clientCertificate = (String) parameters.get("clientCertificate");
    LOG.debug("Validating AMQP connection to {}", connectionUri);
    final AMQPUtil.ConnectionParameters connectionParameters = new AMQPUtil.ConnectionParameters(connectionUri, username, password, brokerCertificate, clientCertificate, skipCertificateCheck);
    JmsConnectionFactory connectionFactory = AMQPUtil.createConnectionFactory(connectionParameters);
    Connection connection = null;
    try {
        // try to create and start the JMS connection
        connection = connectionFactory.createConnection();
        connection.start();
    } catch (JMSException e) {
        final Map<String, Object> redacted = new HashMap<>(parameters);
        redacted.replace("password", "********");
        LOG.warn("Unable to connect to AMQP Broker with parameters {}, Message: {}, error code: {}", redacted, e.getMessage(), e.getErrorCode(), e);
        builder.error(ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.ILLEGAL_PARAMETER_VALUE, e.getMessage()).parameterKey("connectionUri").parameterKey("username").parameterKey("password").build());
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException ignored) {
            // ignore
            }
        }
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)40 Connection (javax.jms.Connection)19 Session (javax.jms.Session)19 MessageConsumer (javax.jms.MessageConsumer)17 MessageProducer (javax.jms.MessageProducer)17 Test (org.junit.Test)17 TextMessage (javax.jms.TextMessage)14 ConnectionFactory (javax.jms.ConnectionFactory)10 Queue (javax.jms.Queue)10 Message (javax.jms.Message)8 BytesMessage (javax.jms.BytesMessage)4 JmsConnection (org.apache.qpid.jms.JmsConnection)4 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)3 URI (java.net.URI)2 JMSSecurityException (javax.jms.JMSSecurityException)2 InitialContext (javax.naming.InitialContext)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2