Problem creating seda endpoint with queue size

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem creating seda endpoint with queue size

ariekenb
I'm running FUSE ESB 4.2.0-fuse-01-00 with it's default version of Camel 2.2.  I'm trying to do something simple: I have a camel context defined in a spring file:

        <camel:camelContext
                id="aaron-test">
        </camel:camelContext>

I inject it into a bean implementing CamelContextAware and try to do this:

                        camelContext.addComponent("activemq", ActiveMQComponent
                                        .activeMQComponent("tcp://localhost:61616"));

                        camelContext.addRoutes(new RouteBuilder() {

                                public void configure() throws Exception {
                                        from("activemq:queue:test.queue").to(
                                                        "vm:eventMessageEndpoint?size=220000");
                                }

                        });

Often (but not always) I get this exception:

 Failed to resolve endpoint: vm://eventMessageEndpoint?size=220000 due to: null
        at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:446)
        at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:46)
        at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:158)
        at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:113)
        at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:119)
        at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:63)
        at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:57)
        at org.apache.camel.model.ToDefinition.createProcessor(ToDefinition.java:87)
        at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:325)
        at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:137)
        at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:690)
        ... 22 more
Caused by: java.lang.NullPointerException
        at org.apache.camel.component.seda.SedaComponent.createQueue(SedaComponent.java:46)
        at org.apache.camel.component.vm.VmComponent.getBlockingQueue(VmComponent.java:53)
        at org.apache.camel.component.vm.VmComponent.createEndpoint(VmComponent.java:43)
        at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:80)
        at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:425)
        ... 32 more



So SedaComponent.createQueue is throwing NPE.  This happens because getAndRemoveParameter() is returning null for the size parameter, which happens because CamelContextHelper.convertTo() returns null.

Why does this happen - it seems to be because DefaultTypeConverter does not have any type converters registered on it.  This means it is not able to convert the string parameter "220000" to an Integer.  This is due to these earlier exceptions when the camel context was created:

16:41:07,220 | DEBUG | ExtenderThread-6 | DefaultPackageScanClassResolver  | .DefaultPackageScanClassResolver  280 | Cannot read entries in url: bundleresource://50.fwk1545595021/org/apache/camel/converter/
java.net.MalformedURLException: no protocol: /org/apache/camel/converter/
        at java.net.URL.<init>(URL.java:567)
        at java.net.URL.<init>(URL.java:464)
        at java.net.URL.<init>(URL.java:413)
        at org.apache.camel.impl.DefaultPackageScanClassResolver.find(DefaultPackageScanClassResolver.java:264)
        at org.apache.camel.impl.DefaultPackageScanClassResolver.find(DefaultPackageScanClassResolver.java:180)
        at org.apache.camel.impl.DefaultPackageScanClassResolver.findAnnotated(DefaultPackageScanClassResolver.java:100)
        at org.apache.camel.impl.converter.AnnotationTypeConverterLoader.load(AnnotationTypeConverterLoader.java:63)
        at org.apache.camel.impl.converter.DefaultTypeConverter.loadTypeConverters(DefaultTypeConverter.java:361)
        at org.apache.camel.impl.converter.DefaultTypeConverter.doStart(DefaultTypeConverter.java:384)
        at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:53)
        at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:49)
        at org.apache.camel.impl.DefaultCamelContext.startServices(DefaultCamelContext.java:1174)

This looks like this bug (https://issues.apache.org/activemq/browse/CAMEL-2663), which resulted in the camel-eclipse class resolver being written in camel 2.3 (not available to me in camel 2.2).  

I have found an ugly workaround, which is to manually force a String to Integer type converter to be registered on the camel context:

                        ((DefaultTypeConverter) camelContext.getTypeConverter())
                                        .addTypeConverter(Integer.class, String.class,
                                                        new StaticMethodTypeConverter(ObjectConverter.class
                                                                        .getMethod("toInteger", Object.class)));


What is the correct fix for this?  Is it necessary to use the new camel-eclipse class resolver with FUSE ESB?
Reply | Threaded
Open this post in threaded view
|

Re: Problem creating seda endpoint with queue size

Willem.Jiang
Administrator
It's not easy to make Camel work with all OSGi platform rightly.
I just went through the Camel OSGi related code, it uses another method
to load converter class, and it should be fine.

I don't know how you inject the camel context, if this camel context is
not replace its DefaultPackageScanClassResolver to
OSGiPackageScanClassResolver, you may hit this kind of issue.

Can you create a JIRA a submit your test case with it?
So I can dig the code to see if it is resolved in Camel trunk.

Willem

ariekenb wrote:

> I'm running FUSE ESB 4.2.0-fuse-01-00 with it's default version of Camel 2.2.
> I'm trying to do something simple: I have a camel context defined in a
> spring file:
>
> <camel:camelContext
> id="aaron-test">
> </camel:camelContext>
>
> I inject it into a bean implementing CamelContextAware and try to do this:
>
> camelContext.addComponent("activemq", ActiveMQComponent
> .activeMQComponent("tcp://localhost:61616"));
>
> camelContext.addRoutes(new RouteBuilder() {
>
> public void configure() throws Exception {
> from("activemq:queue:test.queue").to(
> "vm:eventMessageEndpoint?size=220000");
> }
>
> });
>
> Often (but not always) I get this exception:
>
>  Failed to resolve endpoint: vm://eventMessageEndpoint?size=220000 due to:
> null
>         at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:446)
>         at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:46)
>         at
> org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:158)
>         at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:113)
>         at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:119)
>         at
> org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:63)
>         at
> org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:57)
>         at
> org.apache.camel.model.ToDefinition.createProcessor(ToDefinition.java:87)
>         at
> org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:325)
>         at
> org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:137)
>         at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:690)
>         ... 22 more
> Caused by: java.lang.NullPointerException
>         at
> org.apache.camel.component.seda.SedaComponent.createQueue(SedaComponent.java:46)
>         at
> org.apache.camel.component.vm.VmComponent.getBlockingQueue(VmComponent.java:53)
>         at
> org.apache.camel.component.vm.VmComponent.createEndpoint(VmComponent.java:43)
>         at
> org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:80)
>         at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:425)
>         ... 32 more
>
>
>
> So SedaComponent.createQueue is throwing NPE.  This happens because
> getAndRemoveParameter() is returning null for the size parameter, which
> happens because CamelContextHelper.convertTo() returns null.
>
> Why does this happen - it seems to be because DefaultTypeConverter does not
> have any type converters registered on it.  This means it is not able to
> convert the string parameter "220000" to an Integer.  This is due to these
> earlier exceptions when the camel context was created:
>
> 16:41:07,220 | DEBUG | ExtenderThread-6 | DefaultPackageScanClassResolver  |
> .DefaultPackageScanClassResolver  280 | Cannot read entries in url:
> bundleresource://50.fwk1545595021/org/apache/camel/converter/
> java.net.MalformedURLException: no protocol: /org/apache/camel/converter/
>         at java.net.URL.<init>(URL.java:567)
>         at java.net.URL.<init>(URL.java:464)
>         at java.net.URL.<init>(URL.java:413)
>         at
> org.apache.camel.impl.DefaultPackageScanClassResolver.find(DefaultPackageScanClassResolver.java:264)
>         at
> org.apache.camel.impl.DefaultPackageScanClassResolver.find(DefaultPackageScanClassResolver.java:180)
>         at
> org.apache.camel.impl.DefaultPackageScanClassResolver.findAnnotated(DefaultPackageScanClassResolver.java:100)
>         at
> org.apache.camel.impl.converter.AnnotationTypeConverterLoader.load(AnnotationTypeConverterLoader.java:63)
>         at
> org.apache.camel.impl.converter.DefaultTypeConverter.loadTypeConverters(DefaultTypeConverter.java:361)
>         at
> org.apache.camel.impl.converter.DefaultTypeConverter.doStart(DefaultTypeConverter.java:384)
>         at
> org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:53)
>         at
> org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:49)
>         at
> org.apache.camel.impl.DefaultCamelContext.startServices(DefaultCamelContext.java:1174)
>
> This looks like this bug
> (https://issues.apache.org/activemq/browse/CAMEL-2663), which resulted in
> the camel-eclipse class resolver being written in camel 2.3 (not available
> to me in camel 2.2).  
>
> I have found an ugly workaround, which is to manually force a String to
> Integer type converter to be registered on the camel context:
>
> ((DefaultTypeConverter) camelContext.getTypeConverter())
> .addTypeConverter(Integer.class, String.class,
> new StaticMethodTypeConverter(ObjectConverter.class
> .getMethod("toInteger", Object.class)));
>
>
> What is the correct fix for this?  Is it necessary to use the new
> camel-eclipse class resolver with FUSE ESB?

Reply | Threaded
Open this post in threaded view
|

Re: Problem creating seda endpoint with queue size

ariekenb
Willem -

I think I have found the source of my problem and a better fix.

I am creating the camel context in a spring XML file.  I had FUSE ESB in a state where both camel-spring and camel-spring-osgi bundles were loaded in the container.

When both camel-spring and camel-spring-osgi bundles are loaded, sometimes when I load my bundle my camel context is created with OSGiPackageScanClassResolver and things work correctly.  Other times my camel context is created with DefaultPackageScanClassResolver and I get the exceptions below, and the NPE from SedaComponent.createQueue.

If I do not load camel-spring and only load camel-spring-osgi, things seem to always work.  My camel context is always created with OSGiPackageScanClassResolver and I do not get any exceptions.

So loading both camel-spring and camel-spring-osgi seems to confuse things and cause unpredictable behavior.  Is this expected?  Is the correct solution to never use camel-spring in an OSGi container?

Thanks,
Aaron
Reply | Threaded
Open this post in threaded view
|

Re: Problem creating seda endpoint with queue size

Willem.Jiang
Administrator
Hi,

Camel 2.4.0, we don't ship the camel-spring-osgi anymore, and
camel-spring support the OSGi out of box by Guillaume's great enhancement.

Please try out the latest Fuse ESB released for it.

Willem

ariekenb wrote:

> Willem -
>
> I think I have found the source of my problem and a better fix.
>
> I am creating the camel context in a spring XML file.  I had FUSE ESB in a
> state where both camel-spring and camel-spring-osgi bundles were loaded in
> the container.
>
> When both camel-spring and camel-spring-osgi bundles are loaded, sometimes
> when I load my bundle my camel context is created with
> OSGiPackageScanClassResolver and things work correctly.  Other times my
> camel context is created with DefaultPackageScanClassResolver and I get the
> exceptions below, and the NPE from SedaComponent.createQueue.
>
> If I do not load camel-spring and only load camel-spring-osgi, things seem
> to always work.  My camel context is always created with
> OSGiPackageScanClassResolver and I do not get any exceptions.
>
> So loading both camel-spring and camel-spring-osgi seems to confuse things
> and cause unpredictable behavior.  Is this expected?  Is the correct
> solution to never use camel-spring in an OSGi container?
>
> Thanks,
> Aaron