0 Replies Latest reply on Feb 11, 2010 3:16 AM by slipknot_domagoj.tomljenovic

    JNDI, OSGi, Fuse

    slipknot_domagoj.tomljenovic

      Hi,

       

      Thank You for sharing your time with me.

       

      I used FUSE Integration Designer to create simple maven project.

       

      This project was Camel routing application which scans mails and save attachments in another server directory. Then stored procedure is called. Stored procedure updates database with informations stored in the attachment.

       

      At first, I put jndi.properties and jndi xml into root „src“ directory of application.

      From FUSE Integration Designer everything was worked ok.

       

      Then my admin said that he wants to configure some properties from external file.

       

      I try to add variable classpath entry (pointing to some directory on disk). I put jndi.properties into that dir. In another dir I put jndi.xml with entry pointing to file which contains properties. That solution also worked ok.

       

       

          1. jndi.properties ###

       

      java.naming.factory.initial=org.apache.xbean.spring.jndi.SpringInitialContextFactory

      java.naming.provider.url=file:d:
      temp
      con_fuse
      jndi_xml

       

          1. jndi.xml ###

       

      <bean id="jndi"

      class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"

      factory-method="makeInitialContext">

      <property name="entries">

      <util:map>

      <entry key="fuseConfig" value-ref="jndiEntries" />

      </util:map>

      </property>

      </bean>

       

       

      <bean id="jndiEntries" class="org.springframework.beans.factory.config.MapFactoryBean">

      <property name="sourceMap">

      <map>

      <entry key="properties.file" value="d:/temp/MyMail.properties" />

      </map>

      </property>

      </bean>

       

      Then I build application and create OSGi bundle. It was deployed by putting it in my „C:\progress\fuse-esb-4.1.0.2\deploy“ directory. Just to mention, I also installed fuse-mediation-router-1.6.2.0 and fuse-message-broker-5.3.0.5.

       

      After resolving some dependencies (by deploying needed bundles) I have finally succeeded and component was „Active“ and „Started“.

       

      According to this documentation: (http://fusesource.com/docs/esb/3.3/deploy_guide/DeployESBJNDIConfig.html) I put jndi.properties and jndi.xml into „C:\progress\fuse-esb-4.1.0.2\conf“ directory. After starting ServiceMix console „javax.naming.NameNotFoundException: properties.file…“ was shown.

       

       

       

      This is how I try to lookup in the context.

       

       

       

      InitialContext context = new InitialContext();

      LinkedHashMap hm = (LinkedHashMap) context.lookup("fuseConfig");

      FileInputStream myFile = new FileInputStream((String) hm.get("properties.file"));

      Properties props = new Properties();

      props.load(myFile);

       

      Documentation (http://camel.apache.org/registry.html) says that there is 2 types of registry.

      1. JndiRegistry

      2. ApplicationContextRegistry

       

       

       

      Also it says (http://camel.apache.org/exception-javaxnamingnoinitialcontextexception.html) which problem can arise and how to specify another JNDI provider.

       

      When this code is run:

       

       

      public class RgfiPocRouteBuilder extends RouteBuilder {

      public void configure() {

      .

      .

      .

      System.out.println(getContext().getRegistry().getClass());

      .

      .

      .

       

       

       

      1. in the FUSE Integration Designer it shows:

       

      class org.apache.camel.impl.JndiRegistry

       

      2. bundled in osgi it shows

       

      class org.apache.camel.spring.spi.ApplicationContextRegistry

       

       

       

      My opinion is that jndi.properties was not loaded on ServiceMix console startup.

       

      What I did wrong ?

       

      Please help.

       

      Cheers !

       

      Edited by: slipknot on Feb 11, 2010 8:15 AM