Tuesday, December 15, 2009

Firebird Connection Pool in Glassfish 2.x.x

We will create in a few easy steps a Firebird Connection Pool on GlassFish 2.1.1.

First of all, we need to download the latest jdbc driver from:

http://www.firebirdsql.org/index.php?op=files&id=jaybird

Extract the downloaded archive and take the jaybird-full-x.x.x.jar from the compressed archive and put in {glassfish}/lib directory and restart glassfish:

asadmin stop-domain domain1
asadmin start-domain domain1

Now we need to navigate to the administrator application:
http://localhost:4848/
 
Open the 'Resources' -> 'JDBC' -> 'Connection Pools' and select 'New.
Fill in the Connection Pool 'Name'.
Select 'Resource Type' : 'javax.sql.ConnectionPoolDataSource'.
Select 'Next'.

At the next page complete the 'Datasource Classname' with :

org.firebirdsql.pool.sun.AppServerConnectionPoolDataSource

Then go down at the additional Properties.
Find and edit the following properties :
Select 'Name' : 'userName' and 'Value' : {db_user}
Select 'Name' : 'password' and 'Value' : {db_user_pass}
Select 'Name' : 'databaseName' and 'Value' : {host_name}:{db_path}
for example:
localhost:/my_data_files/mydb.fdb
Select 'Finish'.

Navigate to Connection Pools and select the pool you just created.
Click Ping to test that it is working. If it is not, it is probably because you have mistyped the connection credentials. Go to 'Additional Properties' tab of the connection pool detail page and correct any errors. Try ping again.

Open the 'Resources' -> 'JDBC' -> 'JDBC Resources' and select 'New.
Fill the JNDI Name like 'jdbc/myconnnection'.
Select from 'Pool Name' combo box the pool we just created.
And select 'OK'.

The Connection Pool is ready!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Monday, December 14, 2009

Create Postgresql Connection Pool in Glassfish 2.x.x

We will create a PostgreSQL (8.4) Connection Pool on a GlassFish 2.1.1 [and GlassFish v3].

First of all, we need to download the latest jdbc driver:

http://jdbc.postgresql.org/download.html

Copy the downloaded archive postgresql-x.x.-xxx.jdbc4.jar in {glassfish}/lib directory and restart glassfish:

asadmin stop-domain domain1
asadmin start-domain domain1

Now we need to navigate to the administrator application:
http://localhost:4848/
 
Open the 'Resources' -> 'JDBC' -> 'Connection Pools' and select 'New.
Fill in the Connection Pool 'Name'.
Select 'Resource Type' : 'javax.sql.DataSource'.
Select 'Database Vendor' : 'PostgreSQL'.
Select 'Next'.

At the next page go down at the additional Properties.
Find and edit the following properties :
Select 'Name' : 'User' and 'Value' : {db_user}
Select 'Name' : 'Password' and 'Value' : {db_user_pass}
Select 'Name' : 'DatabaseName' and 'Value' : {db_name}
Select 'Name' : 'ServerName' and 'Value' : {server_hostname}
If your dqatabase is not in the default port (5432) you might also need to edit the following attribute :
Select 'Name' : 'PortNumber' and 'Value' : {port_number}
Select 'Finish'.

Navigate to Connection Pools and select the pool you just created.
Click Ping to test that it is working. If it is not, it is probably because you have mistyped the connection credentials. Go to 'Additional Properties' tab of the connection pool detail page and correct any errors. Try ping again.

Open the 'Resources' -> 'JDBC' -> 'JDBC Resources' and select 'New.
Fill the JNDI Name like 'jdbc/myconnnection'.
Select from 'Pool Name' combo box the pool we just created.
And select 'OK'.

The Connection Pool is ready!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Mysql Connection Pool in GlassFish 2.x.x

As a followup to a previous post, regarding the creation of an oracle connection pool in GlassFish 2.1.1, we will create a MySQL connection pool.

First of all, we need to download from www.mysql.com the latest jdbc driver:

http://dev.mysql.com/downloads/connector/j/5.1.html

Extract the downloaded archive and take the mysql-connector-java-x.x.x-bin.jar from the compressed archive and put in {glassfish}/lib directory and restart glassfish:

asadmin stop-domain domain1
asadmin start-domain domain1

Now we need to navigate to the administrator application:
http://localhost:4848/
 
Open the 'Resources' -> 'JDBC' -> 'Connection Pools' and select 'New.
Fill in the Connection Pool 'Name'.
Select 'Resource Type' : 'javax.sql.DataSource'.
Select 'Database Vendor' : 'MySQL'.
Select 'Next'.

At the next page go down at the additional Properties.
Find and edit the following properties :
Select 'Name' : 'User' and 'Value' : {db_user}
Select 'Name' : 'Password' and 'Value' : {db_user_pass}
Select 'Name' : 'URL' and 'Value' :
jdbc:mysql://[host]:[port]/[database name]
Select 'Finish'.

Navigate to Connection Pools and select the pool you just created.
Click Ping to test that it is working. If it is not, it is probably because you have mistyped the connection credentials. Go to 'Additional Properties' tab of the connection pool detail page and correct any errors. Try ping again.

Open the 'Resources' -> 'JDBC' -> 'JDBC Resources' and select 'New.
Fill the JNDI Name like 'jdbc/myconnnection'.
Select from 'Pool Name' combo box the pool we just created.
And select 'OK'.

The Connection Pool is ready!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Install eclipselink in Glassfish 2.x.x

Installing eclipselink in glassfish is a piece of cake.

First step is to download the eclipselink.jar from :

http://www.eclipse.org/eclipselink/downloads/

Second step is to put ecllipselink.jar (some might also need the persistence.jar) in {glassfish_home}/lib so that the library is available to all domains.

Third step is to create a connection pool. Use the following tutorial for an oracle pool:

http://mariosgaee.blogspot.com/2009/12/oracle-connection-pool-in-glassfish.html

And last, deploy your eclipselink application.


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Monday, December 7, 2009

Oracle Connection Pool in GlassFish 2.x.x

Glassfish does not ship with oracle jdbc drivers. The oracle driver needs to be added manually.  The driver can be found either in a JDeveloper or oracle client or database installation in {install_path}/jdbc/lib, or from oracle's site:

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.html

Glassfish needs at least ojdbc14.jar to work properly. Older drivers do not work. Put the ojdbc14.jar in {glassfish}/lib directory and restart glassfish:

asadmin stop-domain domain1
asadmin start-domain domain1

Now you need to navigate to the administrator application:
http://localhost:4848/
 
Open the 'Resources' -> 'JDBC' -> 'Connection Pools' and select 'New.
Fill in the Connection Pool 'Name'.
Select 'Resource Type' : 'javax.sql.ConnectionPoolDataSource'.
Select 'Database Vendor' : 'Oracle'.
Select 'Next'.

At the next page go down at the additional Properties.
Select all the properties and select 'Delete Properties'.
Select 'Add Property', fill 'Name' : 'user' and 'Value' : {db_user}
Select 'Add Property', fill 'Name' : 'password' and 'Value' : {db_user_pass}
Select 'Add Property', fill 'Name' : 'url' and 'Value' :
jdbc:oracle:thin:@[host][:port]:SID
or
jdbc:oracle:thin:@//[host][:port]/SID
Select 'Finish'.

Navigate to Connection Pools and select the pool you just created.
Click Ping to test that it is working. If it is not, it is probably because you have mistyped the connection credentials. Go to 'Additional Properties' tab of the connection pool detail page and correct any errors. Try ping again.

Open the 'Resources' -> 'JDBC' -> 'JDBC Resources' and select 'New.
Fill the JNDI Name like 'jdbc/myconnnection'.
Select from 'Pool Name' combo box the pool we already created.
And select 'OK'.

The Connection Pool is ready!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

GlassFish and Adf Toplink 10g (2)

As a followup to the previous post I feel the obligation to add my testing experience of a small but full featured ADF Faces and ADF Toplink application in glassfish.

The basic problem I stumbled upon was the External Transaction Controller. Toplink.jar does not provide a TransactionController for GlassFish, although there is one for Oc4j, JBoss, WebSphere and Weblogic. As a result, we have to create one on our own.

