Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
Hi Camel Experts, I am newbie to Apache Camel and was doing a hands-on tutorial to create a custom component. That's when I stumbled on this as to why DefaultEndpoint.createEndpointUri() is not an abstract method, even when it has to be overwritten. The implementation of this method in the parent class - DefaultEndpoint- returns null: /** * A factory method to lazily create the endpointUri if none is specified */ protected String createEndpointUri() { return null; } My custom endpoint was extending the DefaultEndpoint and as a first step I only over-rode the abstract method. This led me to the following exception on context start up. My camel context is embedded in tomcat: java.lang.IllegalArgumentException: endpointUri is not specified and com.kronos.prince.camel.endpoint.MyJDBCEndpoint does not implement createEndpointUri() to create a default value at org.apache.camel.impl.DefaultEndpoint.getEndpointUri(DefaultEndpoint.java:154) at org.apache.camel.impl.DefaultEndpoint.toString(DefaultEndpoint.java:139) at java.lang.String.valueOf(String.java:2854) at java.lang.StringBuilder.append(StringBuilder.java:128) at org.apache.camel.impl.EventDrivenConsumerRoute.toString(EventDrivenConsumerRoute.java:50) at org.apache.camel.management.mbean.ManagedRoute.(ManagedRoute.java:62) at org.apache.camel.management.mbean.ManagedSuspendableRoute.(ManagedSuspendableRoute.java:30) at org.apache.camel.management.DefaultManagementObjectStrategy.getManagedObjectForRoute(DefaultManagementObjectStrategy.java:119) at org.apache.camel.management.DefaultManagementLifecycleStrategy.onRoutesAdd(DefaultManagementLifecycleStrategy.java:523) at org.apache.camel.impl.RouteService.warmUp(RouteService.java:156) at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:2109) at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:2039) at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1827) at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1699) at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1544) at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1512) at org.apache.camel.component.servletlistener.CamelServletContextListener.contextInitialized(CamelServletContextListener.java:162) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) A search on the net didn't help much to resolve this problem. So, i dived int the camel's source code and found out that most of the endpoints like JDBCEndpoint, JMSEndpoint override this method. Doing the same in my custom endpoint fixed the problem. Am I missing something here and there is some other way to over come the above mentioned exception. ___ Thks & brgds P Manchanda Mobile: +91-9811210374
Re: Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
Very often the component creates the endpoint using an uri, and therefore you have the uri already. But if you create the endpoint manually without a component, and just configure the endpoint using getter/setter, then there is no uri per see. And then you can implement that method to construct the uri to use. On Thu, Nov 21, 2013 at 6:48 AM, P Manchanda wrote: > Hi Camel Experts, > > I am newbie to Apache Camel and was doing a hands-on tutorial to create a > custom component. That's when I stumbled on this as to why > DefaultEndpoint.createEndpointUri() is not an abstract method, even when it > has to be overwritten. > > The implementation of this method in the parent class - DefaultEndpoint- > returns null: > > /** > * A factory method to lazily create the endpointUri if none is specified > */ > protected String createEndpointUri() { > return null; > } > > > My custom endpoint was extending the DefaultEndpoint and as a first step I > only over-rode the abstract method. This led me to the following exception on > context start up. My camel context is embedded in tomcat: > > java.lang.IllegalArgumentException: endpointUri is not specified and > com.kronos.prince.camel.endpoint.MyJDBCEndpoint does not implement > createEndpointUri() to create a default value > at > org.apache.camel.impl.DefaultEndpoint.getEndpointUri(DefaultEndpoint.java:154) > at > org.apache.camel.impl.DefaultEndpoint.toString(DefaultEndpoint.java:139) > at java.lang.String.valueOf(String.java:2854) > at java.lang.StringBuilder.append(StringBuilder.java:128) > at > org.apache.camel.impl.EventDrivenConsumerRoute.toString(EventDrivenConsumerRoute.java:50) > at > org.apache.camel.management.mbean.ManagedRoute.(ManagedRoute.java:62) > at > org.apache.camel.management.mbean.ManagedSuspendableRoute.(ManagedSuspendableRoute.java:30) > at > org.apache.camel.management.DefaultManagementObjectStrategy.getManagedObjectForRoute(DefaultManagementObjectStrategy.java:119) > at > org.apache.camel.management.DefaultManagementLifecycleStrategy.onRoutesAdd(DefaultManagementLifecycleStrategy.java:523) > at org.apache.camel.impl.RouteService.warmUp(RouteService.java:156) > at > org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:2109) > at > org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:2039) > at > org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1827) > at > org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1699) > at > org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1544) > at > org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) > > at > org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1512) > at > org.apache.camel.component.servletlistener.CamelServletContextListener.contextInitialized(CamelServletContextListener.java:162) > at > org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) > at > org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) > at > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) > at > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) > at > org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) > at > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618) > > at > org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100) > at > org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618) > at > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) > at java.util.concurrent.FutureTask.run(FutureTask.java:166) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.java:722) > > A search on the net didn't help much to resolve this problem. So, i dived int > the camel's source code and found out that most of the endpoints like > JDBCEndpoint, JMSEndpoint override this method. > > Doing the same in my custom endpoint fixed the problem. Am I missing > something here and there is some other way to over come the above mentioned > exception. > > ___ > Thks & brgds > P Manchanda > Mobile: +91-9811210374 -- Claus Ibsen - Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen
Re: Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
Thanks Claus for quick response. Claus Ibsen-2 wrote > Very often the component creates the endpoint using an uri, and therefore > you have the uri already. Can you point me to some sample components that create the endpoint using an uri -- View this message in context: http://camel.465427.n5.nabble.com/Wondering-why-DefaultEndpoint-createEndpointUri-is-not-an-abstract-method-tp5743595p5743603.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
Every component we ship does that, as they have a xxxComponent doing that. For example LogComponent from camel-core etc. On Thu, Nov 21, 2013 at 10:12 AM, manchandap wrote: > Thanks Claus for quick response. > > > Claus Ibsen-2 wrote >> Very often the component creates the endpoint using an uri, and therefore >> you have the uri already. > > Can you point me to some sample components that create the endpoint using an > uri > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Wondering-why-DefaultEndpoint-createEndpointUri-is-not-an-abstract-method-tp5743595p5743603.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen
Re: Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
Thanks for your continued support on this Claus, I think a better way to create an Endpoint is to use the following constructor rather then overriding the createEndpointUri() method. This would help to keep the same info at one place. DefaultEndpoint(String endpointUri, Component component) Constructs a fully-initialized DefaultEndpoint instance. -- View this message in context: http://camel.465427.n5.nabble.com/Wondering-why-DefaultEndpoint-createEndpointUri-is-not-an-abstract-method-tp5743595p5743608.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Wondering why DefaultEndpoint.createEndpointUri() is not an abstract method
If you want to create a custom Camel component, then it can be a good idea to use the Maven archetype tooling for that, which creates a sample component all setup and ready to use as base for developing the component. http://camel.apache.org/camel-maven-archetypes.html On Thu, Nov 21, 2013 at 11:25 AM, manchandap wrote: > Thanks for your continued support on this Claus, > > I think a better way to create an Endpoint is to use the following > constructor rather then overriding the createEndpointUri() method. This > would help to keep the same info at one place. > > DefaultEndpoint(String endpointUri, Component component) > Constructs a fully-initialized DefaultEndpoint instance. > > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Wondering-why-DefaultEndpoint-createEndpointUri-is-not-an-abstract-method-tp5743595p5743608.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen