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

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

Introduction

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

Prototype

@Override
    public void afterPropertiesSet() 

Source Link

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./*  www.  j  ava 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  ww  w  . ja  va 2  s.com*/
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 testAlgNoProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    ConnectionFactory rabbitCf = spy(//from   ww  w.j  ava2 s.co m
            TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
    new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
    fb.setUseSSL(true);
    fb.setSslAlgorithm("TLSv1.2");
    fb.afterPropertiesSet();
    fb.getObject();
    verify(rabbitCf).useSslProtocol("TLSv1.2");
}

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

@Test
public void testNoAlgNoProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    ConnectionFactory rabbitCf = spy(/*from ww  w  .  jav a2  s  . com*/
            TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
    new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
    fb.setUseSSL(true);
    fb.afterPropertiesSet();
    fb.getObject();
    verify(rabbitCf).useSslProtocol();
}

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

@Test
public void testKSTS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);//from  www . jav  a  2s . c o m
    fb.setKeyStoreType("JKS");
    fb.setKeyStoreResource(new ClassPathResource("test.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.setTrustStoreResource(new ClassPathResource("test.truststore.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.setSecureRandom(SecureRandom.getInstanceStrong());
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: ["), containsString("TM: ["), containsString("random: java.")));
}

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

@Test
public void testNullTS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);//  w  ww .j ava2s. c  o m
    fb.setKeyStoreType("JKS");
    fb.setKeyStoreResource(new ClassPathResource("test.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: ["), containsString("TM: null"), containsString("random: null")));
}

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

@Test
public void testNullKS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);/*from   w  w  w .  j  a v  a  2  s.c  o  m*/
    fb.setKeyStoreType("JKS");
    fb.setTrustStoreResource(new ClassPathResource("test.truststore.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: null"), containsString("TM: ["), containsString("random: null")));
}

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();
    try {//from w ww .j  a  v  a 2  s  . c o m
        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();
    fb.setKeyStoreType("alice");
    fb.setTrustStoreType("bob");
    try {//  w w  w.  j a  v a  2s.  c  om
        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 ww w .j a va 2  s. co 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;
}