วันพฤหัสบดีที่ 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");

วันศุกร์ที่ 20 มีนาคม พ.ศ. 2552

The ways to deal with non-transactional resources

There are serveral ways to deal with them.
1. Interaction without regard to transactionality. This approach is appropriate when there is no need for transaction management.
2. Development of transactional interfaces. This approach is the most comprehensive, but also the most time consuming because it needs to implement JTA interfaces (implementation of javax.transaction.xa.XAResource).
3. Implement the interactions in a “pseudo-transaction” that explicitly checks for and manages error conditions and rollback. I thought this approach like transaction in the web service which have to implement method for rollback by yourself.
In the detail, you can read at TheServerSide.

วันพฤหัสบดีที่ 19 มีนาคม พ.ศ. 2552

Problem from using JPA in grails with maven

I got this problem when i called $mvn grails:run-app.
[groovyc] Compiling 9 source files to /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/target/classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Compile error during compilation with javac.
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:3: package javax.persistence does not exist
[groovyc] import javax.persistence.Entity;
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:4: package javax.persistence does not exist
[groovyc] import javax.persistence.GeneratedValue;
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:5: package javax.persistence does not exist
[groovyc] import javax.persistence.GenerationType;
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:6: package javax.persistence does not exist
[groovyc] import javax.persistence.Id;
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:7: package javax.persistence does not exist
[groovyc] import javax.persistence.Version;
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:26: cannot find symbol
[groovyc] symbol: class Entity
[groovyc] @Entity
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:28: cannot find symbol
[groovyc] symbol : class Id
[groovyc] location: class org.grails.samples.Person
[groovyc] @Id
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:29: cannot find symbol
[groovyc] symbol : class GeneratedValue
[groovyc] location: class org.grails.samples.Person
[groovyc] @GeneratedValue(strategy=GenerationType.AUTO)
[groovyc] ^
[groovyc] /media/src/source/Eclipse/TestFrameWork/workspace/groovy/my-app/src/java/org/grails/samples/Person.java:31: cannot find symbol
[groovyc] symbol : class Version
[groovyc] location: class org.grails.samples.Person
[groovyc] @Version
[groovyc] ^
[groovyc] 9 errors
[groovyc]
[groovyc]
[groovyc] 1 error
Compilation error: Compilation Failed

It seems javax.persistence does not exist in maven dependencies of grails-maven-archetype 1.0.
To fix this problem, I added ejb3-persistence in pom.xml.

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.2.GA</version>
</dependency>

วันเสาร์ที่ 7 มีนาคม พ.ศ. 2552

Why cannot i play Patapon?

When I played this game, My PSP was freeze at loading screen.
I found that this game needs firmware 3.71 up and sets UMD ISO MODE to SONY NP9660,
but my firmware is 5.00 m33-6. Why is still not working?
In the end, I try changing the image file from CSO to ISO format.
yahh!!!! It's workkkkkkks.

วันพฤหัสบดีที่ 15 มกราคม พ.ศ. 2552

Can't start Tomcat after install VMware server.

Today (It is not real and I'm lazy to update my blog ==") I'm astonished at why i cannot start Tomcat.
Previously, I offen use Jetty to run my web application because It is fast and has great Maven plugin integreated.
This is exception.
SEVERE: StandardServer.await: create[8005]:
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.(ServerSocket.java:185)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)
at org.apache.catalina.startup.Catalina.await(Catalina.java:630)
at org.apache.catalina.startup.Catalina.start(Catalina.java:590)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

I knew port 8009 and 8005 is used by another process but i don't know what process use.
Then I searched for process using this port.

sudo netstat -p -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:902 *:* LISTEN 6325/vmware-authdla
tcp 0 0 *:8333 *:* LISTEN 6466/vmware-hostd
tcp 0 0 localhost:8307 *:* LISTEN 6466/vmware-hostd
tcp 0 0 localhost:ipp *:* LISTEN 5069/cupsd
tcp 0 0 localhost:62168 *:* LISTEN 7621/wish8.5
tcp 0 0 *:8222 *:* LISTEN 6466/vmware-hostd
tcp6 0 0 localhost:6880 [::]:* LISTEN 8861/java
tcp6 0 0 localhost:8005 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:22214 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8008 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN 5387/smbd
tcp6 0 0 localhost:45100 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8009 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:47698 [::]:* LISTEN 8861/java
tcp6 0 0 [::]:8308 [::]:* LISTEN 6322/webAccess
tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN 5387/smbd


Then I used ps command to find what webAccess is?

ps -ef | grep webAccess
root 6312 1 0 19:30 ? 00:00:00 /bin/sh /usr/bin/vmware-watchdog -s webAccess -u 30 -q 5 /usr/lib/vmware/webAccess/java/jre1.5.0_15/bin/webAccess -client -Xmx64m -XX:MinHeapFreeRatio=30 -XX:MaxHeapFreeRatio=30 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/common/endorsed -classpath /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/bootstrap.jar:/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/commons-logging-api.jar -Dcatalina.base=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Dcatalina.home=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start
root 6322 6312 0 19:30 ? 00:00:10 /usr/lib/vmware/webAccess/java/jre1.5.0_15/bin/webAccess -client -Xmx64m -XX:MinHeapFreeRatio=30 -XX:MaxHeapFreeRatio=30 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/common/endorsed -classpath /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/bootstrap.jar:/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/bin/commons-logging-api.jar -Dcatalina.base=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Dcatalina.home=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16 -Djava.io.tmpdir=/usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/temp org.apache.catalina.startup.Bootstrap start


I got VMware using Tomcat to run webAccess.
I chose to change Tomcat ports of VMware. I prefer this approach because I do not change other Tomcat ports again. (yes, It includes JBoss too)

To change Tomcat ports.
1 edit server.xml at /usr/lib/vmware/webAccess/tomcat/apache-tomcat-6.0.16/conf/server.xml.
2 change file mode to writeable.
sudo chmod a+w server.xml

3 find and change 8009 and 8005 ports to others.
4 save and change file mode to old mode.
sudo chmod a-w server.xml

5 restart service or reboot you OS.

วันเสาร์ที่ 3 มกราคม พ.ศ. 2552

Other ways to run Maven on Eclipe.

M2eclipse is excellent Maven tool for Eclipse.
I always use hotkey Shift + Alt + X M to run the last maven goals of Maven Build projects.
example First time you run "compile goal" of MyProject. Next time you want to run with other goals. If you use this hotkey, It will run "compile goal" again. You must move a mouse, right click on project, then select Run as Maven builds ... and key the new goal that you want. It is inconvenient.

Today I read Eclipse integration with Grails. In the step Adding domain classes etc, It shows the way to use External Tools to run grails command. It can adapt to run maven goals.
1 Run -> External tools -> External tools configuration ... .
2 Select Program and new launch configuration.
3 Enter a name of "Maven".
4 Browse file system for the location of mvn command that you have installed.
5 Set the working directory to "${project_loc}".
6 Set the arguments as "${string_prompt}".
7 Under the "Refresh" tab, set to refresh the "project containing the selected resource" upon completion.
8 Under the "Common" tab, tick "Display in favorites menu".
9 I set hotkey Shift + Alt + X S to Runs the last launched external Tool.

Every time you use thes hotkey, Eclipe will always ask you what is the goals you need to run.
You can type any maven goals.