The way to call the Transaction Manager in Glassfish is:
java:appserver/TransactionManager

We need to create a new class named GFTransactionController:
===============================================v
package oracle.toplink.transaction.gf;

import javax.transaction.TransactionManager;
import oracle.toplink.transaction.JTATransactionController;

public class GFTransactionController extends JTATransactionController {

public GFTransactionController() { }

protected TransactionManager acquireTransactionManager() throws Exception {
return (TransactionManager)jndiLookup("java:appserver/TransactionManager");
}

public static final String JNDI_TRANSACTION_MANAGER_NAME = "java:appserver/TransactionManager";
}

===============================================
In order to compile this class one needs toplink.jar ({jdev_install}/toplink/jlib) and j2ee.jar ({glassfish_install}/lib) in the classpath.
Then we open toplink.jar (the one inside glassfish) with winrar. We navigate to folder oracle/toplink/transaction. Right click --> Create new folder --> gf. Navigate to gf and drag and drop the GFTransactionController.class file inside. Our new toplink.jar is ready. We copy the new toplink.jar in {glassfish_install}/lib.

We also need to change the Transaction Controller in our project.
Open your adf model project in Jdeveloper and follow these instructions:
===============================================
1. In the Applications Navigator, select DataModel --> Application Sources --> TopLink.
2. Select sessions.xml. In the Structure pane, double-click 'default' (or whatever you have named it).
3. On the General page, select the External Transaction Controller check box in Options.
4. Enter the following transaction class:
oracle.toplink.transaction.gf.GFTransactionController

===============================================

The other problem that I found was at web.xml. JDeveloper creates by default a new web project with a 2.4 xsd for web.xml. We need to change that to a 2.5 xsd. So we open our web.xml and replace our
===============================================
< web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" >
===============================================
with
===============================================
< web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5" >
===============================================

Now redeploy your project and all ejb junctionality is working correctly.

Another minor change is the result of this command: getServletConfig().getServletContext().getRealPath("/test/");
Oc4j returns a slash at the end, while Glassfish does not. A simple solution is to add the last slash after the command:
getServletConfig().getServletContext().getRealPath("/test")+"/";

As I have already mentioned in a previous post, 90% of the problems is a path translation error, because the two servers handle paths a little differently.

As a conlcusion, I need to note that GlassFish can successfully run an ADF Faces with ADF Toplink (EJB 3) Application with only a few configuration changes and some slight code modifications! Apart from TransactionController, all the others pass in OC4J too. So, there is no need to start using glassfish as a testing server if you are already using JDeveloper!


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Sunday, December 6, 2009

GlassFish and Adf Toplink 10g

After my success in deploying an ADF Faces web application in Glassfish (2.1.1), I got a crazy idea. Why not try deploying an ADF Faces with ADF Toplink (EJB 3.0 SessionBean with Pojos) enterprise application in GlassFish? Oracle has deploying instructions for JBoss and WebLogic. What these application Servers have more than GlassFish? Exactly. Nothing!

So I put my thoughts into work. The first success came when I put toplink.jar in ${glassfish}/lib, restarted the server and the model was successfully deployed with no errors! Then I started adding one by one all the runtime libraries that where reported missing by glassfish deployer. Finally I reached a point where deployment was successful, but there were still runtime errors. I continued adding more libraries, one by one. But when I added xmlparserv2.jar library I returned to square one. The deployment was once again unsuccessful. I googled the error:

------------------------------------------------
java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
at javax.xml.parsers.DocumentBuilderFactory.setSchema(DocumentBuilderFactory.java:561)
...
-----------------------------------------------


All hits I got for this error was about using an older xml parser. But I could not figure out why. I searched inside the xmlparserv2.jar and found some javax.* classes apart from oracle.* classes. So I deleted all javax.* classes from inside the jar in order not to override the default classes, and I created a new xmlparserv2.jar (I also removed from xmlparserv2.jar the directory META-INF/services). I renamed it to oxmlparserv2.jar and added it to project libraries.

The application was deployed once again. I was really happy. But my troubles weren't over yet. Not even a simple query would run without giving the error:

