Tuesday, November 21, 2006

Glassfish Installation and Configuration (OC4J Migration)

Hi,

today I've installed multiple application server domains and instances on different linux machines. I've used a script to simplify the work. Glassfish offers the command line interface (CLI) "asadmin" which enables rapid configuration and installation tasks.

Define some paths:

export PASSWORDFILE=~/glassfish/password
export DOMAIN_ROOTDIR=/shared/mydir/glassfish
export RESOURCEXML=~/glassfish/resource.xml


Define domain and instance name and configure ports
export ACTIVE_DOMAIN=CpDomain
export ACTIVE_DOMAIN_LC=cpDomain
export TARGET_HOST_USER=auser
export TARGET_HOST_DOMAIN=host.domain.com
export TARGET_HOST=${TARGET_HOST_USER}@${TARGET_HOST_DOMAIN}
export ADMIN_PORT=10048
export INSTANCE_PORT=10080
export JMS_PORT=10076
export DOMAIN_JMXPORT=10086
export ORB_LISTENER_PORT=10037
export HTTP_SSL_PORT=10081
export ORB_SSL_PORT=10038
export ORB_MUTUALAUTH_PORT=10039
export DEBUG_PORT=10090


And here you go:
# create password file
ssh $TARGET_HOST "echo \"AS_ADMIN_PASSWORD=adminadmin:AS_ADMIN_ADMINPASSWORD=adminadmin\" | tr \":\" \"\n\" > ${PASSWORDFILE}${ACTIVE_DOMAIN}"

# create domain
ssh $TARGET_HOST "${DOMAIN_ROOTDIR}/bin/asadmin create-domain \
--adminuser admin \
--passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} \
--adminport ${ADMIN_PORT} \
--instanceport ${INSTANCE_PORT} \
--echo=true \
--domaindir ${DOMAIN_ROOTDIR}/domain${ACTIVE_DOMAIN} \
--domainproperties \
jms.port=${JMS_PORT}:\
domain.jmxPort=${DOMAIN_JMXPORT}:\
orb.listener.port=${ORB_LISTENER_PORT}:\
http.ssl.port=${HTTP_SSL_PORT}:\
orb.ssl.port=${ORB_SSL_PORT}:\
orb.mutualauth.port=${ORB_MUTUALAUTH_PORT} \
--savemasterpassword=true \
--checkports=true ${ACTIVE_DOMAIN_LC}"

# start domain
ssh $TARGET_HOST "${DOMAIN_ROOTDIR}/bin/asadmin start-domain \
--domaindir ${DOMAIN_ROOTDIR}/domain${ACTIVE_DOMAIN} \
--user admin \
--passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} \
--debug=false \
${ACTIVE_DOMAIN_LC}"

# add jdbc resources
ssh $TARGET_HOST "${DOMAIN_ROOTDIR}/bin/asadmin add-resources --user admin --passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} --host ${TARGET_HOST_DOMAIN} --port ${ADMIN_PORT} ${RESOURCEXML}"

# configure debug port and enable debug mode
ssh $TARGET_HOST "${DOMAIN_ROOTDIR}/bin/asadmin set --user admin --passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} --host ${TARGET_HOST_DOMAIN} --port ${ADMIN_PORT} server.java-config.debug-options=\"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT}\"; ${DOMAIN_ROOTDIR}/bin/asadmin set --user admin --passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} --host ${TARGET_HOST_DOMAIN} --port ${ADMIN_PORT} server.java-config.debug-enabled=true"

# restart domain with debug mode
ssh $TARGET_HOST "${DOMAIN_ROOTDIR}/bin/asadmin stop-domain \
--domaindir ${DOMAIN_ROOTDIR}/domain${ACTIVE_DOMAIN} \
${ACTIVE_DOMAIN_LC}; \
${DOMAIN_ROOTDIR}/bin/asadmin start-domain \
--domaindir ${DOMAIN_ROOTDIR}/domain${ACTIVE_DOMAIN} \
--user admin \
--passwordfile ${PASSWORDFILE}${ACTIVE_DOMAIN} \
--debug=true \
${ACTIVE_DOMAIN_LC}"

Labels:

Monday, November 20, 2006

OC4J to Glassfish Migration Pt. 2

Today I had a breakthrough. All the problems I had have been related to wrong annotations. Instead of using @PersistenceContext to inject the EntityManager, i have used @Resource as shown in one of the many online tutorials.
Now I can access my Database through a stateless session bean (factory) using various finder methods.
Now I have learned a new unpleasant lesson. My database schema is quite complex with a lot of relations. Therefor lazy access is a must and all entities are annotated accordingly. And now the unpleasant thing: my java standalone client throws an exception. The reason is that because of the lazyness, the javaee client wrapper classes are not able to deserialize the pojos with relations to other entities correctly. The related attributes have not been transferred. The result is a ClassNotFound-Exception although all Pojo-classes are accessible.
It seems that I have to transfer the relevant data via the TransferObject pattern.

It would be nice to have some kind of helper class which would be able to fetch all relevant data for a special find.

Nevertheless I am very happy of the actual migration status. I will report about my next steps soon.

Sunday, November 19, 2006

OC4J to Glassfish Migration

Today I've done the next steps for migration.

I've downloaded the following bits:

Hibernate Core, 3.2.1 GA
Hibernate Annotations, 3.2.0 GA
Hibernate EntityManager, 3.2.0 GADownload
Hibernate Tools, 3.2 beta 8

and of course Glassfish:
GlassfishV1, UR1 Build 14
andGlassfishV2, Build 19

I've downloaded both just in case that I will need different versions for various experiments.

I started with GlassfishV2 and my application with entities generated by Hibernate Tools was not running out of the box. Deployment went through without any errors (great).

I've written a small standalone java application which uses an InitialContext to look for an ejb3 stateless session bean. The result is positive. Unluckily the first call of a finder method within the session bean produces a large exception stack trace.

Maybe I have to edit the server.policy file although no security exception has been thrown? Just a feeling. Despite the explanation in another blog I did not copy the hibernate libs into the global glassfish lib, but packaged the libraries within my ejb jar. Maybe I should try copying those files into the global glassfish lib? If this does not help I will use GlassfishV1, UR1 Build 14. If this still does not help I would downgrade the hibernate libs.

More to come another day.

Labels: , ,

Saturday, November 18, 2006

Thinking about switching from Oracle Applicationserver to Glassfish

Hi,

I'm responsible for developing a huge, innovative javaee application. Currently the application is running on the latest Oracle Application Server 10.x. I'm seriously thinking about switching to Glassfish.
The reason is that Glassfish seems to offer the best support for the latest standards and open source frameworks such as EJB3, JSF 1.2, JAX-WS, Hibernate and Spring.
The next days I will try to talk a little bit about the problems about switching to the latest Glassfish V2.

Labels: , ,