Sunday, March 7, 2010

Felipe Gaúcho, You Will Be Missed

How can I write about such a delicate subject? How can I find strength and inspiration in a hard moment like this one? I would summarize this post in only one word: speechless, but the absence of words may let my thoughts and emotions incomplete. So, I decided to write as the words come to my mind, and they are not easy.

I've lost a very dear friend last Friday (March 5th, 2010). His name is Felipe Gaúcho and he had a severe heart attack. I've met Felipe in Fortaleza a long time ago. I don't remember precisely when, but one of his first attitudes with me was to invite me to become a CEJUG Leader. I immediately accepted and I started helping him on several initiatives to make the Ceará Java Community grow up. We were together in this journey until last Friday, when he passed away. His last email to me was last Sunday, our last chat was also a week ago, and his last comment on my blog was last Thursday, copying a link to his most recent post on his blog, whose content is very related with what I wrote. He is also in my list of followers, on the right, and will remain there permanently.


I believe that we always get a bit of the personality of our closest friends to incorporate in our own. Felipe was the one who taught to share. No matter what, no matter how, but no idea should be completely trapped into our minds. Writing ideas on papers is not enough. They should be transmitted to other people, who are real agents of transformation. Felipe not only transmitted his ideas but also motivated people to empower them. I have the same belief and I don't know anyone like him, thus I definitely learned it from him.

Felipe was a young man with strong positions. It took time to convince him about other point of views, but he was the only one I know that once you get to change his position you will be the first one to know that. He comes back to the topic, merges points, discusses other details and goes on the direction of a better overall solution. I believe I improved my diplomacy skills discussing technology and community with him.

He became internationally well known by his open source initiatives and his passion for the Java community.
His focus: undergraduate students.
His intention: prepare students to better face the challenges of the software industry.
His weapon: Java.
His strategy: share learned lessons from the development of open source projects.
His hope: improve the quality of undergraduate courses in Brazil.

In a situation like this, when a young life is interrupted so abruptly, we start thinking how fragile life is. In any case, death is always shocking and touching, but when a person with a closer age dies we get to think about our own existence, how life is short, and how important is every minute breathing.

Rest in peace Felipe. Your family will be constantly comforted by God and You remain in our hearts.

Friday, March 5, 2010

Definitely e-Books

I have a lot of books. Really! I love books. I buy them because I need but sometimes just for the pleasure of having them. They are interesting but they are also so beautifully organized on my bookshelf. 8) But I feel deep inside that there is something wrong with it.

What am I gonna do when the time to leave Belgium comes? I'm inclined to donate most of my books, but how? to whom? I will think about it, but you can also suggest something on the comments below. By the way, one thing that I've learned was: before buying something, consider when the time to discard it finally comes. Might it be some sort of headache for you in the future?

Besides the space and weight issues, there is also the ecological one. Books are made of paper, paper is made of cellulose, cellulose is mostly extracted from the wood, wood is synonymous of tree and trees are one of the main agents of carbon absorption, besides their role on the soil stability and humidity control.

Considering these important reasons, I decided to prioritize the acquisition of eBooks (eletronic books) because they don't have weight, don't require physical space, the unitary impact on the nature is not so relevant, and the facility to transport, browse and search information makes it worth.

Leaving aside the physical beauty, I bought some technical eBooks from O'Reilly , Apress and Packt Publishing, but there are also The Pragmatic Bookshelf and the Amazon collection for the Kindle device. Many other publishers didn't start offering eBooks yet but it is a matter of time.

Buying eBooks directly from the publisher seems to be a good deal. I bought the book Restful Java with JAX-RS for $31.99 while the printed copy costs $39.99, saving $8. But the saving amount would be even higher when considering the shipping cost. On the other hand, the Kindle store doesn't offer a big discount on the Kindle version of a book. For instance, the paper version of the book Effective Java is sold for $35.11 and the Kindle version is offered for 38.64, a surprising higher price for a digital version, but still better due to the shipping cost.

I don't have a Kindle yet, but I'm planning to buy one or any other similar product. My main concern today is to buy books that can be used in my future book reader. For that, I'm avoiding to buy books with password protection. For instance, when opening books from Apress, the Acrobat Reader asks for a password key, which is provided at the moment of the acquisition. Better not forget this key, otherwise... :D

Wednesday, March 3, 2010

You Know What? I Love My Blog

During some procrastination time that I gave to myself last night, I've spent some time exploring all posts that I have published on my blog since 2007. I'm talking about 105 posts, an average of 4 per month, which is not that much in comparison to other more popular blogs, but at least I've been quite regular over the years.

