XwikiNaming
GradSoft Ltd. http://www.gradsoft.ua
Ruslan Shevchenko
XwikiNaming is xwiki plugin which integrate xwiki with external naming system (usually supplied by J2EE application container). In addition, xwikinaming can be used with integration of xwiki with spring IOC framework, by providing jndi api to access spring internal name system and special JNDI provider, which search at first in IOC container, than in default JNDI.
So, with this plugin it is it is easy call J2EE or spring beans from xwiki pages with help of groovy or velocity templates.
You can download project artifacts from google project space:
xwiki-plugin-naming-1.x.jar
xwiki-plugin-naming-1.x-src.tar.gz
License is GPL-v3.
add xwiknaming-<version>.jar to <xwiki-root>/WEB-INF/lib
if you use spring:
add also spring-2.5.3.jar, xbean-spring-common-2.8.jar and xbean-spring-3.3.jar (along with you beans) to <xwiki-root>/WEB-INF/lib
package spring xml configuration as spring.xml with you spring beans or put one directly to <xwiki-root>/webapps/classes/spring.xml (name of file can be changed). Bean with id jndi and type org.apache.xbean.spring.jndi.DefaultContext must be defined in spring configuration, for example:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="jndi" class="org.apache.xbean.spring.jndi.DefaultContext">
<property name="entries">
<map>
<entry key="my-bean">
<bean id="UsedBean" class="ua.gradsoft.xwikinamingtest.spring1.UsedBean">
</bean>
</entry>
</map>
</property>
</bean>
</beans>
add xwikinaming-<version>.jar to list of plugins in xwiki.cfg
If you plan to use combination of spring and jndi than add to xwiki.cfg next variables:
xwikinaming.chain=1
xwikinaming.chain.first=spring
xwikinaming.chain.second=default
in this case xwikinaming plugin will search for naming object at first in spring namespace, than in jndi. In addition you can set location of spring configuration and jndi options (see Detailed Configuration sections for details)
Very simple: just use lookup method.
I.e. for velocity:
#set ($mybean = $xwiki.naming.lookup('my-bean'))
#if (“$!mybean” == “”)
object mybean is not bound in JNDI
#else
#set ($result = $mybean.methodCall())
#end
For groovy:
<% mybean = xwiki.getPlugin(“naming”).lookup(“my-bean”); %>
<% if (mybean==null) { %>
object mybean is not bound in JNDI
<% } else { %>
#set ($result = $mybean.methodCall())
<% } %>
In xwiki.cfg next variables can be set:
xwikinaming.chain -- if 1 then use chain jndi provider, where during lookup we at first look at first jndi provider, than on second. By default – 0.
xwikinaming.chain.first -- type of first provider (spring or default). By default - default.
xwikinaming.chain.first.properties -- if type of first provider in chain is not spring – name of file with jndi properties for first provider. When this parameter is set, than provider is initialized from properties file with appropriative name instead jndi.properties.
xwikinaming.chain.second -- type of second provider in chain.
xwikinaming.chain.second.properties -- name of file with jndi properties for second provider.
xwikinaming.spring.config – if one of providers in chain is spring, than property hold location of spring xml configuration in classpath. spring.xml must contain jndi bean, in the same manner as specified in http://servicemix.apache.org/jndi-configuration.html
In addtion, logging can be configured through log4j framework, so to enable debug
add to xwiki log4j.properties next string:
log4j.logger.ua.gradsoft.xwikinaming=debug
You can call GradSoft for commercial support or request for enhancements.
Our url is http://www.gradsoft.ua