Carsten Erker created CAMEL-8500:
------------------------------------

             Summary: ClassCastException when something other than 
PropertiesComponent is bound to "properties" JNDI name
                 Key: CAMEL-8500
                 URL: https://issues.apache.org/jira/browse/CAMEL-8500
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.13.4
         Environment: Apache Camel 2.13.4 running on JBoss EAP4
            Reporter: Carsten Erker


*Problem:*
When starting the DefaultCamelContext, Camel tries to get a PropertiesComponent 
object from JNDI under the name "properties" (which is hard-coded in 
DefaultCamelContextlookupPropertiesComponent() resp. 
CamelContextHelperlookupPropertiesComponent() in newer Camel versions).

During start we get the following Error:
{code}
org.apache.camel.NoSuchBeanException: Found bean: properties in JNDI Context: 
javax.naming.InitialContext@a37a18 of type: org.jnp.interfaces.NamingContext 
expected type was: class 
org.apache.camel.component.properties.PropertiesComponent
        at 
org.apache.camel.impl.JndiRegistry.lookupByNameAndType(JndiRegistry.java:61)
        at 
org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByNameAndType(PropertyPlaceholderDelegateRegistry.java:63)
        at 
org.apache.camel.impl.DefaultCamelContext.lookupPropertiesComponent(DefaultCamelContext.java:2788)
        at 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1834)
        at 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1716)
        at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
        at 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1684)
        at 
de.bwb.ubi.vs.automat.mbean.CamelStarter.startService(CamelStarter.java:21)
        at 
org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
[...]
Caused by: java.lang.ClassCastException
        at java.lang.Class.cast(Class.java:2999)
        at 
org.apache.camel.impl.JndiRegistry.lookupByNameAndType(JndiRegistry.java:57)
        ... 145 more
{code}

*Reason:*
Our application bind some properties to the name "properties/..." in the JNDI 
global namespace.

*Proposed Solution*
Camel can manage if it finds nothing under the JNDI name, the problem is just 
finding something different than the expected PropertiesComponent instance. 
Instead of calling JndiRegistry.lookupByNameAndType(String, Class) -- this is 
where the cast fails -- we should call JndiRegistry.lookupByName(String name). 
If an instance other than a PropertiesComponent is returned here, we should go 
on as if nothing was found in the JNDI lookup.

I can provide a pull request for this.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to