List of usage examples for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean RabbitConnectionFactoryBean
public RabbitConnectionFactoryBean()
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 v a2s . co 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.ja v a 2 s. c om*/ 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(/* w ww. j a v a 2s. c o 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(//ww w . j a va 2 s. c o m 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 w w w. ja v a 2 s . c om*/ 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);/* ww w . jav a2 s .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);/* w w w . ja v a 2 s .c om*/ 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 testTypeDefault() throws Exception { RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean(); assertEquals("PKCS12", fb.getKeyStoreType()); assertEquals("JKS", fb.getTrustStoreType()); }
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 w w w . ja va 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 testTypeSettersNoProps() throws Exception { RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean(); fb.setKeyStoreType("alice"); fb.setTrustStoreType("bob"); assertEquals("alice", fb.getKeyStoreType()); assertEquals("bob", fb.getTrustStoreType()); }