Dear Camel Technologists,

I am at my wits end figuring out what is wrong with my code as I have been
now trying for more than a week to dynamically update the
'exchangeAuthenticator' bean values by unbinding and then binding it to the
'DefaultRegistry' in 'CamelContext'.

Please help me as to what I am doing wrong below:

ublic void updateAuthenticator() {
   String tenantId = emailConfigBean.getTenantId();
   String clientId = emailConfigBean.getClientId();
   String clientSecret = emailConfigBean.getClientSecret();
   String wsAdapterMailBox = emailConfigBean.getWSAdapterMailBox();

   try {
    log.info("@#$@#$@#$ trying new default registry...");
       log.info("@#$@#%$@#$ Updating authenticator bean: tenantId {}
clientId {} clientSecret {} userName {}", tenantId,
               clientId, clientSecret, wsAdapterMailBox);
       MicrosoftExchangeOnlineOAuth2MailAuthenticator
newExchangeAuthenticator = new
MicrosoftExchangeOnlineOAuth2MailAuthenticator(
               tenantId, clientId, clientSecret, wsAdapterMailBox);
       // Get the registry
       DefaultRegistry defaultRegistry  = (DefaultRegistry)
camelContext.getRegistry();

       // Unbind the existing 'exchangeAuthenticator' bean
MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator =
(MicrosoftExchangeOnlineOAuth2MailAuthenticator) defaultRegistry
.lookupByName("exchangeAuthenticator");
       if (null != exchangeAuthenticator) {
        log.info("@#$@#$@#$ removing the existing
exchangeAuthenticator....");
           defaultRegistry.unbind("exchangeAuthenticator");
       }

       // Bind the new 'exchangeAuthenticator' bean
       defaultRegistry.bind("exchangeAuthenticator",
newExchangeAuthenticator);
       log.info("@#$@#$@#$ bound a new bean exchangeAuthenticator....");
       defaultRegistry.setCamelContext(camelContext);
       log.info("@#$@#$@#$ now set the default registry to camel context
back");

   } catch (Exception e) {
       log.error("Exception in updating authenticator bean: {}",
e.getMessage());
   }
}

Regards,
Dipak.

Reply via email to