It's working with a lazy init of the salesforce component in the route. I
couldn't get the camel context to recognize that the component was added in
main or in the route builder, but it works from a processor in the route. In
the processor the component has to be created with the camel context from
the exchange, started and added to the exchange camel context. If there's a
more elegant way, certainly I'd like to know.

public class Driver 
{
        private Main main;

        public void startDriver() throws Exception
        {
                main = new Main();
                main.enableHangupSupport();     //so you can press ctrl-c to 
terminate the jvm

                ...         
                // get salesforce login credentials from config 
                ...
                
        SalesforceLoginConfig loginConfig = new SalesforceLoginConfig(
            loginUrl, clientId, clientSecret, userName, password,
lazyLogin);

        main.bind("loginConfig", loginConfig);
                main.addRouteBuilder(new RoutePollSalesforce());
        main.run();

        if(main.isStopping()){
            log.info("main is stopping...");
        }
        }
        public static void main(String[] args) throws Exception
        {
                Driver driver = new Driver();
                driver.startDriver();
        }
}

In a RouteBuilder:

        // lazy init salesforce component  
                from("direct:pollSalesforce")
                .process(new SalesforceProcessor())


public class SalesforceProcessor implements Processor
{

        @Override
        public void process(Exchange exchange) throws Exception
        {
                SalesforceLoginConfig loginConfig = 
                                (SalesforceLoginConfig)
exchange.getContext().getRegistry().lookupByName("loginConfig");
        
                SalesforceComponent component;
                component =
(SalesforceComponent)exchange.getContext().getComponent("salesforce",
false);

                if (null == component){
                  component = new SalesforceComponent(exchange.getContext());
                  component.setPackages(new String[]{
                                
QueryRecordsSchedule__c.class.getPackage().getName()  });
                  component.setLoginConfig(loginConfig);
                  component.start();
                  exchange.getContext().addComponent("salesforce", component);
                }

                ProducerTemplate template =
exchange.getContext().createProducerTemplate();

                QueryRecordsSchedule__c queryRecords = template.requestBody
                                ("salesforce:query?sObjectQuery=SELECT Name, Id 
from
Schedule__c&sObjectClass="
                                        + 
QueryRecordsSchedule__c.class.getName(),
                                        null,
                                        QueryRecordsSchedule__c.class);

                template.sendBody(queryRecords);
        }
}



--
View this message in context: 
http://camel.465427.n5.nabble.com/how-to-get-loginConfig-into-standalone-camel-salesforce-component-tp5771694p5771996.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to