cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI in Tomcat unavailable in Alfresco

rdanner
Champ in-the-making
Champ in-the-making
Just thought this might be important to some of you.

Due to the packaging of the naming-*jar files in the Alfresco war file it is not possible to get the java:comp/env context.

If you remove these jars things work as they would typically with Tomcat.  Note – other things may break. I have discussed it with a few folks and the impact of removing these jars is that LDAP related functionality will break.  I have not confirmed this.
23 REPLIES 23

vijay_alfresco
Champ in-the-making
Champ in-the-making
Today I have configured Alfresco 2.1 (Tomcat Version) using JNDI Datasource. The procedure is simple as follows and uses mysql database

1. Update $TOMAT_HOME$\server.xml with the following within

<GlobalNamingResources>
<Resource name="jdbc/alf_global" auth="Container" scope="Shareable"
                 type="javax.sql.DataSource"
       maxActive="100" maxIdle="30" maxWait="10000"
       username="alfresco" password="alfresco"
                 driverClassName="org.gjt.mm.mysql.Driver"
       url="jdbc:mysql:///alfresco"/>
…………………………………………………………
<\GlobalNamingResources>

2. Update $TOMCAT_HOME$\context.xml with the following


<Context path="/alfresco" docBase="alfresco"
         debug="5" reloadable="true" crossContext="true">

    <!– Default set of monitored resources –>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
   
    <!– Uncomment this to disable session persistence across Tomcat
    restarts –>
    <!–
    <Manager pathname="" />
    –>

    <!– Uncomment this to enable Comet connection tacking (provides
     events on session expiration as well as webapp lifecycle) –>
    <!–
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    –>

   <ResourceLink name="jdbc/alfresco" global="jdbc/alf_global" type="javax.sql.DataSource"/>
</Context>

3. Update $TOMCAT_HOME$\webapps\alfresco\WEB-INF\web.xml at the end with the following

  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/alfresco</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

4. Update $TOMCAT_HOME$\webapps\alfresco\WEB-INF\classes\alfresco\core-services-context.xml
with the following

    <!– Datasource bean –>
    <!–<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName">
            <value>${db.driver}</value>
        </property>
        <property name="url">
            <value>${db.url}</value>
        </property>
        <property name="username">
            <value>${db.username}</value>
        </property>
        <property name="password">
            <value>${db.password}</value>
        </property>
        <property name="initialSize" >
            <value>${db.pool.initial}</value>
        </property>
        <property name="maxActive" >
            <value>${db.pool.max}</value>
        </property>
        <property name="defaultAutoCommit" >
            <value>false</value>
        </property>
    </bean>–>
   
   <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/alfresco"/>
   </bean>
Actually you are commenting the BasicDataSource and adding JndiObjectFactoryBean

5. Remove naming-factory.jar and naming-resources.jar from the
   lib $TOMCAT_HOME$\webapps\alfresco\WEB-INF\lib

these 2 jar files are causing problems when initiating java:comp initial context. These jars are used to connect to a remote resource like LDAP..
etc. I have seen many posts having problems with java:comp context,
I think these are due these jar files, please clarify me.

6. Now run your alfresco…

Please update me your experiences

Thanks,
Vijay

bangu
Champ in-the-making
Champ in-the-making
Just thought this might be important to some of you.

Due to the packaging of the naming-*jar files in the Alfresco war file it is not possible to get the java:comp/env context.

If you remove these jars things work as they would typically with Tomcat.  Note – other things may break. I have discussed it with a few folks and the impact of removing these jars is that LDAP related functionality will break.  I have not confirmed this.

hema
Champ in-the-making
Champ in-the-making
Hi Russ,

I see that the links on Jira #1131 are not accessible anymore.
Is there a way to get JNDI patch.
I am currently using alfresco 2.0 as 2.1 version of email listener is still not out. And I see from forums that JNDI works fine on 2.0.

Can you please let me know how to get the alfresco-jcr-jndi-v5.zip.

Thanks very much,
Hema

rdanner
Champ in-the-making
Champ in-the-making
Hi Russ,