----------------------------------------------
javax.servlet.ServletException: javax.el.MethodNotFoundException: Method not found: findItemByName.execute(javax.faces.event.ActionEvent)
root cause
javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: Method not found: findItemByName.execute(javax.faces.event.ActionEvent)
root cause
javax.el.MethodNotFoundException: Method not found: findItemByName.execute(javax.faces.event.ActionEvent)
----------------------------------------------


This was an even more obscure error. I presumed it would still have to do with some missing library. All I needed was to find which library. But there was no error 'noClassDefFoundError' to help me this time! Then I remembered that JDeveloper supports installing all of its runtime libraries to various applications servers, why not glassfish too? Since there is no glassfish installation process in JDeveloper, I improvised. I downloaded a JBoss v4 and installed it. I opened JDeveloper 10.1.3.5 and then I followed the menu:
Tools --> ADF Runtime Installer --> JBoss.
I completed the installation throught the wizard. Jdev then displayed a summary of the installed libraries. Based on this list I figured out that I only needed to use those libraries that were installed in {server}/default/lib directory of JBoss. The others did not seem very important. Here is a list of those that worked form me:

----------------------------------------------------
adf-connections.jar
adfbinding.jar
adfcm.jar
adfm.jar
adfmtl.jar
adfmweb.jar
adfshare.jar
adfui.jar
antlr.jar
bc4jct.jar
bc4jctejb.jar
bc4jdomgnrc.jar
bc4jdomorcl.jar
bc4jimdomains.jar
bc4jmt.jar
bc4jmtejb.jar
cache.jar
collections.jar
commons-cli-1.0.jar
commons-el.jar
concurrent.jar
dc-adapters.jar
dms.jar
http_client.jar
jazncore.jar
jdev-cm.jar
jsp-el-api.jar
libs.txt
mdsrt.jar
ojdbc14.jar
ojpse.jar
oracle-el.jar
oraclepki.jar
ordhttp.jar
ordim.jar
osdt_cert.jar
osdt_core.jar
osdt_saml.jar
osdt_wss.jar
osdt_xmlsec.jar
oxml.jar
oxmlparserv2.jar
runtime12.jar
share.jar
toplink-agent.jar
toplink.jar
translator.jar
xmlef.jar
xsqlserializers.jar
xsu12.jar
----------------------------------------------------


So I copied them to my {glassfish}/lib dir. Except for xml.jar and xmlparserv2.jar. For those two I deleted all javax.* classes from the jar and then I copied them with new names, as oxmlparserv2.jar and oxml.jar, in order to distinguish them in the future.

The result was astounding. The application was deployed successfully and run a query! Total Success!

All that is left to do now, is run thorough tests on every adf-toplink application that needs to be deployed in glassfish, so as to find any minor inconsistencies. As a hint, I have found that the path is handled differently between the two servers. This thought will solve almost 90% of the rest of the incompatibility problems.

Concluding, I need to say that glassfish server has already surpassed my expectations. It is a free open source application server that can compete evenly with other commercial application servers. And if it can run oracle's applications, then it can run any j2ee application!

I want to add as a last thought, as a big organization's application server administrator, a comparison, between glassfish and oas. Say we have 35.000 Euros to spent for a linux application server, hardware and software.

In case we buy oas enterprise edition, its price goes to about 15.000 Euros a core. So with 35.000 Euros we get a dual core license and that leaves 5.000 to get a machine with the best dual core in the market, and at least 10GB of memory. Let's assume that the rest of the hardware will be the same.

