Spring Framework Session Reviewed

Last Monday evening I joined the Java Study Group at the VIK’s house, near Antwerp, for a session about the Spring Framework. It was certainly worth the ride! Besides, Gerrit Cap kindly spoke in English instead of the usual Dutch. 🙂

I have made some research on Spring before, but with this session I could get a better understanding of the framework and its applicability. The idea was to learn the principles behind Spring and how to use the framework. Gerrit Cap spoke about decoupled OO implementations, which are easier to achieve with Spring. He touched other several subjects, including Inversion of Control and AOP.

It came as a surprise that Spring can be used in standalone applications. I thought it was more meaningful to use it in web applications, and the reason is that I usually read about Spring and its applicability in enterprise applications. I really liked that implementations can be done with less code than usual, eliminating duplicate code and promoting code reuse. I find imperative decoupling between objects, which is achieved in Spring by using Inversion of Control.

I liked more things of course! I find the JdbcTemplate fantastic. 😛 I am developing a web application in PHP where I have to do all the code to query the database myself: get a connection to the database, prepare the SQL statement, bind parameters, fetch the result and finally close the connection to the database. And I have to do this many times. JdbcTemplate does all this for you, which lets you actually concentrate on the query itself.

Another thing I find interesting is AOP. Although I had already used AspectJ last year at the Advanced Software Engineering course, while I was studying at TU Delft, I never understood very well the concept. It’s actually quite simple, and using it makes it possible to concentrate on the logic of the application and overlook logging, transaction, security or any other kind of concerns. These can be taken care later or even by another specialized developer.

In conclusion this was a great session, and I hope there will be more like this! In addition, Gert Cuppens offered me a DVD from JavaPolis 2004 with some nice presentations also about Spring and AOP. Ah! And the book “Agile Java Development With Spring, Hibernate and Eclipse” arrived today. Gotta keep running!

June Books

Beginning Java EE 5: From Novice to Professional (amazon.co.uk)

I have been waiting for a book like this one for quite some time. If you’re a novice you don’t need to think twice about purchasing it! 🙂 The authors did a great job in covering most of J2EE (JSP, JSF, Servlets, EJB, JDBC, and Web Services). The main reason why I like this book is that I can follow it without almost any difficulty, the text is very clear and the examples go direct to the point. Since English is not my mother language, I do find some English books hard to follow, but I did not have any problems with this one.

Because this book was written while the specification of Java EE 5 was still being written there are some examples that need some workaround, but you can always look at the book’s website for corrections. And you’ll always learn when trying to find solutions yourself. The book also points to resources where you can find more information on how to solve problems that can possibly occur.

I only have this book for a few days, so I did not finish reading it yet, but until now I am very satisfied. If you are interested in more reviews have a look at amazon.com.

“The Java 2 Enterprise Edition (J2EE) is an extremely powerful platform for developing enterprise-level Java-based applications, primarily for the server. This book shows you how to harness that power, examining how the pieces of the new J2EE 5 platform fit together.

This book surpasses explaining how to code a JSP or an EJB: It explains when and where to use these APIs, what their strengths and weaknesses are, and perhaps most importantly, how to employ the best practices for using them.

Hands-on tutorials are also included, along with clear explanations and working code examples. You will grow to take the next step—from writing client-side desktop applications to writing enterprise applications. You will also learn how to use the individual APIs and tools in the J2EE platform, and how to merge these to create your own enterprise applications.”

Spring Framework Session

The 29th of May, I’ll be joining the Belgium Java Study Group, near Antwerp, for an “Introduction to the Spring Framework“. I am finally going to have a look into it! And the interesting thing is that apparently EJB 3.0 is a now a challenger of Spring (read more). On an earlier post I had a link to a very interesting article for beginners. It was said that a beginner should not loose time learning EJBs. It appears that this argument is not valid anymore! Maybe now there are enough reasons to have a look at the new model for EJBs. But one thing at a time, please! 😛

Can you forget what I just said?

