Example usage for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setSslPropertiesLocation

List of usage examples for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setSslPropertiesLocation

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setSslPropertiesLocation.

Prototype

public void setSslPropertiesLocation(Resource sslPropertiesLocation) 

Source Link

Document

When #setUseSSL(boolean) is true, the SSL properties to use (optional).

Usage

From source file:org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory.java

/**
 * Create a dedicated connection factory for the address.
 * @param address the address to which the factory should connect.
 * @param node  the node./*from w  w  w .  j a va 2s.c  o  m*/
 * @return the connection factory.
 * @throws Exception if errors occur during creation.
 */
protected ConnectionFactory createConnectionFactory(String address, String node) throws Exception {
    RabbitConnectionFactoryBean rcfb = new RabbitConnectionFactoryBean();
    rcfb.setUseSSL(this.useSSL);
    rcfb.setSslPropertiesLocation(this.sslPropertiesLocation);
    rcfb.setKeyStore(this.keyStore);
    rcfb.setTrustStore(this.trustStore);
    rcfb.setKeyStorePassphrase(this.keyStorePassPhrase);
    rcfb.setTrustStorePassphrase(this.trustStorePassPhrase);
    rcfb.afterPropertiesSet();
    CachingConnectionFactory ccf = new CachingConnectionFactory(rcfb.getObject());
    ccf.setAddresses(address);
    ccf.setUsername(this.username);
    ccf.setPassword(this.password);
    ccf.setVirtualHost(this.vhost);
    ccf.setBeanName("node:" + node);
    return ccf;
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
@Ignore/*from  w w w. j a va2s  . c o m*/
public void test() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    fb.setUseSSL(true);
    fb.setSslPropertiesLocation(new ClassPathResource("ssl.properties"));
    fb.setClientProperties(Collections.<String, Object>singletonMap("foo", "bar"));
    fb.afterPropertiesSet();
    ConnectionFactory cf = fb.getObject();
    assertEquals("bar", cf.getClientProperties().get("foo"));
    Connection conn = cf.newConnection();
    Channel chan = conn.createChannel();
    chan.close();
    conn.close();
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testTypeProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    fb.setSslPropertiesLocation(new ClassPathResource("ssl.properties"));
    fb.afterPropertiesSet();/*from  www  . j a v  a  2 s. com*/
    try {
        fb.setUpSSL();
        //Here we make sure the exception is thrown because setUpSSL() will fail.
        // But we only care about having it load the props
        fail("setupSSL should fail");
    } catch (Exception e) {
        assertEquals("foo", fb.getKeyStoreType());
        assertEquals("bar", fb.getTrustStoreType());
    }
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testTypeSettersOverrideProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    fb.setSslPropertiesLocation(new ClassPathResource("ssl.properties"));
    fb.afterPropertiesSet();/*  ww  w  . j a  v a 2s.c om*/
    fb.setKeyStoreType("alice");
    fb.setTrustStoreType("bob");
    try {
        fb.setUpSSL();
        // Here we make sure the exception is thrown because setUpSSL() will fail.
        //But we only care about having it load the props
        fail("setupSSL should fail");
    } catch (Exception e) {
        assertEquals("alice", fb.getKeyStoreType());
        assertEquals("bob", fb.getTrustStoreType());
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.LocalizedQueueConnectionFactory.java

/**
 * Create a dedicated connection factory for the address.
 * @param address the address to which the factory should connect.
 * @return the connection factory./*from w ww  .  j a  va 2  s.  c o m*/
 * @throws Exception if errors occur during creation.
 */
protected ConnectionFactory createConnectionFactory(String address) throws Exception {
    RabbitConnectionFactoryBean rcfb = new RabbitConnectionFactoryBean();
    rcfb.setUseSSL(this.useSSL);
    rcfb.setSslPropertiesLocation(this.sslPropertiesLocation);
    rcfb.afterPropertiesSet();
    CachingConnectionFactory ccf = new CachingConnectionFactory(rcfb.getObject());
    ccf.setAddresses(address);
    ccf.setUsername(this.username);
    ccf.setPassword(this.password);
    ccf.setVirtualHost(this.vhost);
    return ccf;
}