Sunday, March 20, 2011

Richfaces showcase on Amazon's Elastic Beanstalk

Richfaces 4 is around the corner and it runs pretty much same in both Tomcat and JBoss. The major difference is that with Tomcat, you have to bundle in your .war a JSF implementation which could be Mojarra or MyFaces. I don't have a preference on JSF implementation at this stage.  Given that Richfaces runs without problem on Tomcat, I thought I should take AWS Elastic Beanstalk for a ride. As it turns out deploying is as simple as deploying it to your local tomcat instance which is a good thing but it also differs a bit.

In following screen shot, you can see that  I have chosen Richfaces showcase application (showcase.war) which I want to deploy on a 32-bit Linux OS running Tomcat 6. Once app is deployed, it should be deployed on http://prabhat.elasticbeanstalk.com (I have shut down my instance so link wont work).



When I deployed my app, I expected my app to be available at http://prabhat.elasticbeanstalk.com/showcase in line with what I get when I deploy the app locally which is http://localhost:8080/showcase . But Beanstalk renames the .war and deploys it as /usr/share/tomcat6/webapps/ROOT which is why it's available under root context . This is important to know because in the next step of configuration, you would  need to supply the URL which can be used for health check. I initially provided /showcase and I ran into problem. Following is what should be:



Other noteworthy differences or rather limitations are that currently Beanstalk configuration does not give you options to edit JVM parameters initially. Once you have instance up and running, it does give you an option to edit JVM configurations as well pass five application specific parameters but the name of parameters has to be PARAM1, PARAM2 ... May be this will be fixed in future versions or it's already available and I don't know. The latter is likely given that I did not spend a whole lot of time on it.  Anyway, here is screen shot of app running on Beanstalk.







Tuesday, March 8, 2011

Quick tip on hibernate batch operation

You can find the details of what batch operation with respect to DB is and related Hibernate guide at http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html . Any time you need to do bulk inserts/updates, it's better to do in batch to get a better performance. Recently I was developing a small app and followed Hibernate guide to make sure that my configurations were correct. Even after trying several things, I kept seeing following in log generated by Hibernate:

Hibernate: insert into Member (name, id) values (?, ?)
Hibernate: insert into Member (name, id) values (?, ?)
Hibernate: insert into Member (name, id) values (?, ?)
Hibernate: insert into Member (name, id) values (?, ?)
Hibernate: insert into Member (name, id) values (?, ?) 


But batch operation is supposed to generate statements like


insert into Member (name, id) values ('name0', 1),('name1', 2),('name2', 3),('name3', 4),('name4', 5),('name5', 6),('name6', 7),('name7', 8),('name8', 9),('name9', 10),('name10', 11),('name11', 12),('name12', 13),('name13', 14),('name14',
15),('name15', 16),('name16', 17),('name17', 18),('name18', 19),('name19', 20)


It turns out that even when batch operation is in progress, hibernate log shows individual operation. If you don't know this, you might be up for a ride figuring out what the heck is going on. The best way to make sure is to turn on the query logs in DB itself. For MySQL5 installed on Fedora, you do it by adding log parameter at /etc/my.conf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log=/var/log/mysqld.log


You should see statements like following at /var/log/mysqld.log :

2 Query insert into Member (name, id) values ('name0', 1),('name1', 2),('name2', 3),('name3', 4),('name4', 5),('name5', 6),('name6', 7),('name7', 8),('name8', 9),('name9', 10),('name10', 11),('name11', 12),('name12', 13),('name13', 14),('name14',
15),('name15', 16),('name16', 17),('name17', 18),('name18', 19),('name19', 20)
2 Query    commit


The complete test project is at http://anonsvn.jboss.org/repos/qa/prabhat/batch-insert . The relevant hibernate configuration is at http://anonsvn.jboss.org/repos/qa/prabhat/batch-insert/src/main/resources/hibernate.cfg.xml . If you are letting hibernate generate the primary key then don't use GenerationType.Identity in your  model otherwise batch insert will not take place.

Wednesday, March 2, 2011

New guide, tips and tricks for GateIn

Recently my team members published several how-to docs and guides on customizing GateIn Portal which applies to Enterprise Portal Platform (EPP) in most cases as well. Here is a compilation of those docs in one place:



The first two articles use extension mechanism which means that there is no or very very minimal change to OOB GateIn. I believe these docs should help you do an efficient customization of GateIn for your use.

Wednesday, February 16, 2011

JBoss PortletBridge talk at Austin JUG