Sometimes I have a déjà-vu of those times when I had to answer a last question on an exam and I only had five minutes to do it. I had to spit up an answer and I just couldn’t get it out, thus, I would write the first thing that would come to mind.

It only gets worse when I had to answer a question face to the professor! Well it depends on the question of course, but sometimes even when I happen to knew the answer I would find a way to mix it all up. And then, I would come up with the most brainless though.

Now that I am through with those times, I still find a way to resemble them occasionally. So how would you deal with it? Make a post on your blog about it? Maybe yes, if it makes you remember that you can’t know everything and that you can do better next time. If it makes you remember of how you overcome that fall short, by going home and grabbing some books or Google in search of an answer. In the end, you only win, by learning more every time again. And if you felt disappointment with yourself, you will feel contentment after learning the answer.

 

Web Services for Beginners (NetBeans is our friend!)

After a few days of J2EE 1.4 Tutorial on XML, DTD, Dom and XSLT I finally arrived at the “Building Web Services with JAX-RCP” chapter. I was very enthusiastic about it and I went through the entire chapter following all the steps. For my disappointment, at the end of the chapter, I realized I could not build a Web Service myself! And here is the difficulty: am I suppose to know how to write all those configuration files? The tutorial does not explain how to do that, because the examples already provide all those files. I just had to build, deploy and run.

I went Google about building up a Web Service from scratch and I found the tutorial Quick-Start Guide for Web Services which explain how to write a Web Service and a Client using NetBeans. If you’re a beginner you’ll be happy to see that after following this tutorial you actually have a Web Service up and running and a client that accesses it. This tutorial assumes you’re using NetBeans 4.1, so if you’re using NetBeans 5.0 make sure you have the latest updates from Update Center (Tools Menu), otherwise it will give errors when you try to add the service to the registry or when you try to create a client (the latest will actually warn you to get the latest updates). The thing about this article is that it teaches you to build a Web Service using the NetBeans wizard. And my questions are: Is this the best way to do it? Is this the way developers should do it professionally? What if I want to do it using Eclipse? I would like to find more resources about building up Web Services including writing the configuration files part. I am open to suggestions. 🙂

Deployment Experiences

During my daily “J2EE 1.4 Tutorial” I came across an error after deploying the same web module twice. I discovered that the problem as to do with deploying the same web module in packed way (war file) and after that, deploying it again, but this time in an unpacked way (supposedly through the web module directory structure).

Here is what I did:

I used two directories: directory a) containing the packed web module in a war file and directory b) containing the web module directory structure.

  1. I deployed the packaged web module using the Server Admin Console and entering the full path to the war file, contained in directory a). Everything went fine and I could run the application in the browser.
  2. I deployed the web module again using the unpacked version via the asadmin deploydir command line tool. I used the full path of directory a).

This command did not execute successfully and I got the error “Deploying application in domain failed; Unknown deployable object type specified: Cannot determine the J2EE component type”.

I realized that one of the things that I did wrong was specifying the wrong directory path in the asadmin deploydir command. I should specify directory b), the one containing the web module directory structure, but instead I specified directory a). For some reason the server gets messed up and I could not undeploy the application nor I could access the Web Applications in the Server Admin Console, The latest would give the error “Unable to get View for ViewDescriptor ‘webApplications'”.

To solve this problem I had to:

  1. Manually remove the entry for this web module in the ${AppServer.HOME}\domains\domain1\config\domain.xml file. The line to remove is always similar to:

      <web-module availability-enabled=”false” context-root=”/Hello1″ directory-deployed=”true” enabled=”true” location=”${com.sun.aas.installRoot} /lib/install/applications/com_sun_web_ui” name=”Hello1″ object-type=”user” />

  2. Restart the server and happily I was back in the playing field!

I retried the same steps but using the correct directory paths and everything went fine. Although I am not completely sure about the cause of this problem I think the error is caused by an uncompleted deployment of the unpacked web module since it cannot find the correct directory structure. It’s just a pity that it breaks down the previous deployment.

Read more »