Sunday, June 03, 2007

Another helping of Glassfish...mmmm good stuff!

Today I'd like to work with some old things and some new...let's start out by configuring a database for use with Glassfish. In specific, I'll be adding a connection pool for SQL Server using a third party (jTDS) driver.

Here is the procedure

1) Unzip the driver.
2) Copy the jTDS.jar file to the Glassfish's lib directory.
3) If you haven't done so, add a database using in Enterprise Manager...for this test I called
it glassfishdb
4) Add logins as needed to have access to us the glassfishdb
5) Start Application Server as described in a prior blog entry. Note that if Glassfish is
already running then you will want to restart it so it will find the JDBC driver.
6) Open up the Sun Admin Console and log in.
7) Add a connection pool by clicking on Create New JDBC Connection Pool under Other Tasks then
follow this list:
a) Name = sqlserverproxy (or some name of your choice)
b) Resource Type = XADataSource (depends of course...)
c) Database Vendor = Microsoft SQL Server

Click Next (upper right)

d) Datasource Classname = net.sourceforge.jtds.jdbcx.JtdsDataSource
e) Description = Enter some description (SQL Server for Glassfish Test for example)
f) Check connection validation required
g) Servername = localHost
h) port = 1433 (SQL SErver default unless you have changed it)
i) Databasename = glassfishdb
j) User = the user you set up
k) Password = the password you gave the user

After that, click Save then click Ping to verify all is OK.

Note that if you have a question about any of the parameters mentioned here or those I did not specify (pool size for example), simply click Help (upper right hand corner) and Glassfish you tell you all you need to know about this page.

Once that part is complete, you'll want to add a JDBC resource. On the left hand pane, expand Resources, then expand JDBC Resources. On the right hand pane, click New. Give it some name (glassfishResoucePool for example) and select the connection pool name you set up in the prior step, add a description of your choice, then make sure the enabled box is checked.



That's all there is to it! The GUI steps you throught the process and provides assistance should you need it, and even allows you to verify connectivity (via the ping).

So good for the tried and true (this functionality is has been in Glassfish more or less unchanged for as long as I can remember), let's try something a bit newer next. I recall back in an earlier build of Glasssifh (circa b27-30) there was a problem getting web services generated through Netbeans to work due to a problem with Glassfish...let's see if this is still the case.
Following instructions at http://www.netbeans.org/kb/55/websvc-jax-ws.html I built and deployed a test web service (CalculatorWS). I then went into the Classfish Admin Console to see if it was successfully deployed and, hopefully as this did not work the last time I checked, test it out.

To do that, click on Web Services in the left hand pane and verify that ClaculateWS is there.



Click on the name to bring up more options. Here you will see a button labeled Test. This is the part that was missing/broken when I last tried but now it works great.
Click on Test and you will see that Glassfish brings up a little tester web page for you.




It even shows you the soap request and response (click add). Very nice!



Next week I'll try to test some of the performance improvements over prior versions. In build 33 I saw a substantial improvement for simple stateless session EJBs transporting data in packet sizes from 2 to 20K over build 27. Will the improvments continue?

Until next time then...

No comments: