/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.amqphub.spring.boot.jms.example;

import org.amqphub.spring.boot.jms.autoconfigure.AMQP10JMSConnectionFactoryCustomizer;
import org.apache.qpid.jms.policy.JmsDefaultMessageIDPolicy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;

/**
 * Example showing how to customize the configuration of the ConnectionFactory being
 * used in the application.
 */
@SpringBootApplication
@EnableJms
public class CustomConfigurationExample {

    public static void main(String[] args) {
        SpringApplication.run(CustomConfigurationExample.class, args);
    }

    /**
     * Uses a configuration annotation to define an AMQP10JMSConnectionFactoryCustomizer
     * override that configures the Qpid JMS ConnectionFactory used by the starter to match
     * requirements of the user.  In this case the login credentials are set and the client
     * is configured to use UUID's as the JMS Message ID values.
     */
    @Configuration
    protected static class CustomAMQP10JMSClientConfiguration {

        @Bean
        public AMQP10JMSConnectionFactoryCustomizer myAMQP10Configuration() {
            return (factory) -> {
                factory.setUsername("admin");
                factory.setPassword("admin");

                ((JmsDefaultMessageIDPolicy) factory.getMessageIDPolicy()).setMessageIDType("UUID");
            };
        }
    }
}

@@ -933,69 +933,8 @@
 er;%0A
-import org.apache.qpid.jms.policy.JmsDefaultMessageIDPolicy;%0A
 impo
@@ -1806,87 +1806,108 @@
  set
- and the client%0A     * is configured to use UUID's as the JMS Message ID values
+, this could be%0A     * done in cases where credentials are retrieved from some external resource etc
 .%0A  
@@ -2214,17 +2214,16 @@
 dmin%22);%0A
-%0A
         
@@ -2234,92 +2234,237 @@
     
-((JmsDefaultMessageIDPolicy) factory.getMessageIDPolicy()).setMessageIDType(%22UUID%22);
+factory.setPopulateJMSXUserID(true);%0A%0A                // Other options such as custom SSLContext can be applied here%0A                // where they might otherwise be difficult to set via properties%0A                // file or URI.
 %0A   

Simplify the customized factory example