In case we choose glassfish, all the money goes to hardware. What do we buy with 35.000 Euros? Two machines (as I saw at dell's site) with 24 cores ( 4 x Intel 6cores) and 48GB memory each. Which sums up to 48 cores running almost at top speed and 96GB of memory. With both servers we get clustering and support. And I need to add that glassfish community support is as good as oracle's.

What I make of it? I don't care how fast oas is. It may even be twice as fast (or even thrice as fast) as glassfish. Who cares? With those money and glassfish one can buy 24 times more cpus and memory.

And as a last stroke, I need to add the yearly support fee to oracle. Instead of paying support and licensing fees, which amount in around 20% a year. If we save this money, we can invest them in a new system every four or five years. (And all the rest of the money can go to seminars!)

A clear win for open source and glassfish against oracle application server!


P.S.
There is an error in this comparison. While GlassFish is open source and therefore free, the use of ADF framework is not. I have a more accurate comparison here.

Saturday, December 5, 2009

Glassfish and Adf Faces

A friend told me that glassfish is the best Application Server for Java based web projects. So I installed GlassFish 2.1.1, in three easy steps, which are well documented in the download site. I wanted to see if adf faces would run at all.
I downloaded the adf faces demo 10.1.3.0.4 from oracle's site. I deployed it and everything run smoothly! well, almost everything! whenever I needed to open a popup window, for example the chooseDate component, the server would reply with the error:
=================
javax.servlet.ServletException: viewId:/__ADFv__ - View /__ADFv__ could not be restored.
root cause
javax.faces.application.ViewExpiredException: viewId:/__ADFv__ - View /__ADFv__ could not be restored.
=================
I searched the internet but found nowhere any references to it. After reading that glassfish project is providing the portability of adf faces to glassfish without modifications, I filed a bug. The reply came only a few hours later. The answer was simple. The problem was already solved but not well documented. All, I had to do was put these two lines in the web.xml file:
=================
< context-param>
< param-name>com.sun.faces.enableRestoreView11Compatibility< /param-name>
< param-value>true< /param-value>
< /context-param>
=================
After that the adf faces demo run, literally, without any modifications!

As a conclusion, I need to congratulate the GlassFish Project community, for its immediate answer and professionality, something we don't find easily these days. Keep up the good work guys.


p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.

Friday, December 4, 2009

Running gwt project error

I thought giving gwt a chance, so I opened a tutorial for gwt and eclipse. Very soon I had the code for a little HelloWorld example ready to run. But when I hit 'run as --> Web Application' there was a sinister error waiting for me!!!

- libstdc++.so.5: cannot open shared object file: No such file or directory

So I thought I'll apt-get my way through! But stdlibc++.so.5 is no longer available on ubuntu 9.10!
So I googled the library and I had to install almost manually. Here is the download mirrors list for libstdc++5 library.

http://packages.ubuntu.com/jaunty/i386/libstdc++5/download.

After downloading and installing it, gwt worked fine. Though my code was a mess! lol.
And I need to add that linux is a beauty. I did not have to restart eclipse. I just hit 'Run' one more time and it worked!

Tuesday, November 24, 2009

Install Google App Engine Plugin for Eclipse

First things first. Google is offering a plugin for Eclipse. So I had to download and install eclipse. The thing is I recently switched to ubuntu linux (9.10) and was so fascinated with its easy-to-use interface that I immediately jumped to Applications --> Ubuntu Software Center and installed eclipse. All went fine. Until I started following google's installation instrunctions for the plugin. The setup would never finish, because there were some missing libraries. I started searching the internet for help. I found that ubuntu's release of eclipse is a slightly different one that lacks update support. I tried using the update sites of the mainstream release of eclipse, but that didn't do the trick either.
I was frustrated. I uninstalled the ubuntu release and downloaded the official release. Things went smoothly, because eclipse doesn't need installing! Only extracting! When I arrived at the installation plugin screen I realised that some things were not viewable. That was really weird. Just as if I was looking at a non stable release! As a consequence, I was unable to install the plugin.
I was even more frustrated, but I didn't quit just yet. I starting searching the internet blindly. With no luck. Then I started looking at all the Google App Engine pages just in case. And there I found it. At a google blog there was one easy step to solve all of my problems! So all I had to do was create a new file in the eclipse home directory with the following lines:

------------

#!/bin/sh
export GDK_NATIVE_WINDOWS=1
./eclipse
------------

and run eclipse through it.
All of my troubles were over. All the instructions for the plugin installation were completing successfully! For your reference the google installation instructions are at the following urls:

http://code.google.com/eclipse/docs/getting_started.html#installing

[http://dl.google.com/eclipse/plugin/3.5]

After a few days I tried repeating the above procedure at a windows xp sp3 machine. I was surprised to find out that the installation process was flawless, without a glitch! This is a clear win for windows! Although eclipse is an open source software, it's installation on an ubuntu machine was far more troublesome that in windows.