All these posts tell a lot about my research time in Belgium, thoughts, wishes, ideas, opinions, and many more. It's so amazing the amount of experiences that I've shared with you, the feedback that some of you shared with me. Yeah! For me, post's comments are the best part of this blog.

I remember how happy I was when my blog was 1 year old with almost 300 unique visitors per month. I thought: “Wow! 300 different people reading my ideas! It's a lot of people!”. I wouldn't expect that 2 years later I would have more than 1.400 unique visitors per month. Today, I'm having the same thought I had 2 years ago, since 1.400 visitors is a lot of people too ;). But I know that some of you are laughing because it is still a small number in comparison with other popular blogs, but I'm proud of each one of my visitors, mainly the 450 ones that come here more than once every month.

I wish I could share more with you here because each post represents only 20% of the full experience that I have got writing it. Actually, I don't have any profit from here, making it more like a hobby than a responsibility. I even tried putting some Google advertizing on the right, but I've got only 3 clicks during these 6 months of exposure, which means absolutely nothing :D. What make it worth is the possibility to talk to my self, to talk to you like in a restaurant and the feedback I receive when I write technical articles, mostly solving basic problems that annoy a lot of people, and I receive comments from all over the world thanking for the solution I have proposed.

Now, I would like to conclude with a attempt of poem that stays in the subconscious of this blog:

I might regret but I don't

I might regret doing things not related to my work just to solve other people's problem, but I don't because those things taught me many other things that I didn't expect to learn.

I might regret starting my research so late, but I don't because pressure is also part of the game.

I might regret allowing my love to spend several weeks far from home, but I don't because it would be very selfish, these trips are great for her carrier, and I admire her achievements.

I might regret losing contact with some friends that I've made here, but I don't because they proved to be more selfish than the friendly acceptable.

I might regret drinking and eating too much some times, but I don't because Belgium has the best beers in the world, Europe has the best cuisine and I won't be here for so long.

I might regret giving up of opening a business in Europe, but I don't because what I'm planning now will help a lot more people than I was planning to help before.

Last but not least, I might regret to be too much optimistic even not archiving many wishes I had, but I don't because so many miracles have happened in my life, proving that optimism brings most of my wishes and what it doesn't bring I also gain in terms of lessons learned.
Thank you for your visit(s)!

Saturday, February 27, 2010

Sending E-mails with JavaMail on Glassfish V3

One of the main advantages of using an application server like Glassfish is to keep your application free of complex code, such as 1) manual control of database transactions; 2) database access configuration; 3) security authentication and authorization; 4) sending and receiving e-mail messages, among many other complexities that are non-functional requirements, consuming the time we would be spending on functional requirements.

In my opinion, an important differential of Glassfish V3 is its very rich and complete administration console. It is easy to use and to learn, which is, in my opinion, one of the most important competitive advantages, since it contributes to reduce the maintenance cost, a constant headache for system administrators. We have used the administrative console in a previous post to configure a database connection to PostgreSQL. Now, we are going to use it again in order to configure a JavaMail resource for applications that aim to send emails.

Follow the steps below:

  1. enter in the administrative console (http://[server-name]:4848/).
  2. go to Resources / JavaMail Sessions.
  3. create a new JavaMail session and set the following mandatory properties:
    JNDI Name: mail/[email-account-name]
    Mail Host: [smtp-server-address]
    Default User: the username to authenticate on the smtp server
    Default Return Address: the address used by recipients to reply the message. Some servers require that this address should be the one used by the authenticated user to access his mailbox.
If the server doesn't request secure authentication, then the three steps above are enough to start using the new JavaMail session, but a server without secure authentication is a very rare case nowadays. You will certainly need to inform a password to login on the smtp server. In most cases, the server administrator also changes the default port of the smtp server, which forces us to explicitly inform the correct port. For these special needs we can use additional properties in the JavaMail session. Follow the steps below:
  1. Still on the JavaMail session form, go to the Additional Properties section and add 3 more properties, which are:
    mail.smtp.port: [port-number]
    mail.smtp.auth: true
    mail.smtp.password: ****** ;)
  2. Click on Save to create the JavaMail session.
The last step is how to use this new JavaMail session in our applications to send emails. Using the JNDI name, we are going to inject the JavaMail session in a Java class, which could be a POJO of a pure web application, an EJB Session Bean, or any other type of class. See the code below for details:

public class UserAccountBsn {
  @Resource(name = "mail/[email-account-name]")
  private Session mailSession;

  public void sendMessage(UserAccount userAccount) {
    Message msg = new MimeMessage(mailSession);
    try {
      msg.setSubject("[app] Email Alert");
      msg.setRecipient(RecipientType.TO,
        new InternetAddress(userAccount.getEmail(),
        userAccount.toString()));
      msg.setText("Hello "+ userAccount.getName());
      Transport.send(msg);
    }
    catch(MessagingException me) {
      // manage exception
    }
    catch(UnsupportedEncodingException uee) {
      // manage exception
    }
  }
}

