Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8500

ClassCastException when something other than PropertiesComponent is bound to "properties" JNDI name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.13.4
    • 2.14.3, 2.15.1, 2.16.0
    • camel-core
    • None
    • Apache Camel 2.13.4 running on JBoss EAP4

    • Novice

    Description

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

      During start we get the following Error:

      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
      

      Reason
      In our installation, some properties are bound 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.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            cerker Carsten Erker
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: