Rebirth of T-rex

Does dinosaur really extinct? What caused the dinosaur to vanish? Have you ever wonder whether the real 'you' is disappearing and slowly vanishing? Hope that through this blog, we will be able to maintain the real self.

Introduction to Portal and Portlet

Posted by T-rex Lim Huat Heng

The following are important points extracted from the JSR 168 Portlet Specification for quick reference. Please download the Java API and specification from the above hyperlink for further details.

What is a Portal?

=> A web based application that commonly provides personalization, single sign on, content aggregation from different sources and hosts the presentation layer of Information Systems.

Portal pages may have different set of portlets creating content for different users.

What is a Portlet?

=> A Java technology based web component, managed by a portlet container, that processes requests and generates dynamic content.

Portlets are used by portals as pluggable user interface components that provide a presentation layer to Information System.

Lifecycle of portlet is managed by the portlet container.

Fragment => Content generated by a portlet. A piece of markup (eg. HTML, XHTML, XML) adhering to certain rules and can be aggregated with the content of other portlets to form the portal page. May vary from one user to another depending on the user configuration for the portlet.

Web clients interact with (usually the content produced by) portlets via a request/response paradigm implemented by the portal. Eg. by following a links or submitting forms -> portlet actions received by the portal, forwarded to the portlets targeted by user's interactions.

What is a Portlet Container?

=> runs portlets and provides them with the required runtime environment.

Contains portlets and manages their lifecycle. Also provides persistent storage for portlet preferences.

Receives requests from the portal to execute requests on the portlets hosted by it.