The @Resource annotation receives the JNDI name of the JavaMail session and injects an instance of the session in the variable mailSession. This variable is used within the sendMessage method to create a new MimeMessage. The content of the message is built and finally sent to the recipient by the method Transport.send. The method receives as parameter an entity class representing an user registered on the application. It is so simple, isn't it? ;)

Using this feature, we avoid any additional implementation to add those parameters hardcoded or parameterized, saving a lot of time, simplifying the maintenance of the applications, and reusing existing resources naturally shared by the container.

Friday, February 26, 2010

Creating a Connection Pool to PostgreSQL on Glassfish V3

I recently created a new connection pool to PostgreSQL on Glassfish and I would like to share the steps I followed with you. Obviously, you need PostgreSQL and Glassfish installed on your machine and a database already created in PostgreSQL. If you didn't configure your new PostgreSQL installation yet, follow the steps I described at this previous post and come back here to continue with the connection pool. The necessary steps are:

  1. We need the PostgreSQL JDBC Driver, since Glassfish and its deployed applications are writen in Java. Drivers are available for download at http://jdbc.postgresql.org. For this experiment choose the JDBC4 driver.
  2. Download the driver file postgresql-<version>.jdbc4.jar and copy it to the diretory [glassfish_home]/glassfish/domains/domain1/lib/.
  3. Restart Glassfish in order to make it load the new database driver. I thought that adopting an OSGI architecture Glassfish would never need restarts again, but I was wrong. At least, the restarting process is faster than V2.
  4. Enter in the administration console and go to Resources/JDBC/Connection Pools.
  5. Create a new connection pool with the name [database_name]Pool, select the resource type javax.sql.ConnectionPoolDataSource, select the database vendor PostgreSQL and click next.
  6. Select the datasource classname org.portgresql.ds.PGConnectionPoolDataSource and inform the following additional properties:
    DatabaseName=[database-name]
    Password=******* ;)
    PortNumber=5432 (this is the default port but make sure that you are using the correct one)
    ServerName=[server-name|ip]
    User=<database-username>
  7. Click Finish to save the new connection pool.
  8. Go to the list of connection pools again and select the new one that you just created.
  9. Click on Ping to check if the connection was correctly configured. The message "Ping Succeeded" means that the connection is working fine.
  10. In order to be able to use this connection pool in JEE applications, we have to create a JNDI name for it. Go to Resources/JDBC/JDBC Resources.
  11. Click on New and set the JNDI Name jdbc/[database_name], select the connection pool created above and click Ok to finish. This JNDI name will be used by applications to access the PostgreSQL database.
These instructions may work with Glassfish V2 as well, since its database configuration is quite similar.

I'm being very specific in terms of chosen technologies, but if you have a slightly different configuration and these steps are not working yet, please comment your issues below, describing also your current configuration/context. Maybe, we can figure it out.

Monday, February 22, 2010

Jamie Oliver for the Peace Nobel Prize

Last year Mr. Obama won the Peace Nobel Prize. There was a lot of controversy about this prize because the president of the United States didn't do anything concrete to bring peace to the world. I, particularly, didn't like the Nobel commission's choice for this prize. So, in order to fix this hasty decision, I would like to suggest a name for 2010: Jamie Oliver, the famous British chef! What???

Jamie figured out that he can actually change the world by changing people's eating habits. His mission statement seems really touching, inspiring and reachable actually.

“I wish for your help to create a strong, sustainable movement to educate every child about food, inspire families to cook again and empower people everywhere to fight obesity.”

Doing this, Jamie could save millions of lives all over the world reducing the obesity statistics and, consequently, making people feel really happy for doing something definitively useful, which is: feed people. Watch his message in this video below. It is more than convincing, it's touching.



You may think I'm exaggerating, but I'm not. I'm 31 years old and I started to cook at 30, less than 1 year ago. I know by a matter of fact what Jamie is trying to say. I know how good cooking means for mental health :D. If you have a family to care about and you go to the kitchen with the mission to feed them, you see exactly your importance in other people's life cycle in the simplest way possible. That's why cooking is worth experiencing.

These two pictures below show two of Jamie's recipes that we have made at home and they are simply amazing.
Poulet et Poireaux Stroganoff

Côtelettes D'Agneau Grillées Avec Une Riche Salsa

Look at the details about Jamie's plan here and start helping him to accomplish this by just spreading the wonderful art of cooking. If somehow you are not motivated enough, watch the movie Julie & Julia and you will be sufficiently motivated. Trust me! ;)