You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by rpcat <rp...@gmail.com> on 2015/09/21 07:27:18 UTC

how to get loginConfig into standalone camel salesforce component

My standalone camel instance needs a salesforce component. It has:

public class Driver 
{
	private Main main;
	static final Logger log = LoggerFactory.getLogger(Driver.class);

	public void startDriver() throws Exception
	{
		main = new Main();
		main.enableHangupSupport();	//so you can press ctrl-c to terminate the jvm
...
                SalesforceLoginConfig loginConfig = new
SalesforceLoginConfig(
                    loginUrl, clientId, clientSecret, userName, password,
lazyLogin);

                SalesforceComponent component = new SalesforceComponent();
                component.setLoginConfig(loginConfig);
        
                component.setPackages(new
String[]{Program_Schedule__c.class.getPackage().getName()    });

                main.getOrCreateCamelContext().addComponent(componentName,
component);		
		main.addRouteBuilder(new RoutePollSalesforce());
		
but when i start up the route there's no loginConfig:

Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create
component: salesforce
        at
org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:400)
        at
org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:376)
        at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:548)
        ... 25 more
Caused by: java.lang.IllegalArgumentException: loginConfig must be specified
        at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:293)
        at
org.apache.camel.component.salesforce.SalesforceComponent.doStart(SalesforceComponent.java:175)
        at
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at
org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2885)
        at
org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:395)
        ... 27 more
[                      Thread-0] MainSupport$HangupInterceptor  INFO 
Received hang up - stopping the main instance.

suggestions would be greatly appreciated.




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

Re: how to get loginConfig into standalone camel salesforce component

Posted by rpcat <rp...@gmail.com>.
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.

Re: how to get loginConfig into standalone camel salesforce component

Posted by rpcat <rp...@gmail.com>.
it's not getting the salesforce component into the camel context



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

Re: how to get loginConfig into standalone camel salesforce component

Posted by rpcat <rp...@gmail.com>.
Yes, I am referencing the tests. They don't include how to make it work in a
standalone camel. The question is how to get the instance of
SalesforceComponent in the CamelContext of the instance of standalone
org.apache.camel.main.Main. So i've done it in my RouteBuilder configure()
where i can add the SalesforceComponent instance to the context in the
route: 

public class RoutePollSalesforce extends RouteBuilder {
...
    public void configure() throws Exception {

...

        SalesforceComponent component = new SalesforceComponent();
        component.setLoginConfig(this.loginConfig);
        
        component.setPackages(new String[]{
        		Program_Schedule__c.class.getPackage().getName()
        });

	this.getContext().addComponent("salesforce", component);
		
	from("direct:pollSalesforce")
	.to("salesforce:query?q=SELECT+Id,Name+FROM+Program_Schedule__c");
  }
}

and now the complaint is this, which I don't understand yet:

Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
Failed to create route route4 at: >>>
To[salesforce:query?q=SELECT+Id,Name+FROM+Program_Schedule__c] <<< in route:
Route(route4)[[From[direct:pollSalesforce]] -> [To[salesforc... because of
Failed to resolve endpoint:
salesforce://query?q=SELECT+Id%2CName+FROM+Program_Schedule__c due to:
Failed to resolve endpoint:
salesforce://query?q=SELECT+Id%2CName+FROM+Program_Schedule__c due to: There
are 1 parameters that couldn't be set on the endpoint. Check the uri if the
parameters are spelt correctly and that they are properties of the endpoint.
Unknown parameters=[{q=SELECT Id,Name FROM Program_Schedule__c}]
        at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1028)
        at
org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:185)
        at
org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:841)
        at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:2911)
        at
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2634)
        at
org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:167)
        at
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2483)
        at
org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2479)
        at
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2502)
        at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2479)
        at
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2448)
        at org.apache.camel.main.Main.doStart(Main.java:124)
        at
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at org.apache.camel.main.MainSupport.run(MainSupport.java:150)
        at com.disney.datg.Driver.startDriver(Driver.java:77)
        at com.disney.datg.Driver.main(Driver.java:88)





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

Re: how to get loginConfig into standalone camel salesforce component

Posted by Christian Müller <ch...@gmail.com>.
Did you checked the tests for this component?

Best,
Christian
Am 21.09.2015 07:27 schrieb "rpcat" <rp...@gmail.com>:

> My standalone camel instance needs a salesforce component. It has:
>
> public class Driver
> {
>         private Main main;
>         static final Logger log = LoggerFactory.getLogger(Driver.class);
>
>         public void startDriver() throws Exception
>         {
>                 main = new Main();
>                 main.enableHangupSupport();     //so you can press ctrl-c
> to terminate the jvm
> ...
>                 SalesforceLoginConfig loginConfig = new
> SalesforceLoginConfig(
>                     loginUrl, clientId, clientSecret, userName, password,
> lazyLogin);
>
>                 SalesforceComponent component = new SalesforceComponent();
>                 component.setLoginConfig(loginConfig);
>
>                 component.setPackages(new
> String[]{Program_Schedule__c.class.getPackage().getName()    });
>
>                 main.getOrCreateCamelContext().addComponent(componentName,
> component);
>                 main.addRouteBuilder(new RoutePollSalesforce());
>
> but when i start up the route there's no loginConfig:
>
> Caused by: org.apache.camel.RuntimeCamelException: Cannot auto create
> component: salesforce
>         at
>
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:400)
>         at
>
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:376)
>         at
>
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:548)
>         ... 25 more
> Caused by: java.lang.IllegalArgumentException: loginConfig must be
> specified
>         at
> org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:293)
>         at
>
> org.apache.camel.component.salesforce.SalesforceComponent.doStart(SalesforceComponent.java:175)
>         at
> org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
>         at
>
> org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2885)
>         at
>
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.java:395)
>         ... 27 more
> [                      Thread-0] MainSupport$HangupInterceptor  INFO
> Received hang up - stopping the main instance.
>
> suggestions would be greatly appreciated.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/how-to-get-loginConfig-into-standalone-camel-salesforce-component-tp5771694.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>