I see that the links on Jira #1131 are not accessible anymore.
Is there a way to get JNDI patch.
I am currently using alfresco 2.0 as 2.1 version of email listener is still not out. And I see from forums that JNDI works fine on 2.0.

Can you please let me know how to get the alfresco-jcr-jndi-v5.zip.

Thanks very much,
Hema

Hema are you looking to make JNDI work or are you looking to get JCR or both?

JNDI works when you remove the apache naming jars from Alfresco but I caution you, LDAP functionality may break

If you are looking to push JCR in to JNDI and then pick it up with another application:

I think i can put this code up in the JCR-RMI area:  If you are thinking about this here are some thoughts:

- You need to remove the JCR api from alfresco and put it in the shared classloader (you need to establish the JCR api as common to both apps)
- You need spring to push the JCR implementation up in to JNDI

I like the reference to the JCR repository to be a Proxy because I want some JCR implementation available even if alfresco has not started.  If you are going to take this approach you need to consider that the consumer application may start before alfresco.  We have this scenario which means we also need a small component that manages initialization of the server.

If you are using JBOSS you can use the MBeans management capability to manage start up order dependency.  If you are using tomcat you can probably do the same thing but I've haven't tried it with the JMX components.

hema
Champ in-the-making
Champ in-the-making
If you are looking to push JCR in to JNDI and then pick it up with another application:

I think i can put this code up in the JCR-RMI area: If you are thinking about this here are some thoughts:

- You need to remove the JCR api from alfresco and put it in the shared classloader (you need to establish the JCR api as common to both apps)
- You need spring to push the JCR implementation up in to JNDI


Thanks Russ for a very fast reply.

Yes, you are absolutely right. I want to use JNDI for remote access from my custom- application. I use only JCR api in my application. And hence I would need both JCR and JNDI.

My application does not do all the administration functions on  the repo. Since Alfresco Web client does a very good job on this, I would love to keep that. But for some of our custom operations on the repository, we use our application. So both need to be running at the same time.
I am able to acheive this scenario with JCR-RMI extension, but we are having some problems with multi threads so, thought JNDI must be a good option.

About the proxy, I guess that's a real good thought, I would try that once my JCR - JNDI is up and running Smiley Happy (just for ref: I use Apache Tomcat 5.5)

So if you could put up the code on the given site and just give me some pointers as to how to proceed, that would be really great.

Thanks again very much for your time,
Hema

rdanner
Champ in-the-making
Champ in-the-making
Dinner is served Smiley Happy

This is the package I had in my source tree and it's the last one I uploaded to issues.alfresco.com

If you have any issues let me know.

It contains a readme on how to use it.

Best,

http://forge.alfresco.com/frs/download.php/295/alfresco-jcr-jndi-v5.zip

hema
Champ in-the-making
Champ in-the-making
Russ,
Thank you very much.
I will try that out and write to you about the outcome once I am done. Smiley Happy

Thanks again,
Hema

hema
Champ in-the-making
Champ in-the-making
Thanks Russ,
I could successfully run the Test Application without any problems.

But, Now I have an issue based on my requirement.
My program is not a web application. I have to talk to the repository even though the web client is running. So I need the context.
(Previously I used rmi to get an instance of repository. Now I want to use jndi to get an instance of the repository)

I just tried to use the JndiJcrObjectFactory's getObjectInstance to get an instance of repository but could not pass the right parameters.

Is there a way to talk to the jcr repository using jndi from a local application (not web application) when already a instance of alfresco (web-client) is running.

Thank you very much,
Hema

hema
Champ in-the-making
Champ in-the-making
Hi Russ,

Hope you will able to help me with this.
I used the steps from lookupJndiJcr from test-tomcat.jsp to get my initial context.

After getting the environment right(with difficulty Smiley Happy ), I could get my InitialContext. But now I am facing problems with java:comp. I get the following error:
javax.naming.NameNotFoundException: Name java:comp is not bound in this Context

I am trying to google around to find some solution. but no success.
I see that naming -*.jars could be a problem but I cannot remove them from my application because the property java.naming.factory.initial needs org.apache.naming.java.javaURLContextFactory which is in naming-factory.jar

So please advice how I can go about.

Thanks very much again,
Hema