วันพฤหัสบดีที่ 16 เมษายน พ.ศ. 2552

JBoss5 JNDI

เพิ่งจะได้ลอง JBoss 5.0.1 หลังจากที่ลอง JBoss 5.0 ตั้งแต่วันแรกที่ออก(อุตส่าห์รอคอย)
ใน JBoss 5.0 พบว่าเขียน Test client (java class with main method to call ejb service) เปลี่ยน namming ให้ตายก็ lookup ไม่เจอสักทีเสียเวลาเป็นวัน เลิกเลย

หลังจากเห็น JBoss 5.0.1 ออกมาเกือบสองเดือนก็ยังไม่ได้เทส วันนี้ว่างๆเลยขอลองซะหน่อย
ปรากฏว่าเต่นเต๋นเต้น ตอน deploy เสร็จเห็นเลยว่ามี JNDI อะไรบ้างที่ binding เข้ากับ Global JNDI เลย
23:30:20,632 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

MyPrint/remote - EJB3.x Default Remote Business Interface
MyPrint/remote-test.PrintRemote - EJB3.x Remote Business Interface


เข้าไปดูใน JMX Console ก็เห็นเหมือนเวอร์ชั่น 4.2 ด้วย(ดีใจไม่ต้องเสียเวลางม)
+- MyPrint (class: org.jnp.interfaces.NamingContext)
| +- remote-test.PrintRemote (class: Proxy for: test.PrintRemote)
| +- remote (class: Proxy for: test.PrintRemote)


ตัว Test client ก็ง่ายๆเหมือนเวอร์ชั่น 4.2 เลย

public class PrintClient {
public static void main(String[] args) {
try {
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.provider.url","jnp://localhost:1099");
prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

InitialContext ctx = new InitialContext(prop);
PrintRemote print = (PrintRemote)ctx.lookup("MyPrint/remote");
print.display();
} catch (Exception e) {
e.printStackTrace();
}
}
}

จบเรื่องคาใจไปอีกเรื่อง งมใน mail ก็เห็นคนบ่นกัน ว่าแล้วว่ามันต้องแก้

วันจันทร์ที่ 6 เมษายน พ.ศ. 2552

Bug in GORMSessionFactoryDefinitionParser

In GORM of Grails 1.1, I found this bug.
if you define context.xml like this.

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<gorm:sessionFactory base-package="org.grails.samples"
data-source-ref="dataSource" message-source-ref="messageSource" transaction-manager-ref="txManager">
<property name="configLocations" value="classpath:hibernate.cfg.xml" />
<property name="hibernateProperties">
<util:map>
<entry key="hibernate.hbm2ddl.auto" value="update" />
</util:map>
</property>
</gorm:sessionFactory>

An attribute transaction-manager-ref is not necessary, for Grails will create transactionManager (org.springframework.orm.hibernate3.HibernateTransactionManager), but whether you provide your transaction manager, you will see this exception.
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:971)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:758)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:422)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.gable.grails.test.interoperation.App.main(App.java:15)

In found in GORMSessionFactoryDefinitionParser on line 213.

targetRegistry.registerAlias("transactionManager", transactionManagerRef);

I thought this line intend to give transactionManager being an alias of transactionManagerRef.
It should be

targetRegistry.registerAlias(transactionManagerRef, "transactionManager");