Come hear yours truly talk about JBoss Portletbridge at this month's Austin JUG meeting on Feb 22. The details of talk is at http://austinjug.org/index.jsp?p=events-20110222 There will be free pizza and thanks to Red Hat for sponsoring my talk.

On personal note, as part of my Eejot (www.eejot.org) effort, pls bring any old laptop you have that you are not using too much. You can tax deduct your contribution.

Monday, December 6, 2010

Thoughts on recent Hudson trademark issues

Recently I have seen several tweets and blogs on forking Hudson and I also come across this article on how Oracle is trying to assert its trademark on Hudson. This trademark thing simply disgusts me to say the least.

I have been involved with Hudson from very early days and I think my first post to Hudson's user mailing list was in early 2007 and I even wrote a little portlet that aggregated data from Hudson. I am not a kind of guy who tries to get his head around copyright issues and different OSS licenses but I always understood that

  • Hudson started as Kohsuke Kawaguchi's pet project and he worked on top of his regular day job
  • Kohsuke did and still does an awesome job of being involved with community and as a result got several committers and plugin developers
  • Hudson got popular enough that Sun thought it deserved Kohsuke's full attention and they also started selling support for it.
So more or less Hudson has been a perfect example of OSS where both project and community have had mutual relationship. Why would anyone want to impose a trademark on it? Oracle has been in news mainly for bad reasons among java community and this simply asserts why java community does not trust Oracle to be a good steward for Java. Leave Hudson as it is Oracle and start working with community, not against it. !!

Wednesday, November 17, 2010

Richfaces : ReThink Before ReRender

Sometimes when you go deeper into a framework or a tool , you tend to take beginner stuff for granted. That bit me today for a while before I could get my head around it.  ;-)

When using Ajax, it's a well known fact that for you to manipulate a DOM element, that element needs to be present. Same rule applies when you are using reRender in Richfaces as well. Let's take a look at following code snippet:

<rich:panel header="Add New Application">
   <h:outputText value="App Name " />
   <h:inputText size="20" id="appNameInput" value="#{appConfigBean.currentApp.appName}" />
   <a4j:commandButton id="new_app_submit" action="#{appConfigBean.addNewApp}"     
    value="Add" reRender="appDetails" />
</rich:panel>


<h:panelGrid columns="2" id="appDetails" 
                rendered="#{appConfigBean.renderDetail}">
      <h:outputText value="Some stuff"/>
</h:panelGrid>


The addNewApp method in backing bean sets renderDetail to true which initially was false. So when you click Add button, you would expect reRender to kick in and show the panelGrid with id appDetails. Nope. It does not happen. From second paragraph you might have understood the reason already. But here is a more detailed explanation.

Since initially, renderDetail boolean is set to false, when the page is first loaded, the html for panelGrid never gets rendered hence there does not exist a DOM element with id appDetails and reRender does not know what to update.

To fix this, the easiest and probably the best solution is to surround panelGrid with a4j:outputPanel and you would put this output panel's id for reRender to do its magic.  Here is the updated code:

<a4j:commandbutton id="new_app_submit">
                      action="#{appConfigBean.addNewApp}" value="Add"
                      reRender="appDetailOutputPanel" /&gt; 

<a4j:outputpanel id="appDetailOutputPanel"> 
     <h:panelgrid columns="2" id="appDetails">
                     rendered="#{appConfigBean.renderDetail}"&gt;
          <h:outputtext value="Some stuff"></h:outputtext>
     </h:panelgrid>
</a4j:outputpanel>

Tuesday, November 2, 2010

Tips when using AWS sdk with JBoss AS + GateIn

While working on a really cool portlet for GateIn that uses Quartz scheduler and AWS sdk which I am going to unveil to the rest of the world in few days ;-), I came across a weird problem. :


Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.xml.xpath.XPath.setNamespaceContext(Ljavax/xml/namespace/NamespaceContext;)V" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/quartz/xml/XMLSchedulingDataProcessor, and the class loader (instance of ) for resolved class, javax/xml/xpath/XPath, have different Class objects for the type javax/xml/namespace/NamespaceContext used in the signature


This kind of error obviously suggests some conflict with classloader and that was the case in this scenario too. I initially thought it must be something with quartz because I am using Quartz's XMLSchedulingDataProcessorPlugin but looks like that dependency comes from AWS sdk. To get it working, I simply removed stax-api-1.0.1.jar from WAR file and portlet deployed fine. The conflict happens because GateIn 3.0.1.GA + JBoss AS 5 combination has stax-api.jar under GateIn-3.1.0-GA/lib/endorsed which means StAX library is a system-wide library.