/** Configures the given connection factory */
 public void configure(ActiveMQConnectionFactory factory, MessageActivationSpec activationSpec) {
   if (serverUrl != null) {
     factory.setBrokerURL(serverUrl);
   }
   if (clientid != null) {
     factory.setClientID(clientid);
   }
   if (redeliveryPolicy != null) {
     factory.setRedeliveryPolicy(redeliveryPolicy);
   }
   if (prefetchPolicy != null) {
     factory.setPrefetchPolicy(prefetchPolicy);
   }
   if (factory instanceof ActiveMQSslConnectionFactory) {
     String trustStore =
         defaultValue(
             activationSpec == null ? null : activationSpec.getTrustStore(), getTrustStore());
     String trustStorePassword =
         defaultValue(
             activationSpec == null ? null : activationSpec.getTrustStorePassword(),
             getTrustStorePassword());
     String keyStore =
         defaultValue(activationSpec == null ? null : activationSpec.getKeyStore(), getKeyStore());
     String keyStorePassword =
         defaultValue(
             activationSpec == null ? null : activationSpec.getKeyStorePassword(),
             getKeyStorePassword());
     String keyStoreKeyPassword =
         defaultValue(
             activationSpec == null ? null : activationSpec.getKeyStoreKeyPassword(),
             getKeyStoreKeyPassword());
     ActiveMQSslConnectionFactory sslFactory = (ActiveMQSslConnectionFactory) factory;
     if (trustStore != null) {
       try {
         sslFactory.setTrustStore(trustStore);
       } catch (Exception e) {
         log.warn("Unable to set TrustStore", e);
       }
     }
     if (trustStorePassword != null) {
       sslFactory.setTrustStorePassword(trustStorePassword);
     }
     if (keyStore != null) {
       try {
         sslFactory.setKeyStore(keyStore);
       } catch (Exception e) {
         log.warn("Unable to set KeyStore", e);
       }
     }
     if (keyStorePassword != null) {
       sslFactory.setKeyStorePassword(keyStorePassword);
     }
     if (keyStoreKeyPassword != null) {
       sslFactory.setKeyStoreKeyPassword(keyStoreKeyPassword);
     }
   }
 }
Пример #2
0
  public void testConnectionFactory() throws Exception {
    // Create sample connection factory
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
    factory.setDispatchAsync(true);
    factory.setBrokerURL("vm://test");
    factory.setClientID("test");
    factory.setCopyMessageOnSend(false);
    factory.setDisableTimeStampsByDefault(true);
    factory.setObjectMessageSerializationDefered(true);
    factory.setOptimizedMessageDispatch(false);
    factory.setPassword("pass");
    factory.setUseAsyncSend(true);
    factory.setUseCompression(true);
    factory.setUseRetroactiveConsumer(true);
    factory.setUserName("user");
    factory.getPrefetchPolicy().setQueuePrefetch(777);
    factory.getRedeliveryPolicy().setMaximumRedeliveries(15);
    factory.getRedeliveryPolicy().setBackOffMultiplier((short) 32);

    // Create reference
    Reference ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory);

    // Get object created based on reference
    ActiveMQConnectionFactory temp;
    JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
    temp = (ActiveMQConnectionFactory) refFactory.getObjectInstance(ref, null, null, null);

    // Check settings
    assertEquals(factory.isDispatchAsync(), temp.isDispatchAsync());
    assertEquals(factory.getBrokerURL(), temp.getBrokerURL());
    assertEquals(factory.getClientID(), temp.getClientID());
    assertEquals(factory.isCopyMessageOnSend(), temp.isCopyMessageOnSend());
    assertEquals(factory.isDisableTimeStampsByDefault(), temp.isDisableTimeStampsByDefault());
    assertEquals(
        factory.isObjectMessageSerializationDefered(), temp.isObjectMessageSerializationDefered());
    assertEquals(factory.isOptimizedMessageDispatch(), temp.isOptimizedMessageDispatch());
    assertEquals(factory.getPassword(), temp.getPassword());
    assertEquals(factory.isUseAsyncSend(), temp.isUseAsyncSend());
    assertEquals(factory.isUseCompression(), temp.isUseCompression());
    assertEquals(factory.isUseRetroactiveConsumer(), temp.isUseRetroactiveConsumer());
    assertEquals(factory.getUserName(), temp.getUserName());
    assertEquals(
        factory.getPrefetchPolicy().getQueuePrefetch(),
        temp.getPrefetchPolicy().getQueuePrefetch());
    assertEquals(
        factory.getRedeliveryPolicy().getMaximumRedeliveries(),
        temp.getRedeliveryPolicy().getMaximumRedeliveries());
    assertEquals(
        factory.getRedeliveryPolicy().getBackOffMultiplier(),
        temp.getRedeliveryPolicy().getBackOffMultiplier());
  }