Not responsible for aggregating the content produced by the portlets (but portal's responsibility to handle it).

A portal and a portlet container can be built together as a simple component of an application suite or as two separate components of a portal application.

An Example

A typical sequence of events, initiated when users access the portal page:

  • A client (eg. a web browser) after being authenticated makes an HTTP request to the portal
  • The request is received by the portal
  • The portal determines if the request contains an action targeted to any of the portlets associated with the portal page
  • If there is an action targeted to a portlet, the portal requests the portlet container to invoke the portlet to process the action
  • A portal invokes portlets, through the portlet container, to obtain content fragments that can be included in the resulting portal page
  • The portal aggregates the output of the portlets in the portal page and sends the portal page back to the client

'Sneak Preview' of Açaí Berry

Posted by T-rex Lim Huat Heng


Recently, I have just come across an interesting fruit, in particularly the Açaí Berry. The more I research on this 'super fruit', the more I am getting excited on the benefits it brings. Since I may take slightly longer time to compile more details in this blog, let me provide you some 'sneak preview' of it. The following information are quoted from other resources.


Açaí Berry- The Gift of Nature

Hidden deep within the Amazon rainforest of Brazil is a small, dark berry that posses scientific properties claimed by no other fruit. This deep purple, grape sized, nutrient dense fruit grows at the top of towering Açaí trees. It boasts the protein profile of an egg, a fatty acid ratio similar to olive oil, and has more than 30 times the antioxidant power of red grapes. It also packs vitamin B1, B2, B3, E, and C, phosphorus, calcium, potassium, and fiber.



Oprah Winfrey touts the Açaí Berry as the #1 food to keep you looking and feeling younger



Dr. Nicholas Perricone calls the Açaí Berry "one of the most nutritious and powerful foods in the world."

My First Sample Java Application on Facebook

Posted by T-rex Lim Huat Heng

Since Mandy introduced Facebook to me, I am kind of addicted to it. I admit that it's one of the 'must-open' application when I start my notebook, besides my Microsoft Outlook.


However, since I am a developer myself, passion for Java language, I have always been interested to try out a Java application deployed on Facebook.


Then, I found out a very good tutorial with video guiding how to build and deploy a sample Java application on Facebook. I have to admit that I really need to thank The Screencast Blog to help me kick start my trial.


Since the blog was written in June 2007, I believe there are a number of changes to the Facebook API, I was stucked following the sample provided (with compilation error and NullPointerException). For instance, someone suggested the usage of FacebookRestClient class needs to be replaced by FacebookXmlRestClient.


I have looked at several other blogs including the Javablog and T=Machine for references, but to no avail as these blogs were written last year also.


Although it may seem that I can't proceed further with the lack of documentation on Java application for Facebook, but as usual, it's not the end of the world, Google comes to my rescue! Google Code provides a wrapper- the Facebook-Java-API that solves my problem. The Javadoc is also available for reference.


Therefore, the following are simplified steps to produce my first sample Java application on Facebook (based on The Sceencast Blog example).


My development environment:



Steps:


In Facebook



  1. Login to Facebook using your valid account (register one if you don't have).

  2. Access Developer application, click Add Application button on the top right panel.

  3. Then click on Add Developer button. A confirmation message is shown upon successful addition of the application.

  4. Go to the application Developer. Then, click + Set Up New Application button.

  5. Enter the Application Name (as MyFirstSampleFacebookJavaApp) and select the check box. Then, click Submit button. API Key is created. Note that the API Key and Secret key values are required later.

  6. Click Edit Settings link. Key in the Callback Url as http://localhost:8080/MyFirstSampleFacebookJavaApp/LoginServlet (This is the URL to the Java Servlet that will be created below). Then, click Save button.

In Eclipse



  1. Select from menu File > New > Project...
  2. Select Web > Dynamic Web Project in the New Project pop-up window. Then, click Next > button.
  3. Key in the Project name and select Target Runtime with the following values. Then, click Next > button.

    • Project name: MyFirstSampleFacebookJavaApp
    • Target Runtime: JBoss

  4. Ensure the version of Dynamic Web Module and Java are correct. Then, click Next > button and Finish button.


    • Dyname Web Module: 2.5
    • Java: 6.0

  5. Click on Yes when prompted to change to J2EE perspective.
  6. Add Facebook Java API JAR (facebook-java-api-1.7.3.jar) and JSON JAR (json-1.0.jar) into the WEB-INF\lib folder
  7. Add the source code (downloaded from the SVN) into the src folder.
  8. Right click on the project name and select New > Other... from the pop-up menu. Then, select Web > Servlet and click Next > button.
  9. Enter the Java package and Class name with the following values. Then, click Next > button. Please note that if the Java package is refactored after this step, the web.xml need to be amended accordingly.


    • Java package: com.fbdev.app.java.servlet
    • Class name: LoginServlet

  10. Add Initialization Parameters by clicking the Add... button. First add the parameter API_KEY with the following values, then click OK button.


    • Name: API_KEY
    • Value: (value in Facebook stated in Step 5 above. eg. 121036f141717859e681df3522bb04ec)

  11. Repeat the above step for parameter SECRET_KEY. Then, click OK button, followed by Next > button and Finish button.


    • Name: SECRET_KEY
    • Value: (value in Facebook stated in Step 5 above. eg. 87acfde11abd748f24e03bf5612bac62)

  12. Add the following code into doGet method.


    • String apiKey = getServletConfig().getInitParameter("API_KEY");
      String secretKey = getServletConfig().getInitParameter("SECRET_KEY");
      FacebookRestClient fbRestClient = null;
      HttpSession session = request.getSession();
      String sessionKey = (String) session.getAttribute("facebookSession");
      String token = request.getParameter("auth_token");
      if(sessionKey != null && sessionKey.length() > 0) {
      fbRestClient = new FacebookRestClient(apiKey, secretKey, sessionKey);
      }
      else if(token != null) {
      fbRestClient = new FacebookRestClient(apiKey, secretKey);
      fbRestClient.setIsDesktop(false);
      try {
      sessionKey = fbRestClient.auth_getSession(token);
      session.setAttribute("facebookSession", sessionKey);
      }
      catch (FacebookException e) {
      e.printStackTrace();
      }
      }
      else {
      response.sendRedirect("http://www.facebook.com/login.php?api_key=" + apiKey + "&v=1.0");
      return;
      }
      playWithFacebookAPI(request, fbRestClient);
      request.getRequestDispatcher("info.jsp").forward(request, response);

  13. Add a new method playWithFacebookAPI with the following code.


    • private void playWithFacebookAPI(HttpServletRequest request,
      FacebookRestClient fbRestClient) {
      try {
      long myId = fbRestClient.users_getLoggedInUser();
      EnumSet<ProfileField> fields = EnumSet.of(ProfileField.NAME, ProfileField.PIC);
      Collection<Long> users = new ArrayList();
      users.add(myId);
      Document d = fbRestClient.users_getInfo(users, fields);
      String name = d.getElementsByTagName("name").item(0).getTextContent();
      String picture = d.getElementsByTagName("pic").item(0).getTextContent();
      request.setAttribute("name", name);
      request.setAttribute("picture", picture);
      } catch (FacebookException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }
      }

  14. Right click on the project name and select New > Other... from the pop-up menu. Then, select Web > JSP and click Next > button.
  15. Key in the File name as info.jsp, then, click Next > button.
  16. Select New JSP file (xhtml) as the JSP Template and click Finish button.
  17. Modify the JSP to have the following content (an extract)


    • <title>My First Sample Facebook Java Application</title>
    • <body>
      <div>
      ${requestScope.name }
      </div>
      <div>
      <img src="${requestScope.picture }"></img>
      </div>
      </body>

  18. Publish the application to the JBoss server. In Servers view, right click on the JBoss 4.2 and select Publish from the pop-up menu. (If it is the first time, right click on the project name, select Run As > Run on Server from the pop-up menu. Then select JBoss 4.2 from the list and click Next > button. Select MyFirstSampleFacebookJavaApp and click Add > button. Next click Finish button.)

In Browser



  1. Access http://localhost:8080/MyFirstSampleFacebookJavaApp/LoginServlet

  2. Login with valid Email and Password. Then, click Login button.

  3. Click Log in to MyFirstSampleFacebookJavaApp button.

  4. The page will show the user id and photo of the user.

A 'Heart' Alert

Posted by T-rex Lim Huat Heng

Upon returning from lunch, Ming, our colleague who didn't join us for lunch, told us that his friend, at his 30s, just diagnosed with coronary artery clog. My first reaction was, 'Ming, what did you just said?' Ming answered, 'My friend who is on his 30 plus just got a heart attack and need to undergo an operation (which I believe is called Angioplasty)'. After trying to find out more information from him, I shared with him what I have encountered two years back during my dad's stay in the hospital after a surgery.

During that time, my dad was suffering from water clogging in his brain as one of the side effects from the radiotherapy. I guess you must be wonder why water clog in the brain after the radiotherapy. Based on my understanding from the doctor, there are cells in our brain that are 'in-charge' of draining off water from the brain to be 'released' from our body. However, many of those cells were dead after the radiotherapy and water was not drained off, thus clogging in the brain.

Doctor has installed a B-P shunt to regulate the water in his brain, such that the 'extra' ones are drained off to his bladder through the narrow tube embedded within his body near the skin surface. He was there for the 'maintenance', to replace a small part of the tube that was clogged by tiny dead cells.

It was during that time, I saw a young man, at his 20s was admitted to this wad and was in coma state. Later we found out, he was working in KL and suddenly colapsed. Apparently they found that the blood vessels in his brain burst. He did not make it and passed away in the morning on the same day my dad was discharged from the hospital. I saw the sorrow of his crying family members upon receiving the bad news.

As I was writing this blog, I come across the website of 'CRY' for Cardiac Risk in the Young - Sudden Cardiac Death (SCD), Sudden Death Syndrome (SDS). Once you enter the page, you will realize the highlighted statement of 'Every week, 8 'apparently' fit and healthy young people die in the UK from undiagnosed heart conditions.' At the same time, I also come across a useful nutritional tips for healthy heart by Julie Upton at Howstuffworks, which may be useful for our reference.

In fact, when I was on my way back home on the LRT, I was telling myself that I have a piece of important source of information about heart health and I must try to share with Ming and the rest at the soonest. Since it's part of my life crusade to help 1 million people through knowledge sharing, that's my duty to share about what I have learnt from a doctor who have survived for more than 25 years after suffered from two cancers. I met this doctor two years back in Singapore. I felt gratitute even though I had travelled all the way from KL to Singapore to attend her health seminar.

I understand the sense of urgency more this time, as I have also gone through several occasions of 'it's too late' and eventually the person I was trying to share the information with died not long after that. Therefore, Ming, please give me a day or two to compile what I have. I will be able to share with you at the soonest and hope that will also help you friend who have successfully gone through the surgery.