<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>java-ee &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://wordpress.com/tag/java-ee/</link>
	<description>Feed of posts on WordPress.com tagged "java-ee"</description>
	<pubDate>Fri, 25 Jul 2008 16:30:50 +0000</pubDate>

	<generator>http://wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[AppFuse Your Project For a Skyrocketing Start]]></title>
<link>http://dhydrated.wordpress.com/?p=137</link>
<pubDate>Tue, 22 Jul 2008 08:49:46 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=137</guid>
<description><![CDATA[Need to start a project in lightning speed? If you want to skip those dirty works in setting up a pr]]></description>
<content:encoded><![CDATA[<p>Need to start a project in lightning speed? If you want to skip those dirty works in setting up a project framework, well..., I just found out a great utility just for that. It is called Appfuse 2. Now with version 2, it is tied together with Maven 2 which makes the setup a lot easier. The prerequisites for applying Appfuse is Maven 2 and MySQL 5. You need to install these 2 in your machine.<br />
There are several archetypes you could choose from, and for the sake of writing, I just choose <em>appfuse-basic-jsf</em>. So I just run below command, it will create a project with JSF,Spring &#38; Hibernate. There are also other persistence files included, such as JPA and iBatis.</p>
<p><span style="color:#00ff00;"><strong>mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-jsf -DremoteRepositories=<span class="nobr">http://static.appfuse.org/releases</span> -DarchetypeVersion=2.0.2 -DgroupId=org.dhydrated.appfuse.jsf -DartifactId=appfuseJsfWeb</strong></span></p>
<p>Then, I need to tweak the <em>pom </em>according to my MySQL installation. By default, it uses <em>root</em> with no password as the MySQL user. So I just simply add my password in the <em>pom </em>file below.</p>
<p>[sourcecode language='xml']</p>
<p><?xml version="1.0" encoding="UTF-8"?></p>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<p><modelVersion>4.0.0</modelVersion><br />
<groupId>org.dhydrated.appfuse.jsf</groupId><br />
<artifactId>appfuseJsfWeb</artifactId></p>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version><br />
<name>AppFuse JSF Application</name><br />
<url>http://www.mycompany.com</url><br />
...</p>
<properties>
...<br />
<jdbc.username>root</jdbc.username><br />
<jdbc.password>password</jdbc.password>
</properties>
</project>
<p>[/sourcecode]</p>
<p>Then, I run below command and let Maven 2 do all the boring stuffs such as dependencies checking, creating tables in database and etc. It will take a while if you doing it for the first time.</p>
<p><span style="color:#00ff00;"><strong>mvn</strong></span></p>
<p>Then, I need to package it into war, so I just simply run below command.</p>
<p><span style="color:#00ff00;"><strong>mvn war:war</strong></span></p>
<p>Next, I need to tweak again the pom since I'm deploying the application into Glassfish 2 in my machine. By default, the application is set to run with Jetty or Tomcat. So if your choice of application server is one of these default settings, you can skip this step. I'll add below maven plugin to enable me to deploy my application into Glassfish 2.</p>
<p>[sourcecode language='xml']</p>
<p><?xml version="1.0" encoding="UTF-8"?></p>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><br />
...<br />
    <build><br />
        <finalName>${artifactId}</finalName></p>
<plugins>
<plugin>
                <groupId>org.codehaus.mojo</groupId><br />
                <artifactId>exec-maven-plugin</artifactId><br />
                <executions><br />
                    <execution><br />
                        <id>deploy</id><br />
                        <goals><br />
                            <goal>exec</goal><br />
                        </goals><br />
                    </execution><br />
                </executions><br />
                <configuration><br />
                    <executable>C:/Program Files/glassfish-v2ur1/bin/asadmin.bat</executable><br />
                    <arguments><br />
                        <argument>deploy</argument><br />
                        <argument>--user=admin</argument><br />
                        <argument>--passwordfile="C:/passwordfile.txt"</argument><br />
                        <argument>--host=localhost</argument><br />
                        <argument>--port=14360</argument><br />
                        <argument>target/${artifactId}.${packaging}</argument><br />
                    </arguments><br />
                </configuration>
            </plugin>
            ...
        </plugins>
    </build><br />
    ...
    </project>
<p>[/sourcecode]</p>
<p>Above, I'm using <em>exec-maven-plugin </em>to run an executable command to deploy my <em>war </em>into Glassfish 2. In order to call above plugin, I typed below command.</p>
<p><span style="color:#00ff00;"><strong>mvn exec:exec</strong></span></p>
<p>After that, you should be able to see your application is being deploy from your server console. After all these steps, Presto!, now you have a full-fledged Java Enterprise application running on your server. Thanks to Spring, it is also equipped with security and transaction management. Couple of users with specific roles are already included.</p>
<p>If I run my application, I should get the Login page as below.</p>
[caption id="attachment_142" align="alignnone" width="510" caption="appfuse-jsf-login"]<a href="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-login.jpg"><img class="size-full wp-image-142" src="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-login.jpg" alt="appfuse-jsf-login" width="510" height="446" /></a>[/caption]
<p>Above is the login page. One of the default user is admin.</p>
[caption id="attachment_143" align="alignnone" width="510" caption="appfuse-jsf-home"]<a href="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-home.jpg"><img class="size-full wp-image-143" src="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-home.jpg" alt="appfuse-jsf-home" width="510" height="448" /></a>[/caption]
<p>Above is the home page once you are logged in. It uses Struts-Menu for menu layout.</p>
[caption id="attachment_144" align="alignnone" width="510" caption="appfuse-jsf-users"]<a href="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-users.jpg"><img class="size-full wp-image-144" src="http://dhydrated.wordpress.com/files/2008/07/appfuse-jsf-users.jpg" alt="appfuse-jsf-users" width="510" height="447" /></a>[/caption]
<p>It also includes CRUD pages for Users.</p>
<p>How's that for speed? It only took 10 minutes to create this application (if you know how to do it, of course). There are several other UI frameworks you could choose from, besides JSF. I guess the 2 most commonly used are JSF and Struts2. If I only knew about Appfuse 2, I would have used it on my last project. It is awesome. I don't need to do all the basic stuffs anymore and I can just straight away focus on the business requirements. Yeah!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Pengantar Java Platform]]></title>
<link>http://ghanoz2480.wordpress.com/?p=89</link>
<pubDate>Sat, 19 Jul 2008 18:15:42 +0000</pubDate>
<dc:creator>ghanoz2480</dc:creator>
<guid>http://ghanoz2480.wordpress.com/?p=89</guid>
<description><![CDATA[Apa yang dibutuhkan?
Sebelum kita bisa membuat aplikasi yang ditulis dengan bahasa Java, dibutuhkan ]]></description>
<content:encoded><![CDATA[<h4>Apa yang dibutuhkan?</h4>
<p align="justify">Sebelum kita bisa membuat aplikasi yang ditulis dengan bahasa Java, dibutuhkan <em>Java Platform Standard Edition</em> (Java SE) <em>development kit</em>. <em>Developemnt kit</em> itu berisi J<em>ava Virtual Machine</em> (JVM), <em>core Application Programming Interface</em> (API), dan kompiler yang digunakan untuk <em>development</em>.</p>
<p align="justify">Untuk pengguna Mac sebaiknya mengunjungi <a href="http://developer.apple.com/java/">http://developer.apple.com/java/ (Mac OS X Java Runtime Environment)</a>.</p>
<p align="justify">Jika ingin mengerjakan dalam <em>Integrated Development Environment</em> (IDE), kunjungi <a href="http://java.sun.com/javase/downloads/">http://java.sun.com/javase/downloads/</a> (untuk men-<em>download</em> Java SE dengan NetBeans IDE).</p>
<p align="justify">Untuk beberapa proyek, mungkin Anda membutuhkan berkas tambahan. Tetapi jika Anda masih belum mengetahui apa yang Anda butuhkan Java SE saja sudah cukup untuk memenuhi kebutuhan Anda sampai familiar dengan Java <em>platform</em>. Di bawah ini yang adalah yang populer untuk di-<em>download</em>.</p>
<ul>
<li>Java SE
<p align="justify">Anda bisa mendapatkan Java SE di <a href="http://java.sun.com/javase/">http://java.sun.com/javase/</a>, <em>kit</em> ini sangat dibutuhkan untuk menghasilkan semua aplikasi, kecuali yang dirancang khusus untuk perlengkapan konsumen (<em>consumer devices</em>) digunakan <em>Java Platform Micro Edition</em> (Java ME). Java SE terdiri dari kompiler, <em>runtime environment</em>, dan <em>core</em> API.</p>
</li>
<li>Java Platform Enterprise Edition (Java EE)
<p align="justify">Anda bisa mendapatkannya di <a href="http://java.sun.com/javaee/">http://java.sun.com/javaee/</a>. Paket ini terdiri dari <em>application server</em>, dan teknologi <em>JavaServerPages</em> (JSP). Gunakan J2EE dengan Java SE.</p>
</li>
<li>Java Platform Micro Edition (Java ME)
<p align="justify">Anda bisa mendapatkannya di <a href="http://java.sun.com/javame/">http://java.sun.com/javame/</a>. Digunakan jika ingin menghasilkan program untuk Palm Pilots, <em>screen phones</em>, dan <em>consumer device</em> yang lainnya. Java ME menyediakan <em>tools</em> untuk <em>compiling</em>, <em>deployment</em>, dan konfigurasi alat (<em>device configuration</em>), dan API yang dikhususkan untuk setiap <em>device</em>.</p>
</li>
<li>JavaFX Script Technology
<p align="justify">Anda bisa mendapatkannya di <a href="https://openjfx.dev.java.net/">https://openjfx.dev.java.net/</a>. JavaFX Script Technology merupakan bahasa <em>scripting</em> yang sangat produktif, yang memungkinkan pembuat <em>content</em> (<em>content developers</em>) untuk membuat media yang kaya dan <em>content</em> untuk <em>deployment</em> pada <em>Java environments</em>.</p>
</li>
</ul>
<p align="justify"><em>Development kit</em> yang sudah dijelaskan diatas memasukkan API yang dibutuhkan untuk berbagai macam tipe aplikasi apapun yang Anda hasilkan dalam bahasa pemrograman Java.</p>
<p align="justify">Java API adalah kumpulan (<em>libraries</em>) dari kode yang sudah disusun, untuk menambahkan fungsionalitas yang sudah dibuat dan dapat dirubah, sehingga menghemat waktu <em>coding</em>.</p>
<p align="justify">Program-program Java dieksekusi dalam program yang dinamakan JVM (<em>Java Virtual Machine</em>) daripada dijalankan langsung pada sistem operasi (<em>native operating systems</em>), program di-<em>interpreted</em> oleh JVM untuk <em>native operating systems</em>.  Hal tersebut membuat program yang ditulis dengan bahasa Java dapat berjalan dari satu <em>platform</em> ke <em>platform</em> lainnya. Dengan kata lain kita dapat membuat program di Solaris, Linux, Macintosh, atau Windows, dan dapat dijalankan pada <em>server</em> atau <em>platform</em> yang lain.</p>
<h4>Membuat Program Java dengan Three Basic Flavors</h4>
<p align="justify">Setelah Anda memiliki <em>development kit</em> yang dibutuhkan, baru kita bisa menulis program dalam bahasa Java. Kita dapat menulis program dengan tiga basic flavors, yaitu <em>applet</em>, aplikasi dan <em>servlets/JSP pages</em>. <em>Applet</em> berjalan dalam JVM yang ditambah ke dalam <em>web browser</em>, aplikasi berjalan dalam JVM yang ter-<em>install</em> dalam sistem komputer, dan yang terakhir <em>servlets/JSP</em> berjalan dalam JVM yang ter-<em>install</em> dalam <em>web server</em>.</p>
<p align="justify">Sedangkan <em>applet</em> dan aplikasi biasanya memiliki suatu antar muka (<em>user interface</em>) yang dipasangkan dengan fungsionalitas <em>backend</em>, <em>servlet</em> hanya menyediakan fungsionalitas <em>backend</em> saja.</p>
<p align="justify">Antar muka yang digunakan untuk <em>servlet</em> biasanya dalam bentuk HTML pada browser yang men-<em>invoke servlet</em>, tetapi setiap <em>applet</em> atau aplikasi yang membuka permintaan <em>Hypertext Transfer Protocol</em> (HTTP) dapat memanggil sebuah <em>servlet</em>. Dan sebaliknya, JSP, menggabungkan <em>servlet</em> dan HTML ke dalam satu komponen. Selain menggunakan halaman HTML dengan <em>servlet</em> terpisah, Anda bisa menggunakan halaman HTML dengan tag HTML yang biasa (<em>regular</em>) dengan gabungan <em>scriptles</em>, potongan-potongan pendek kode. Seluruh halaman lalu mengolahnya ke dalam <em>servlet</em> ketika diakses atau diserahkan dan hasilnya kembali ke halaman HTML yang sama, yang mengandung kode tersebut.</p>
<h4>Sumber</h4>
<ol>
<li>Nourie, D., and Pawlan, M., “<em>Introduction to Java Platform</em>”, Updated July 2007, <a href="http://java.sun.com/new2java/programming/intro/">http://java.sun.com/new2java/programming/intro/</a></li>
</ol>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Persistence Gone Awry with Ms Access]]></title>
<link>http://dhydrated.wordpress.com/?p=115</link>
<pubDate>Wed, 16 Jul 2008 07:01:47 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=115</guid>
<description><![CDATA[I was given a task to work on Ms Access database. I had to choose either JDBC, iBatis and Hibernate ]]></description>
<content:encoded><![CDATA[<p>I was given a task to work on Ms Access database. I had to choose either JDBC, iBatis and Hibernate for the persistence mechanic. So I tried each of them to see which one is the best.</p>
<p>First, I worked with JDBC with Spring. Below is one of the query where I mapped the result to <em>Country</em> object.</p>
<pre>[sourcecode language="java"]
public class CountryDaoJdbcImpl extends AbstractJdbcDao implements CountryDao {

    public List getAllCountries() {

        List countries = getJdbcTemplate().
                query(
                "SELECT * FROM Country_Code", new RowMapper() {

            public Object mapRow(ResultSet rs, int rowNum)
                    throws SQLException, DataAccessException {
                Country country = new Country();
                country.setCode(rs.getString(1));
                country.setName(rs.getString(2));
                country.setIsdCode(rs.getString(3));
                return country;
            }
        });

        return countries;
    }
}
[/sourcecode]</pre>
<p>It is easy to implement but the code is too verbose. Plus, if I have relationships between objects, the code will be more complicated and maintenance would be tough.</p>
<p>Then, I tried to implement iBatis with Spring. Below is the iBatis config for an object with a relationship with another object.</p>
<pre>[sourcecode language='xml']
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="General">

    <resultMap id="CategoryResultMap" class="Category" groupBy="categoryCode">
        <result property="categoryCode" column="categoryCode" />
        <result property="description" column="description" />
    </resultMap>    

    <resultMap id="SubCategoryResultMap" class="SubCategory" groupBy="subCategoryCode">
        <result property="subCategoryCode" column="subCategoryCode" />
        <result property="description" column="description" />
        <result property="categoryCode" column="categoryCode" />
        <result property="category"
                column="categoryCode"
                select="General.getCategoryByCategoryCode" />
    </resultMap>
<select id="getAllCountries" resultClass="Country">
        SELECT
        country_code as code, name, isd_code as isdCode
        FROM
        country_code
    </select>
<select id="getAllSubCategories" resultMap="SubCategoryResultMap">
        SELECT
        sub_category_code as subCategoryCode,
        sub_category_name as description,
        category_code as categoryCode
        FROM
        sub_category_code
    </select>
<select id="getCategoryByCategoryCode" parameterClass="string"
            resultMap="CategoryResultMap" >
        SELECT
        category as categoryCode,
        description
        FROM
        category_code
        WHERE
        category = #value#
    </select>

</sqlMap>
[/sourcecode]</pre>
<p>Above is the iBatis config for a SubCategory object that has a Category object as a parent. </p>
<pre>
[sourcecode language='java']
public class SubCategoryDaoIbatisImpl extends AbstractIbatisDao implements SubCategoryDao{

    public SubCategoryDaoIbatisImpl(DaoManager daoManager){
        super(daoManager);
    }

    @Override
    public List<SubCategory> getAllSubCategories() throws SQLException {
        return getSqlMapExecutor().queryForList("General.getAllSubCategories", null);
    }
}
[/sourcecode]
</pre>
<p>Above is the query made via <em>SqlMapExecutor</em>, but this doesn't work with MS Access. When I migrated the database to MySQL, it worked fine. So, iBatis is a NO too for Ms Access.</p>
<p>My last resort was Hibernate with Spring. Below is my code for the same object above.</p>
<pre>[sourcecode language="java"]
...

/**
* @author Taufek
*/
@Entity
@Table(name = "sub_category_code")
public class SubCategory extends AbstractEntity {

private Category category;
private String subCategoryCode;
private String description;

@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name = "category_code")
public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

@Column(name = "sub_category_name")
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Id
@Column(name = "sub_category_code")
public String getSubCategoryCode() {
return subCategoryCode;
}

public void setSubCategoryCode(String subCategoryCode) {
this.subCategoryCode = subCategoryCode;
}
...
}

[/sourcecode]</pre>
<p>Above is the SubCategory object.</p>
<pre>[sourcecode language="java"]
...
/**
* @author Taufek
*/
@Entity
@Table(name="category_code")
public class Category extends AbstractEntity{

private String categoryCode;
private String description;

@Id
@Column(name="category")
public String getCategoryCode() {
return categoryCode;
}

public void setCategoryCode(String code) {
this.categoryCode = code;
}

@Column(name="description")
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
...
}

[/sourcecode]</pre>
<p>Above is Category object which is the parent of SubCategory.</p>
<pre>[sourcecode language="java"]
public class SubCategoryDaoHibernateImpl extends AbstractHibernateDao implements SubCategoryDao{

    public List getAllSubCategories() throws SQLException {
        return getHibernateTemplate().loadAll(SubCategory.class);
    }

}
[/sourcecode]</pre>
<p>Above is the query. It is simpler with Hibernate. I only need to put the Hibernate annotations on each property in an entity to map it to its counterpart in the database. Then, by using <em>HibernateTemplate </em>from Spring, just use one of the methods provided to make a query.</p>
<p>I thought, I was done with choosing persistence method, but whenever there is an object which has more than 1 relationship, the query will return error. I found out that whenever there is a query with a relationship, hibernate will construct a query consists of LEFT OUTER JOIN to combine between 2 tables. I was surprised to find out that MS Access query can only has 1 LEFT OUTER JOIN. If you run a query with more than 1 LEFT OUTER JOIN, it will return an error.</p>
<p>So now,I'm back to square one with ol' JDBC.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Zero XML with Struts2]]></title>
<link>http://dhydrated.wordpress.com/?p=101</link>
<pubDate>Fri, 04 Jul 2008 08:51:52 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=101</guid>
<description><![CDATA[Most of JEE&#8217;s MVC frameworks nowadays, requires a bit of learning on their XML configurations.]]></description>
<content:encoded><![CDATA[<p>Most of JEE's MVC frameworks nowadays, requires a bit of learning on their XML configurations. Some might get frustrated when seeing those long list of XMLs in a project. But for me, XML configuration is easier to maintain and learn if you know where to look. Now, Struts2 has taken the next step, and their goal is zero configuration. There are not actually there yet, but they have done tremendous job on reducing XML configs. But if you are a fan of XML like me, you can still stick to XML configs.</p>
<p>Struts2 took advantage of Annotation to move those configurations from XML to <em>Action</em> class itself. The only XML you need to set is your ol' trusty web.xml. You need to set the heart of Struts2 component which is the <em>FilterDispatcher </em>like below.</p>
<p>[sourcecode language="xml"]</p>
<p><?xml version="1.0" encoding="UTF-8"?><br />
<web-app id="WebApp_9"<br />
         version="2.4"<br />
         xmlns="http://java.sun.com/xml/ns/j2ee"<br />
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"></p>
<p>    <display-name>Dhydrated's Fortune Teller Web</display-name></p>
<p>    <filter><br />
        <filter-name>struts2</filter-name><br />
        <filter-class><br />
            org.apache.struts2.dispatcher.FilterDispatcher<br />
        </filter-class><br />
        <!-- Scanning for annotation packages --><br />
        <init-param></p>
<param-name>actionPackages</param-name>
<param-value>org.dhydrated</param-value>
        </init-param><br />
    </filter></p>
<p>    <filter-mapping><br />
        <filter-name>struts2</filter-name><br />
        <url-pattern>/*</url-pattern><br />
    </filter-mapping></p>
<p>    <welcome-file-list><br />
        <welcome-file>index.jsp</welcome-file><br />
    </welcome-file-list></p>
<p></web-app></p>
<p>[/sourcecode]</p>
<p>There is nothing special about above settings but just note that within FilterDispatcher element, I'm declaring <em>actionPackages </em>with <em>org.dhydrated</em> value. Struts2 will scan through this java packages for <em>Action</em> classes.</p>
<p>Below is my first <em>Action</em> class called <em>Index.java</em>.</p>
<p>[sourcecode language="java"]</p>
<p>package org.dhydrated.sample;</p>
<p>import com.opensymphony.xwork2.ActionSupport;<br />
import org.apache.struts2.config.Result;</p>
<p>/**<br />
 * @author Dhydrated<br />
 */<br />
@Result( value="/pages/VisitorForm.jsp" )<br />
public class Index extends ActionSupport{  </p>
<p>}</p>
<p>[/sourcecode]</p>
<p>Above will be the first <em>Action</em> class to be hit when entering the application. From the index.jsp, I will just redirect by calling <em>response.sendRedirect("sample/index.action");</em>. <em>Index </em>action class will do nothing except redirecting to the <em>VisitorForm.jsp</em>. Below is my <em>VisitorForm.jsp </em>code.</p>
<p>[sourcecode language="xml"]</p>
<p><%@ page contentType="text/html; charset=UTF-8" %><br />
<%@ taglib prefix="s" uri="/struts-tags" %><br />
<html><br />
    <head><br />
        <title>Dhydrated's Fortune Teller</title><br />
    </head><br />
    <body></p>
<h4>Although I'm a fortune teller, please state your name</h4>
<p><s:form action="fortuneTeller"><br />
            <s:textfield name="name" label="Your name"/><br />
            <s:submit/><br />
        </s:form><br />
    </body><br />
</html></p>
<p>[/sourcecode]</p>
<p>Below is the page being rendered.</p>
<p><a href="http://dhydrated.wordpress.com/files/2008/07/struts2-inputform.jpg"><img class="alignnone size-full wp-image-108" src="http://dhydrated.wordpress.com/files/2008/07/struts2-inputform.jpg" alt="" width="413" height="225" /></a></p>
<p>On this page, I'm just trying to capture the user name and bind it to <em>name </em>property of <em>FortuneTellerAction</em> action class. When I submit this form, <em>FortuneTellerAction</em> action class will be executed. Below is my <em>FortuneTellerAction </em>action class.</p>
<p>[sourcecode language="java"]</p>
<p>package org.dhydrated.sample;</p>
<p>import org.apache.struts2.config.Result;</p>
<p>/**<br />
 * @author Dhydrated<br />
 */<br />
@Result(name="SUCCESS", value="/pages/FortuneTeller.jsp" )<br />
public class FortuneTellerAction {</p>
<p>    private String name;</p>
<p>    public String getName() {<br />
        return name;<br />
    }</p>
<p>    public void setName(String name) {<br />
        this.name = name;<br />
    }</p>
<p>    public String getFortune(){<br />
        return "Howdy, " + name + ". Today's is your lucky day.";<br />
    }</p>
<p>    public String execute() {<br />
        return "SUCCESS";<br />
    }<br />
}</p>
<p>[/sourcecode]</p>
<p>By now, above class already captured user's data into <em>name</em> property. <em>execute</em> method will be called and redirect user to <em>FortuneTeller.jsp</em> page. This is set at the above code as <em>@Result(name="SUCCESS", value="/pages/FortuneTeller.jsp" )</em>. <em>FortuneTeller.jsp</em> code is as below.</p>
<p>[sourcecode language="xml"]</p>
<p><%@ page contentType="text/html; charset=UTF-8" %><br />
<%@ taglib prefix="s" uri="/struts-tags" %><br />
<html><br />
    <head><br />
        <title>Dhydrated's Fortune Teller</title><br />
    </head><br />
    <body></p>
<h4><s:property value="fortune"/></h4>
<p></body><br />
</html></p>
<p>[/sourcecode]</p>
<p>Value <em>fortune</em> is referring to the <em>getFortune() </em>method from the <em>FortuneTellerAction </em>action class. The output of the page should be like below.</p>
<p><a href="http://dhydrated.wordpress.com/files/2008/07/struts2-outputform.jpg"><img class="alignnone size-full wp-image-109" src="http://dhydrated.wordpress.com/files/2008/07/struts2-outputform.jpg" alt="" width="450" height="170" /><br />
</a></p>
<p>There are 2 points you should notice here. First, there are 2 ways of naming your <em>Action</em> class when using annotation. The <em>Index </em>action class extends Struts2 <em>ActionSupport </em>class, but the <em>FortuneTellerAction</em> action class does not. So, either you extends from <em>ActionSupport</em> class or end your action class with <em>Action</em> suffix, Struts2 will recognizes it as an <em>Action</em> class.</p>
<p>Second, if you recall, we set <em>org.dhydrated</em> as the annotation packages. My <em>Index</em> action class is under <em>org.dhydrated.sample</em> package. The value after <em>org.dhydrated.</em> will be treated as the URL namespace. So, the URL to call my <em>Index </em>action class is <em>http://&#60;host&#62;:&#60;port&#62;/&#60;servlet-contextpath&#62;/sample/index.action</em>. And of course, there will be <em>.action</em> suffix for every <em>Action</em> class.</p>
<p>Annotation really helps to slam down the number of XML config files. But when the project grew bigger, it could get complicated when you need to browse through all the <em>Action</em> classes to understand your project flow. For me, XML is still the best way to put all your <em>Action</em> declarations and project flows. Usually, XML files is group within a same folder so that it is easy to find. Some IDEs have great visual editor that works with XML to simplify the process in building the configs.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Java - Dicas e Tutoriais]]></title>
<link>http://alyssontmv.wordpress.com/?p=71</link>
<pubDate>Mon, 30 Jun 2008 16:47:50 +0000</pubDate>
<dc:creator>alyssontmv</dc:creator>
<guid>http://alyssontmv.wordpress.com/?p=71</guid>
<description><![CDATA[Outro bom site de dicas Java SE, Java EE, Java ME é o
http://www.java-tips.org/
O site é em Inglê]]></description>
<content:encoded><![CDATA[<p>Outro bom site de dicas Java SE, Java EE, Java ME é o</p>
<p><a href="http://www.java-tips.org/" target="_self">http://www.java-tips.org/</a></p>
<p>O site é em Inglês.</p>
<p>Até a próxima!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Apply Facelets to Your Faces]]></title>
<link>http://dhydrated.wordpress.com/?p=75</link>
<pubDate>Mon, 30 Jun 2008 08:11:08 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=75</guid>
<description><![CDATA[After working with JSF for quite sometimes, what should I learn next? Naturally, it would be Facelet]]></description>
<content:encoded><![CDATA[<p>After working with JSF for quite sometimes, what should I learn next? Naturally, it would be <em>Facelets</em>. It is a templating language which is suitable for JSF. Although, <em>Facelets </em>was build with JSF in mind but it is said that, <em>Facelets </em>is flexible enough to be use with other UI language besides JSF.</p>
<p>So, what are needed for Facelets to work? Glad you asked. Below are the libraries needed for running JSF with Facelets. As you can see, MyFaces have made into my top choice. But don't fret about it, just swap MyFaces libraries with Sun-RI if you prefer the latter.</p>
<p>[sourcecode language="xml"]</p>
<project<br />
    xmlns = "http://maven.apache.org/POM/4.0.0"<br />
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"<br />
    xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><br />
    ...<br />
    <dependencies><br />
        <dependency><br />
            <groupId>javax.servlet</groupId><br />
            <artifactId>servlet-api</artifactId><br />
            <version>2.5</version><br />
            <scope>provided</scope><br />
        </dependency><br />
        <dependency><br />
            <groupId>javax.servlet</groupId><br />
            <artifactId>jstl</artifactId><br />
            <version>1.2</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>com.sun.facelets</groupId><br />
            <artifactId>jsf-facelets</artifactId><br />
            <version>1.1.13</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>myfaces</groupId><br />
            <artifactId>myfaces-api</artifactId><br />
            <version>1.2.3</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>myfaces</groupId><br />
            <artifactId>myfaces-impl</artifactId><br />
            <version>1.2.3</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>commons-logging</groupId><br />
            <artifactId>commons-logging</artifactId><br />
            <version>1.1.1</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>commons-beanutils</groupId><br />
            <artifactId>commons-beanutils</artifactId><br />
            <version>1.6</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>commons-codec</groupId><br />
            <artifactId>commons-codec</artifactId><br />
            <version>1.2</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>commons-digester</groupId><br />
            <artifactId>commons-digester</artifactId><br />
            <version>1.8</version><br />
        </dependency><br />
        <dependency><br />
            <groupId>commons-el</groupId><br />
            <artifactId>commons-el</artifactId><br />
            <version>1.0</version><br />
        </dependency><br />
    </dependencies></p>
</project>
[/sourcecode]</p>
<p>Then, I need to amend the web deployment descriptor to include the JSF servlet. Facelets has a standard file suffix which is 'xhtml'. Hence, context-param named <em>javax.faces.DEFAULT_SUFFIX </em>and JSF Servlet's <em>URL  Pattern</em> are set to <em>.xhtml</em>.</p>
<p>[sourcecode language="xml"]<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<web-app version="2.5"<br />
         xmlns="http://java.sun.com/xml/ns/javaee"<br />
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"></p>
<p>    <context-param></p>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
    </context-param><br />
    <context-param></p>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
    </context-param><br />
    <context-param></p>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
    </context-param><br />
    <context-param></p>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
    </context-param><br />
    <context-param></p>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
    </context-param></p>
<p>    <servlet><br />
        <servlet-name>Faces Servlet</servlet-name><br />
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class><br />
        <load-on-startup>1</load-on-startup><br />
    </servlet><br />
    <servlet-mapping><br />
        <servlet-name>Faces Servlet</servlet-name><br />
        <url-pattern>*.xhtml</url-pattern><br />
    </servlet-mapping><br />
    <welcome-file-list><br />
        <welcome-file>index.xhtml</welcome-file><br />
    </welcome-file-list><br />
</web-app><br />
[/sourcecode]</p>
<p>Next stop is the faces-config.xml file. Minimally, what I need to add is just the Facelets' view handler as below.</p>
<p>[sourcecode language="xml"]<br />
<faces-config version="1.2"<br />
              xmlns="http://java.sun.com/xml/ns/javaee"<br />
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"><br />
    <application><br />
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler><br />
    </application><br />
</faces-config><br />
[/sourcecode]</p>
<p>After configuring the XMLs, then I can start working on the UI. Ideally, we will start by creating a template for all our pages. Facelets has a strict requirement which the page must be a fully XHTML-compliant. Working with IDE sure helps a lot in weeding out those pesky errors. Below is a simple template named <em>template.xhtml</em>.</p>
<p>[sourcecode language="xml"]<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD<br />
XHTML 1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"<br />
      xmlns:ui="http://java.sun.com/jsf/facelets"<br />
      xmlns:f="http://java.sun.com/jsf/core"<br />
      xmlns:h="http://java.sun.com/jsf/html"><br />
    <head><br />
        <title>Dhydrated's Well</title><br />
    </head><br />
    <body><br />
        <h:form><br />
                <ui:insert name="body-content"><br />
                    Body to be replaced.<br />
                </ui:insert><br />
        </h:form><br />
    </body><br />
</html><br />
[/sourcecode]</p>
<p>As you could have guessed, <em>Facelets </em>tag has <em>ui</em> prefix. Above, I've created a hook on the template named <em>body-content </em>by using the <em>ui:insert </em>tag, which could be replaced by my JSF view. Now, lets create a JSF view that uses above template.</p>
<p>[sourcecode language="xml"]<br />
<!DOCTYPE html<br />
PUBLIC "-//W3C//DTD XHTML1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"<br />
      xmlns:ui="http://java.sun.com/jsf/facelets"<br />
      xmlns:h="http://java.sun.com/jsf/html"><br />
    <body><br />
        <ui:composition template="template.xhtml"></p>
<p>            <ui:define name="body-content"><br />
                <t:outputText value="Value from JSF View" /><br />
            </ui:define><br />
        </ui:composition><br />
    </body><br />
</html><br />
[/sourcecode]</p>
<p>Above JSF view, uses <em>ui:composition</em> tag to state which template it referring to. Then, it uses <em>ui:define</em> to position it content in the template by matching it's name with template's <em>ui:insert</em> tag's name. So when you run this view on the browser, <em>Facelets </em>will help to decorate the page based on the choosen template.</p>
<p>What I had shown above is just one of the benefits from Facelets. There are other great goodies from Facelets which are component composition (which is my favourite), customizable tag libs,  extendable components and etc. It also helps to nicely interweave JSTL and JSP expression language (EL) together. Although, there are others templating utilities such as Tiles, FreeMarker, Velocity and SiteMesh, Facelets does has a good edge when applied with JSF.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Java - Tutoriais e Referencias da SUN]]></title>
<link>http://alyssontmv.wordpress.com/?p=64</link>
<pubDate>Wed, 25 Jun 2008 20:11:29 +0000</pubDate>
<dc:creator>alyssontmv</dc:creator>
<guid>http://alyssontmv.wordpress.com/?p=64</guid>
<description><![CDATA[Seguem links de tutoriais e referencias da linguagem Java (by Sun):
Varios documentos de referencia ]]></description>
<content:encoded><![CDATA[<p>Seguem links de tutoriais e referencias da linguagem Java (by Sun):</p>
<p>Varios documentos de referencia da linguagem Java:</p>
<p><a href="http://java.sun.com/javase/reference/index.jsp" target="_blank">http://java.sun.com/javase/reference/index.jsp</a></p>
<p>Varios tutoriais JavaSE e JavaEE: <a href="http://java.sun.com/javase/reference/tutorials.jsp" target="_blank">http://java.sun.com/javase/reference/tutorials.jsp</a></p>
<p>Ate a proxima!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Kickstart Your Project with Maven 2]]></title>
<link>http://dhydrated.wordpress.com/?p=49</link>
<pubDate>Tue, 24 Jun 2008 05:09:50 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=49</guid>
<description><![CDATA[Starting a new project is time consuming. You need to determine the technologies involved, build the]]></description>
<content:encoded><![CDATA[<p>Starting a new project is time consuming. You need to determine the technologies involved, build the project structure, setup the configuration files, work out the dependencies of jar files and etc. Before I had encountered Maven, I just used to copy my existing project, and start working from there. I need to add/delete, Java, jar and other resources files prior to starting a new project. With Maven came into the picture, I need not to worry about most of the tasks I just mentioned.</p>
<p>There are several ways you could start you project with Maven. But I choose to use the <em>generate </em>goal from <em>archetype </em>plug-in because it seems to be the easiest way to start a new project. <em>Archetype </em>is like a project template, where Maven has a set of predefined project templates we could choose from. If we do not specify a specific <em>archetype</em>, it would goes into an interactive mode, which is awesome. I would hate it if I need to remember those <em>archetype </em>names. Below picture, is how I run the <em>generate </em>task command.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-generate.jpg"><img class="alignnone size-full wp-image-51" src="http://dhydrated.wordpress.com/files/2008/06/mvn-generate.jpg" alt="" width="355" height="29" /></a></p>
<p>When you hit the [Enter] key, you would get the archetype list as below picture.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-list.jpg"><img class="alignnone size-full wp-image-52" src="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-list.jpg" alt="" width="510" height="766" /></a></p>
<p>From the picture above you could see, there are 44 <em>archetype</em>s you could choose from. For a simple webapp, I should choose number 18, which represents maven-archetype-webapp <em>archetype</em>. Key in number 18 and hit [Enter] key.</p>
<p>Then, you will be asked to enter your project details as below.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-details.jpg"><img class="alignnone size-full wp-image-53" src="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-details.jpg" alt="" width="399" height="53" /></a></p>
<p>Console will ask you to confirm the given details as below.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-confirm.jpg"><img class="alignnone size-full wp-image-54" src="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-confirm.jpg" alt="" width="275" height="74" /></a></p>
<p>Finally, Maven will start working in the background and produce below output in the console.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-console.jpg"><img class="alignnone size-full wp-image-55" src="http://dhydrated.wordpress.com/files/2008/06/mvn-generate-proj-console.jpg" alt="" width="509" height="211" /></a></p>
<p>If you are running for the first time, it will check all dependencies and download it if necessary. Downloaded dependencies are stored in your local repository. By default, if you are installing Maven in Windows XP, it will be at <em>C:\Documents and Settings\&#60;user&#62;\.m</em> path.</p>
<p>Now, Maven had created below project structure.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/mvn-proj-structure.jpg"><img class="alignnone size-full wp-image-57" src="http://dhydrated.wordpress.com/files/2008/06/mvn-proj-structure.jpg" alt="" width="215" height="164" /><br />
</a></p>
<p>From here, you need to add more details to your pom.xml file to add more dependencies details in order for Maven to download the necessary jar files. By default, the pom.xml will be configured with JUnit the testing component.</p>
<p>Maven is a good utility to speed up and facilitate the building process of your application. It adopts standard approach so all projects has similar architecture. New developer, who just comes in to join a project, could easily get a good understanding of an application. Developer will requires less time on wading through specific configurations and project structure.</p>
<p>For those who are fan of Eclipse or NetBean IDE, there is a good news for you. Maven have plug-ins which enables it to be integrated with these IDE. Working with Maven through IDE, is much simpler than above mentioned process. :)</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Simplified Ajax with DWR 2.0]]></title>
<link>http://dhydrated.wordpress.com/?p=43</link>
<pubDate>Thu, 19 Jun 2008 09:11:15 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=43</guid>
<description><![CDATA[Being a conservative JSF developer, I&#8217;ve been resorting to Ajax4JSF (A4J) for my ajaxified app]]></description>
<content:encoded><![CDATA[<p>Being a conservative JSF developer, I've been resorting to Ajax4JSF (A4J) for my <em>ajaxified </em>applications. All I need to do is just jack-in A4J into my application and extend from my existing JSF tags. So easy, I don't need to know the underlying implementation of Ajax. But I've been thinking, what if one day, I have to develop or maintain an application without JSF? A4J will not be there anymore to help me out. So, I decided to look for a new utility which could facilitates in making an Ajax call. There are myriads of Ajax helper libraries, but one that does caught my attention is DWR. Current stable version is 2.0 but version 3.0 is under heavy development. So, we could expect the latter version anytime soon.</p>
<p>Why I like it so much? - because it makes Ajax implementation simple for Java developer. It actually generates the Javascript objects for client side, which kind of mimicking the Java objects on the server side.</p>
<p>Here is a simple example of DWR. Below is my Java object, which is a normal POJO with a method getting a User object.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/dwr-java-method.jpg"><img class="alignnone size-full wp-image-44" src="http://dhydrated.wordpress.com/files/2008/06/dwr-java-method.jpg" alt="DWR Java Method" width="296" height="156" /></a></p>
<p>Next, I just need to declare my POJO in <em>dwr.xml</em> file.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/dwr-xml.jpg"><img class="alignnone size-full wp-image-45" src="http://dhydrated.wordpress.com/files/2008/06/dwr-xml.jpg" alt="dwr.xml file" width="510" height="120" /><br />
</a>The <em>convert </em>tag, is where I declare my User bean class, so DWR will able to marshall and unmarshall the bean between client and server side. The <em>create </em>tag, is where I declare my POJO, which will be mapped to the generated DWR's Javascript object.<a href="http://dhydrated.wordpress.com/files/2008/06/dwr-xml.jpg"></a></p>
<p>Now server side configurations are out of my way. Lets go to the client side. In my page, I need to includes below scripts.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/dwr-js-import.jpg"><img class="alignnone size-full wp-image-46" src="http://dhydrated.wordpress.com/files/2008/06/dwr-js-import.jpg" alt="DWR Javascript Import" width="510" height="120" /><br />
</a>First script tag, imports the common DWR engine script which is a mandatory script to be imported. Second script tag, imports DWR utility script. Utility is optional but it provides lots of handy functions. Third script tag, is the generated script which contains the Javascript object that maps to my <em>UserService </em>POJO.<a href="http://dhydrated.wordpress.com/files/2008/06/dwr-js-import.jpg"><br />
</a></p>
<p>Now, I can just call the method from Javascript like below and let DWR do all the dirty work.</p>
<p><a href="http://dhydrated.wordpress.com/files/2008/06/dwr-js-function.jpg"><img class="alignnone size-full wp-image-47" src="http://dhydrated.wordpress.com/files/2008/06/dwr-js-function.jpg" alt="DWR Javascript Functions" width="510" height="137" /><br />
</a>From the first function, you can see that I'm using the generated UserService object to make the Ajax call via getUser method. The way we call the method from a Javascript is a bit different compared to calling it from a Java class. Although, my method only accepts 1 argument in Java, but here, I have to put a callback function as the 2nd parameter which acts as the handler for the return object. DWR will handles all the heavy lifting on marshalling the request to the server and unmarshalling the response back to the Javascript object. The good thing is, not only you could pass and receive all the primitive and wrapper classes, but DWR also works on your POJO. As in this example, I'm expecting a <em>User </em>POJO as the return object. You don't need to work on any XML or JSON format in marshalling and unmarshalling your data.</p>
<p>Although, comparing to A4J, there are more work to do here, especially on the client side, but it does give you more flexibility and control over your Ajax call. More control means you are able to fine tune your Ajax calls for performance optimization. Plus, DWR requires no specific framework. Hence, learning DWR, is beneficial because you could implement it regardless of your application architecture. It is also possible to patch DWR into your existing applications. DWR definitely will be in my list for my future projects.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Generate iBatis' Goodies ]]></title>
<link>http://dhydrated.wordpress.com/?p=36</link>
<pubDate>Mon, 16 Jun 2008 08:25:04 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=36</guid>
<description><![CDATA[Currently, I&#8217;m learning on how to incorporate iBatis into my application&#8217;s persistence l]]></description>
<content:encoded><![CDATA[<p>Currently, I'm learning on how to incorporate <em>iBatis </em>into my application's persistence layer. <em>iBatis </em>relies heavily on its xml files, which are used to map the SQLs to Java objects. If your project, contains a large number of tables, this could be a problem. You have to hand-code all the Java objects and SQLs manually.  Being a self proclaimed Gung-Ho of open source technologies, I believe there must be something out there that could ease this burden. Well, there is!</p>
<p>There is a tool which was known as <em>Abator</em>, and was renamed to <em>iBator</em>. Wondering why changed the name? It was stated at the iBator web site, it was due to trade registration dispute. Well, changed name doesn't affect the functionality at all. Functionally, iBator helps to generate the SQL Map Xmls and Java files based on the existing tables. Not only that, it could also generates DAO layer for you. It could tailor your DAO layer according to the Spring DAO standards. All you need to do after this, is tweak a bit on the generated xml files and connect your service layer to the DAO layer. How's that for a speed in your project.</p>
<p>Basically, you will need one jar file, <em>iBator </em>jar. It doesn't has any dependencies. But in my case, I would need ant jar file, since I'm using ant to execute the generator.</p>
<p>First, I would need the <em>abatorConfig.xml</em> file. Below is how I set the database connection settings:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ibator-config-1.jpg"><img class="alignnone size-full wp-image-37" src="http://dhydrated.wordpress.com/files/2008/06/ibator-config-1.jpg" alt="" width="836" height="141" /></a></p>
<p>Then, there are 3 items I'm setting below. First element, is the Java objects' settings. Second element, is the SQLs xml files' settings. And the third element, is the DAOs settings. Here you have to specify the target locations and the package/folder names for the generated files.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ibator-config-2.jpg"><img class="alignnone size-full wp-image-38" src="http://dhydrated.wordpress.com/files/2008/06/ibator-config-2.jpg" alt="Generated Files Configs" width="716" height="185" /></a></p>
<p>Third,  is my tables settings. Here I mapped the tables to my Java objects:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ibator-config-3.jpg"><img class="alignnone size-full wp-image-39" src="http://dhydrated.wordpress.com/files/2008/06/ibator-config-3.jpg" alt="Tables Configs" width="577" height="263" /></a></p>
<p>Lastly, I just need to execute below ant file:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ibator-build.jpg"><img class="alignnone size-full wp-image-40" src="http://dhydrated.wordpress.com/files/2008/06/ibator-build.jpg" alt="iBator Ant Build" width="510" height="498" /></a></p>
<p>That's it. After running above ant build, you would have the almost complete DAO layer for your application. Some extra work might be needed such as configuring your tables relationship, setting your SQLMapConfig, and connecting your DAO layer to your service layer.</p>
<p>As with any other generator utility, it won't gives you the perfect generated files. Some level of tweaking is expected from you. But to kick start a project with lots of tables, for sure you could appreciate the benefits of this utility.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Checking Out iBatis]]></title>
<link>http://dhydrated.wordpress.com/?p=28</link>
<pubDate>Wed, 11 Jun 2008 06:29:28 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=28</guid>
<description><![CDATA[I&#8217;ve been to couple of Java technical interviews that asked about iBatis. Frustrated with my l]]></description>
<content:encoded><![CDATA[<p>I've been to couple of Java technical interviews that asked about <em>iBatis</em>. Frustrated with my lack of knowledge on the matter, I just had to tell the interviewer that I'd never work on the framework before. <em>iBatis </em>must be popular enough and worth the time for me to check it out. So, after working with the starter guide, here's what I've learned.</p>
<p>Unlike other ORM (Object-Relational Mapping) frameworks such as Hibernate, which reduces dramatically number of SQLs for the developer, <em>iBatis </em>works closely with SQL. It SQL-like syntax gives you more control over your relationships between your relational database and your POJO. It's also lightweight and requires minimal effort to jack it up into your application. Basically, it only requires one jar file (since it came bundled with its dependencies) and 2 XML configuration files, to be located in your application classpath.</p>
<p>First off, the <em>SqlMapConfig.xml</em> file.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/sqlmapconfigxml.jpg"><img class="alignnone size-full wp-image-29" src="http://dhydrated.wordpress.com/files/2008/06/sqlmapconfigxml.jpg" alt="SqlMapConfig.xml" width="501" height="488" /></a></p>
<p>As you can see, this is where the general configurations of IBatis are located.</p>
<p>Second, the <em>SqlMap.xml</em> file, where you put your sql mappings.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/sqlmapxml.jpg"><img class="alignnone size-full wp-image-30" src="http://dhydrated.wordpress.com/files/2008/06/sqlmapxml.jpg" alt="SqlMap.xml" width="478" height="187" /></a></p>
<p>Here, I've created a select mapping and as you can see, it uses native SQL. So, if you're an avid users of SQL, this would not be a problem to interpret.</p>
<p>Lastly, I've create a test class, to make a test call on above select mapping.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/querytestjava.jpg"><img class="alignnone size-full wp-image-31" src="http://dhydrated.wordpress.com/files/2008/06/querytestjava.jpg" alt="QueryTest.java" width="510" height="678" /></a></p>
<p>In the <em>init </em>method, it loads the configuration file called <em>SqlMapConfig.xml</em> and in the <em>getPersonQuery </em>test method, is where the magic happens. The <em>queryForObject </em>method uses <em>getPerson </em>select mapping, which I've declared in <em>SqlMap.xml</em> file and it should returns a Person object.</p>
<p>That's it and now my application persistence layer is under <em>iBatis</em>. If I run the test class, It should print out the person instance that I've queried on my console:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/queryoutput.jpg"><img class="alignnone size-full wp-image-32" src="http://dhydrated.wordpress.com/files/2008/06/queryoutput.jpg" alt="Query Output" width="649" height="128" /></a></p>
<p>So <em>iBatis </em>is great and all but the question is, when do you choose <em>iBatis </em>over other ORMs? If you, as a developer, have full control over your domain objects design, ORM might me the best choice for you. But, if you are working on an existing database structure or there is a possibility that your database layer might me under different team responsibility, then <em>iBatis </em>will be a good choice. Hmm... maybe I'll stuff <em>iBatis </em>into my new upcoming project just for the fun of it.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Test Driving Swing Applications]]></title>
<link>http://softstuff.wordpress.com/?p=53</link>
<pubDate>Tue, 10 Jun 2008 17:53:10 +0000</pubDate>
<dc:creator>vkomulai</dc:creator>
<guid>http://softstuff.wordpress.com/?p=53</guid>
<description><![CDATA[I&#8217;ve done my fare share of developing Swing apps in my java years. Perhaps 40% of UI developme]]></description>
<content:encoded><![CDATA[<p>I've done my fare share of developing Swing apps in my java years. Perhaps 40% of UI development in my 8 years of java experience is done in Swing. Now that's a quite a big percentage these days, when most of my colleagues have never done any Swing and their UI development is mostly done to web. Since the industry is concentrated to the web, naturally most of the tools (for example testing) are concentrated to web as well.</p>
<p>I believe that integration tests are perhaps the most valuable tests that are written (Acceptance tests excluded, but you create acceptance tests using these tools), so I share my experiences from two very different open source testing tools for Swing. One is called the <a href="http://fest.easytesting.org/swing/">FEST-Swing</a>, and the other is <a href="http://www.marathontesting.com/">Marathon</a>.</p>
<p><strong>FEST-Swing</strong></p>
<p>FEST-Swing is a Java API for, which is based on looking up components and making assertions on them. The API is a <a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html">DSL</a>ish 'fluent API', which makes writing the tests somewhat pleasant. It can be used with either JUnit or TestNG so  it doesn't lock you in one unit testing framework, and the best part of the project is that it is active (last update was on May 19 2008). For example, I used FEST-Swing for testing my SCJD assignment, and it proved to be a good tool for the purpose - no problems in writing the tests, and it was quite easy to test all the scenarios. I'm not sure how it responds to more complicated UI's, but I'm ready to give it a try in other projects as well. Very promising indeed.</p>
<p><strong>Marathon</strong></p>
<p>The project was initially started by the <a href="http://www.thoughtworks.com/">ThoughtWorks</a> developers, so I thought there might by something to it and I decided to give it a try. The framework is based on capturing user interactions and recording them as Python scripts. Of course you can edit these recorded scripts later on using any text editor, because the scripts are valid Python, not some <span class="p" style="color:#cc0000;"> </span><span class="p">proprietary</span> format.  I tried this on one quite complicated (lot's of user interface logic and decision making) project and I ran into problems. The scripts recorded by the recorder all required some manual editing before I could re-run them from the Python file.</p>
<p><strong>Frankenstein</strong></p>
<p><a href="http://blog.sidu.in/">Sidu Ponnappa</a> sent a comment to my "about"-page concerning another open source framework, the Frankenstein. It is hosted at openqa.com, the same site  that hosts Selenium. Like Marathon, this is also started in the ThoughtWroks labs. After a quick try Frankenstein is a clearly on a very early stage of it's development. For example, the documentation is extremely lightweight, with practically no examples.</p>
<p>The framework allows you to record your UI actions, which are then saved to Ruby scripts. After a few try and errors I managed to record some actions and run the saved Ruby scripts after minor changes to the scripts. What I liked about this one was the simplicity of the recorder, and the possibilities that the Ruby driver brings to testing the UI's..</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Kenalan sama Spring]]></title>
<link>http://henings.wordpress.com/?p=204</link>
<pubDate>Tue, 10 Jun 2008 05:01:05 +0000</pubDate>
<dc:creator>heningsept</dc:creator>
<guid>http://henings.wordpress.com/?p=204</guid>
<description><![CDATA[Spring adalah salah satu application framework untuk aplikasi berbasis Java, tepatnya J2EE. Apakah a]]></description>
<content:encoded><![CDATA[<p>Spring adalah salah satu application framework untuk aplikasi berbasis Java, tepatnya J2EE. Apakah application framework itu? Setelah disarikan dari berbagai macam sumber bacaan, gw simpulkan application framework itu adalah sekumpulan aturan atau standar yang disertai dengan library, yang digunakan untuk mempermudah, mempercepat atau membuat pengembangan aplikasi secara rapi sehingga bisa dikembangkan lagi dengan mudah di kemudian hari. Sedangkan J2EE --sekarang disebut Java EE-- oleh situs Sun Microsystem dijelaskan sebagai</p>
<p>"<em>Java Platform, Enterprise Edition (Java EE) builds on the solid foundation of Java Platform, Standard Edition (Java SE) and is the industry standard for implementing enterprise-class service-oriented architecture (SOA) and next-generation web applications</em>".</p>
<p>Sederhananya, ini adalah edisi Java yang dipakai untuk mengembangkan aplikasi berskala besar atau enterprise. Edisi lainnya, Java SE (Standard Edition) adalah Java yang selama ini gw pakai untuk mengembangkan aplikasi desktop kecil2an). Dan satunya lagi, Java ME (Micro Edition) sesuai namanya, untuk mengembangkan aplikasi untuk perangkat kecil seperti PDA, handphone, dll. Jadi alih2 menggunakan Java SE yang selama ini gw pakai, sekarang gw akan mulai belajar dan menggunakan Java EE. Pak Endy Muhardin berbaik hati memberikan tips bagaimana mulai belajar Java EE di <a href="http://endy.artivisi.com/blog/java/road-to-java-ee/#more-331">sini</a>.</p>
<p>Sekarang balik lagi ke Spring. Ketika bicara tentang Spring, maka akan sering sekali terdengar istilah Inversion of Control (IoC) dan Dependency Injection. Gw sebagai pendatang baru dalam dunia Spring ini tentu saja bingung dengan kedua istilah itu. Untunglah ada forum berbahasa Indonesia yang membahas mengenai hal2 tersebut. Ada juga contoh yang bagus dari <a href="http://www.devx.com/Java/Article/21665">http://www.devx.com/Java/Article/21665.</a> Jadi mari lihat contoh berikut ini.</p>
<p>Misalnya gw mo buat suatu class yang bertugas memproses data, dalam arti membaca data dari suatu file dan memberikan data dari file tersebut pada class yang memanggilnya. Namanya class DataProcessor.</p>
<p><span style="color:#800080;">class DataProcessor<br />
{<br />
public Result processData()<br />
{<br />
FileDataReader dataReader = new FileDataReader("/data/file1.data");<br />
Data data = dataReader.readData();    //membaca data<br />
return data.calculateResult();    //mengembalikan data pada class yang memanggilnya<br />
}<br />
}</span></p>
<p>Ini dia potongan class yang memanggil si DataProcessor (disebut client code).</p>
<p><span style="color:#800080;">//client code:<br />
DataProcessor fileDataProcessor = new DataProcessor();    //membuat objek DataProcessor<br />
Result result = fileDataProcessor.processData();        //meminta data dari hasil pembacaan file</span></p>
<p>Di sini terlihat DataProcessor bergantung atau dependent pada FileDataReader. Kalau mau membaca data dari sumber lain, misalnya database, class DataProcessor harus direfactor, biar bisa menerapkan pembacaan data yang lebih general. Salah satu caranya dengan menggunakan interface.</p>
<p><span style="color:#800080;">interface DataReader {<br />
public Data readData(); }</span></p>
<p><span style="color:#800080;">class DataProcessor<br />
{<br />
private DataReader dataReader;</span></p>
<p><span style="color:#800080;"> public DataProcessor(DataReader reader) {<br />
this.dataReader = reader;  }</span></p>
<p><span style="color:#800080;"> public Result processData() {<br />
Data data = dataReader.readData();<br />
return data.calculateResult();   }<br />
}</span></p>
<p><span style="color:#800080;">//client code:<br />
FileDataReader dataReader = new FileDataReader("/data/file1.data");<br />
DataProcessor fileDataProcessor = new DataProcessor(dataReader);<br />
Result result = fileDataProcessor.processData();</span></p>
<p>DataProcessor tidak lagi beroperasi pada objek FileDataReader, melainkan pada interface DataReader yang diimplementasikan oleh FileDataReader sehingga lebih generic dan reusable. Masalahnya, setiap client code yang mau memproses data harus membuat objek data reader sendiri dan me-link objeknya dengan DataProcessor. Daripada begitu, kita bisa menginjeksikan kebergantungan (inject the dependency) antara DataReader dengan DataProcessor dengan factory class. Factory ini istilah yang baru gw kenal juga. Jadi ditambahankanlah class DataProcessorFactory ini dan client code-nya menggunakan jasa si factory untuk membuatkan reference ke DataProcessor.</p>
<p><span style="color:#800080;">class DataProcessorFactory<br />
{<br />
public static DataProcessor getFileDataProcessor()<br />
{<br />
DataReader reader = new FileDataReader("/data/file1.data");;<br />
DataProcessor dataProcessor = new DataProcessor(reader);<br />
return dataProcessor;<br />
}<br />
}</span></p>
<p><span style="color:#800080;">//client code:<br />
DataProcessor fileDataProcessor = DataProcessorFactory.getFileDataProcessor();<br />
Result result = fileDataProcessor.processData();</span></p>
<p>Si factory-lah yang membuatkan objek dari DataProcessor untuk client. Client tinggal meminta objek dan data hasil baca file melalui factory. Dengan ini telah terjadi apa yang namanya Inversion of Control dengan cara Dependency Injection (DI). Bentuk IoC yang lain adalah Dependency Pull, tapi gw belum ngerti itu.</p>
<p>Semakin besar aplikasi yang dibuat, semakin banyak factory class yang diperlukan. Ini gak menguntungkan karena kebanyakan factory itu merupakan singleton sederhana, yang tugasnya membuat dan menghubungkan objek2, nggak bisa di-inherit sehingga banyak duplikasi. Kelebihan DI dengan Spring, menurut DevX.com adalah<br />
"<em>... its ability to act as a factory to create objects. Spring reads a schematic defined in an external configuration file, creates and wires the objects together using reflection, and then passes the objects back to you. Think of Spring as a factory that you don't have to write any code for.</em>"</p>
<p>Intinya, Spring membuatkan dan menghubungkan objek2 melalui skema yang didefiniskan di configuration file eksternal, dalam hal ini file XML (gw gak tau hanya bisa XML file apa bisa yang lain). Langsung aja ke contoh kodenya. Client code akan menjadi seperti ini.</p>
<p><span style="color:#800080;">//client code:<br />
InputStream is = new FileInputStream("src/examples/spring/beans.xml");<br />
BeanFactory factory = new XmlBeanFactory(is);</span></p>
<p><span style="color:#800080;">DataProcessor dataProcessor = (DataProcessor) factory.getBean("fileDataProcessor");<br />
Result result = dataProcessor.processData();</span></p>
<p>dan file XMLnya seperti ini.</p>
<p><span style="color:#008000;">&#60;?xml version="1.0" encoding="UTF-8"?&#62;<br />
&#60;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&#62;</span></p>
<p><span style="color:#008000;">&#60;beans&#62;<br />
&#60;bean name="fileDataProcessor"<br />
class="examples.spring.DataProcessor"<br />
singleton="true"&#62;<br />
&#60;constructor-arg&#62;<br />
&#60;ref bean="fileDataReader"/&#62;<br />
&#60;/constructor-arg&#62;<br />
&#60;/bean&#62;<br />
&#60;bean name="fileDataReader"<br />
class="examples.spring.FileDataReader"<br />
singleton="true"&#62;<br />
&#60;constructor-arg&#62;<br />
&#60;value&#62;/data/file1.data&#60;/value&#62;<br />
&#60;/constructor-arg&#62;<br />
&#60;/bean&#62;<br />
&#60;/beans&#62;</span></p>
<p>Selalu dibungkus dengan tag &#60;beans&#62;&#60;/beans&#62;, di dalamnya bisa ada banyak tag &#60;bean&#62;, yang merepresentasikan objek di code Java yang kita buat. Contohnya pada code XML di atas, bean name yang pertama adalah "fileDataProcessor", ini adalah identifier untuk objek bertipe DataProcessor (class="examples.spring.DataProcessor"). Singleton = true artinya gw rasa mirip2 static di Java, jadi setiap kali ada request dari client, Spring akan selalu memberikan instance yang sama. Kalau singleton diset false, Spring akan membuat bean (instance kali ya maksudnya) yang berbeda untuk setiap request. Dalam tag &#60;constructor-arg&#62;, &#60;ref bean="fileDataReader"/&#62; berarti passing objek dengan id "fileDataReader" untuk constructornya. Dari tag bean yang kedua bisa kita lihat bahwa "fileDatReader" ini nama instance dari class FileDataReader. Bean yang kedua ini mempassing nilai ke constructornya (lihat &#60;value&#62;/data/file1.data&#60;/value&#62;).</p>
<p>Sampai saat ini itulah yang gw pahami. Masih belum mengerti hal2 lain seperti AOP, DAO, dan ORM. Kesimpulan tentang Spring, katanya sih framework yang satu ini sangat mantep sekali. Ini garis besarnya</p>
<ul>
<li> Spring bertujuan untuk meminimalkan dependency antar komponen aplikasi dan menyediakan plug-in architecture. Mungkin inilah yang mendukung terjadinya dynamic workflow seperti yang dijelaskan supervisor KP gw kemaren. Jadi kita bisa pasang komponen aplikasi saat runtime tanpa perlu bongkar kode Java-nya.</li>
<li>Object linking di Spring didefinisikan di file XML, jadi kita bisa memasang komponen atau konfigurasi yang berbeda saat runtime.</li>
<li>Berbeda dengan factory yang invasive, di mana client sangat tergantung pada factory karena meminta objek ke sana, Spring menyediakan reference objek ke client yang membutuhkan. Spring secara aktif merangkai dependency dari objek yang gak kenal satu sama lain menjadi aplikasi yang utuh.</li>
<li>Kemampuannya ini berguna banget buat Test-Driven-Development di Xtreme Programming (gw gak terlalu ngerti ini). Tapi mungkin artinya adalah bisa memudahkan untuk testing sana sini. Karena kode2 gak saling kenal, tp kalo mau disatuin juga gampang. Client gak perlu membuat objek baru (gak pernah membuat reference dengan keyword new), gak perlu lookup ke factory, Spring yang menyediakan dependency-nya secara runtime--dengan real maupun mock object.</li>
<li>Unit testing jadi mudah dilakukan karena gak ada dependecy yang hard-code, class2 yang ada saling gak kenal satu sama lain.</li>
</ul>
<p>sumber2 bacaan:<br />
<a href="http://dotnet.netindonesia.net/?0::21357">http://dotnet.netindonesia.net/?0::21357</a><br />
<a href="http://www.devx.com/Java/Article/21665">http://www.devx.com/Java/Article/21665</a><br />
<a href="http://arfan86.blogspot.com/2007/02/chating-tentang-spring-framework.html">http://arfan86.blogspot.com/2007/02/chating-tentang-spring-framework.html</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Don't Create But Generate (Your XML Schema)]]></title>
<link>http://dhydrated.wordpress.com/?p=21</link>
<pubDate>Fri, 06 Jun 2008 06:57:15 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=21</guid>
<description><![CDATA[If, you are using DTD (Document Definition Type) to describe your XML data, then you are still livin]]></description>
<content:encoded><![CDATA[<p>If, you are using DTD (Document Definition Type) to describe your XML data, then you are still living in the stone age (, unless you're maintaining existing legacy system and too afraid or lazy to change them, then that is understandable :p ).  Instead, use an XML Schema Language which is widely adopted nowadays. There are lots of XML Schema Languages, but 2 most prominent families would be W3C and RELAX NG XML Schemas. I'm kinda guy who just like to stick with the bigger herd. Being a follower instead of an early-adopter, I just chose W3C XML Schema.</p>
<p>Composing XML Schema Descriptor (XSD) is not all dandy. But I've came across a utility that can give you a good kick start. It's an open source utility from my neighboring country, Thailand, and it's called <a title="Trang" href="http://www.thaiopensource.com/relaxng/trang.html"><em>Trang</em></a>, which is named after a place in Thailand. You just need to download the <a title="trang.jar" href="http://www.thaiopensource.com/download/trang-20030619.zip">jar</a> file.</p>
<p>Let's get started. Usually, when you're building a web service, you would need to compose your WSDL file, which in turn, contains the request and response XML schema. Let say, below is my request and response examples:</p>
<p><a href="http://dhydrated.wordpress.com/files/2008/06/dhydratedrequest.jpg"><img class="alignnone size-full wp-image-22" src="http://dhydrated.wordpress.com/files/2008/06/dhydratedrequest.jpg" alt="DhydratedRequest" width="383" height="78" /><br />
</a>Sample of a request (<em>DhydratedRequest.xml</em>).</p>
<p><a href="http://dhydrated.wordpress.com/files/2008/06/dhydratedresponse.jpg"><img class="alignnone size-full wp-image-23" src="http://dhydrated.wordpress.com/files/2008/06/dhydratedresponse.jpg" alt="DhydratedResponse" width="392" height="53" /><br />
</a>Sample of a response (<em>DhydratedResponse.xml</em>).</p>
<p>Then, run <em>Trang </em>to generate your XSD as below:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/trangcommand.jpg"><img class="alignnone size-full wp-image-24" src="http://dhydrated.wordpress.com/files/2008/06/trangcommand.jpg" alt="Trang Command" width="510" height="23" /><br />
</a>The last 3 arguments were the request xml sample , response xml sample  and the name of your-to-be XSD file. Once you run the command you will get below XSD file (<em>DhydratedTypes.xsd</em>):<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/dhydratedxsd-highlited.jpg"></a></p>
<p style="text-align:center;"><img class="size-full wp-image-25 aligncenter" src="http://dhydrated.wordpress.com/files/2008/06/dhydratedxsd-highlited.jpg" alt="Dhydrated XSD" width="392" height="409" /></p>
<p>As you may notice, the generated XSD is not all perfect yet. You may need to make some amendment to make it more suitable for your needs. I will make some changes on the part that I highlighted with red outlined box. For those elements, I want to restrict them with limited acceptable values. The final XSD will looks like below:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/dhydratedxsd-modified-highlited.jpg"><img class="alignnone size-full wp-image-26" src="http://dhydrated.wordpress.com/files/2008/06/dhydratedxsd-modified-highlited.jpg" alt="Modified DhydratedTypes.xsd" width="390" height="684" /></a><br />
Above, is how you can restrict the values of an element. For example, above, <em>TypeOfWater </em>element can only contains either <em>Spring</em>, <em>Tap</em>, <em>Rain</em> or <em>ReverseOsmosis </em>value. Now, you can use above XSD to validate against your request and response XML.</p>
<p>In summary, <em>Trang</em> doesn't really helps us to compose the perfect XSD, but it helps by giving us a good kick start, especially, for an XSD newbie like me :) . Plus, it will be less error-prone if you  start by generating your schema. Although, above sample request and response is quite simple, the XSD contains lots of repetitive keywords and prefixes which a typing error may be failed to be seen by our naked eye. So, play safe and generate!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Simplified EJB3 Testing]]></title>
<link>http://dhydrated.wordpress.com/?p=9</link>
<pubDate>Mon, 02 Jun 2008 06:25:06 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=9</guid>
<description><![CDATA[After working with Spring Framework to build POJO-based services, I found that it is  very easy to p]]></description>
<content:encoded><![CDATA[<p>After working with Spring Framework to build POJO-based services, I found that it is  very easy to perform a unit test on them. I just need to build a Service Locator to locate the bean, and Spring will do the rest, by injecting all the dependencies.</p>
<p>Lately, I was learning on how to use EJB3, then it got me thinking. Since, EJB3 session beans can't live outside their container and they rely on the container for the Dependency-Injection (DI), how on earth do I test them?. I've came across a utility, which can help me to test EJB3 components outside their container. It's an extension of JUnit and it's cleverly called EJB3Unit. Although, it should be easy to configure but it took me 3 days to figure it out (,after I've found out that I had downloaded the incorrect version, that is :p).</p>
<p>First off, you need to download the necessary EJB3Unit jar and its dependencies as shown below.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ejb3unit-dependencies.jpg"><img class="alignnone size-full wp-image-12" src="http://dhydrated.wordpress.com/files/2008/06/ejb3unit-dependencies.jpg" alt="Required Jars" width="457" height="489" /></a><a href="http://dhydrated.wordpress.com/files/2008/06/ejb3unit-dependencies.jpg"><br />
</a></p>
<p>If you wanted to test your data in your existing persistence layer, you could do that. But as you can see from above diagram, it natively uses Hibernate implementation for the Persistence Provider, and my project is running on GlassFish v2, and by default, it uses Toplink implementation. EJB3Unit also has another great feature which is called In Memory test. It will uses the default database in EJB3Unit, which is by HSQLDB (Hypersonice SQL Database) and auto-generates all the necessary components in the memory. After finishes executing the test methods, it will be cleared off.</p>
<p>Secondly, you need the EJBUnit properties file (ejb3unit.properties) in your classpath. If you need to do an In Memory test, you just have to following below settings:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ejb3properties.jpg"><img class="alignnone size-full wp-image-13" src="http://dhydrated.wordpress.com/files/2008/06/ejb3properties.jpg" alt="ejb3unit.properties" width="637" height="139" /></a></p>
<p>Lastly, you need to build the test class such as below:<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/sessionbean-test.jpg"><img class="alignnone size-full wp-image-14" src="http://dhydrated.wordpress.com/files/2008/06/sessionbean-test.jpg" alt="Session Bean Test" width="494" height="573" /></a></p>
<p>A bit of explanation might be justified. To test a simple session bean, your test class would need to extends from <em>com.bm.testsuite.BaseSessionBeanFixture</em> class and pass your Session bean class as the generic argument (, as shown in the picture, <em>com.dhydrated.business.ProcessBean</em> is my Session Bean). On line 17, you may need to pass your Entities, as array of java.lang.Class, but in my case I want to keep it simple and left it empty. In the constructor, you must call parent's constructor and pass your Session Bean class and the usedBeans variable. Then the rest will be your test methods. Here, I just have one simple test method called <em>testMyProcessBean</em>. In the method, I'll get my <em>ProcessBean </em>instance, and the DI will be handled by EJB3Unit. I can just simply call any methods in my <em>ProcessBean </em>instance, and as shown in above diagram, I'm calling my custom method called <em>printMessage</em> and it should returns a message in <em>String </em>object.</p>
<p>Now, I just need to compile and run above class and I should get the below output on my console.<br />
<a href="http://dhydrated.wordpress.com/files/2008/06/ejb3unit-output.jpg"><img class="alignnone size-full wp-image-16" src="http://dhydrated.wordpress.com/files/2008/06/ejb3unit-output.jpg" alt="" width="1026" height="262" /></a></p>
<p>Now, I can rest assured that my Session Bean is working fine before deploying it to the server.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Walk Down My Entities]]></title>
<link>http://dhydrated.wordpress.com/?p=7</link>
<pubDate>Fri, 30 May 2008 07:47:43 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=7</guid>
<description><![CDATA[Are you having problem constructing your JPQL (JPA Query Language) query? Tired of testing your quer]]></description>
<content:encoded><![CDATA[<p><a href="http://dhydrated.wordpress.com/files/2008/05/jqt.jpg"><img class="alignright size-medium wp-image-8" src="http://dhydrated.wordpress.com/files/2008/05/jqt.jpg?w=300" alt="" width="300" height="248" /></a>Are you having problem constructing your JPQL (JPA Query Language) query? Tired of testing your query by running your whole application on the server and only to find out that your query syntax is incorrect? If that's your case, JQT (JPA Query Tool) might be the answer for you. It allows you to browse through your entities in the database. You just pass your JPQL query, and it retrieves the entities for you. It also accepts native query if JPQL is not your cup of tea. It is easier and time saving to construct a query this way. You should only pass over the query to your application code once you ascertain that the query is valid.</p>
<p>The tool is available at this <a title="jpa-query-tool" href="https://jpaquerytool.dev.java.net">link</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Enterprise Computing By Day]]></title>
<link>http://wekaworx.wordpress.com/?p=18</link>
<pubDate>Fri, 30 May 2008 01:33:40 +0000</pubDate>
<dc:creator>wekaworx</dc:creator>
<guid>http://wekaworx.wordpress.com/?p=18</guid>
<description><![CDATA[
By day I am an enterprise developer (Java EE for those who care).
http://java.sun.com/javaee/
Enter]]></description>
<content:encoded><![CDATA[<p><a href="http://wekaworx.files.wordpress.com/2008/06/blokes.jpg"><img class="alignnone size-full wp-image-24" src="http://wekaworx.wordpress.com/files/2008/06/blokes.jpg" alt="IT Blokes (and girls)" width="400" height="539" /></a></p>
<p>By day I am an enterprise developer (Java EE for those who care).</p>
<p><a href="http://java.sun.com/javaee/">http://java.sun.com/javaee/</a></p>
<p>Enterprise systems are large computer systems usually talking to other large computer systems. I really like this work, it's hard, complex and not for everyone.</p>
<p>One aspect of this type of development is the other people you have to interact with. Last week was a bit like the picture above, where I had to solve many problems with an application due for release. I felt like the "Bloke from New Zealand".</p>
<p>Anyway, fitting into a team is all part of the fun!</p>
<p>This is quite different to Wekaworx, with a team of one, that's just me, and that's fun too, often more fun!</p>
<p>Don't be scared to be the bloke in the hole, others will look on with opinions, but only the guy in the hole is doing the job. What could be better than that!</p>
<p>Cheers</p>
<p>Graeme Young</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Security 2 Rocks]]></title>
<link>http://dhydrated.wordpress.com/?p=6</link>
<pubDate>Wed, 28 May 2008 07:41:23 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=6</guid>
<description><![CDATA[For those who has worked with Acegi Security previously, must have been through the XML hell since t]]></description>
<content:encoded><![CDATA[<p>For those who has worked with Acegi Security previously, must have been through the XML hell since there are a lot of boilerplate managed beans under the module. Fear no more, Spring Security 2 is here, to make it your day (if Spring is your cup of tea, that is). There have been some major changes, mostly to simplify the web security settings. There are 2 files needed to be updated/created.</p>
<p>First off, the web.xml, add the following elements:</p>
<p><strong>&#60;filter&#62;<br />
&#60;filter-name&#62;springSecurityFilterChain&#60;/filter-name&#62;<br />
&#60;filter-class&#62;org.springframework.web.filter.DelegatingFilterProxy&#60;/filter-class&#62;<br />
&#60;/filter&#62;</strong></p>
<p><strong>&#60;filter-mapping&#62;<br />
&#60;filter-name&#62;springSecurityFilterChain&#60;/filter-name&#62;<br />
&#60;url-pattern&#62;/*&#60;/url-pattern&#62;<br />
&#60;/filter-mapping&#62;</strong></p>
<p>Then finally, the Spring's beans xml file:</p>
<p><strong>&#60;http auto-config="true"&#62;</strong><strong><br />
&#60;intercept-url pattern="/faces/**" access="ROLE_SUPERVISOR"/&#62;</strong><strong><br />
&#60;intercept-url pattern="/faces/**" access="</strong><span class="sc3"><span class="st0">IS_AUTHENTICATED_REMEMBER</span></span><strong>"/&#62;<br />
&#60;/http&#62;</strong></p>
<p><strong>&#60;authentication-provider&#62;<br />
&#60;password-encoder hash="md5"/&#62;<br />
&#60;user-service&#62;<br />
&#60;user name="rod" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" /&#62;<br />
&#60;/user-service&#62;<br />
&#60;/authentication-provider&#62;</strong></p>
<p>Presto, my application is now secured by Spring. Of course, there are some prerequisite steps that I've done, such as, include all the dependencies libraries and setup Spring Core to load all  Spring's beans xml. For more info. please refer to <a title="Spring Security 2" href="http://static.springframework.org/spring-security/site/index.html" target="_blank">documentation</a> from Spring Framework. Surely, you could appreciate the simplicity of Spring Security 2, especially, compared to its predecessor. Caveat, this sample is not intended for production deployment but more for prototyping an application. Naturally, you might need to move out the authentication provider to another service provider such as  a database or LDAP authentication.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Richfaces and Facelets]]></title>
<link>http://ianmichell.wordpress.com/?p=7</link>
<pubDate>Thu, 22 May 2008 04:57:59 +0000</pubDate>
<dc:creator>ianmichell</dc:creator>
<guid>http://ianmichell.wordpress.com/?p=7</guid>
<description><![CDATA[I don&#8217;t know why I&#8217;ve fallen in love with JBoss richfaces&#8230; But I seem to have disc]]></description>
<content:encoded><![CDATA[<p>I don't know why I've fallen in love with JBoss richfaces... But I seem to have discovered it so useful! The fact that I can create a modal dialog window and then have it refresh behind the scenes to show stats for our printing devices at photobox is just fantastic!</p>
<p>The best thing of all, is that I have not had to write a single line of javascript!</p>
<p>Polling can be done with:</p>
<blockquote><p><em>&#60;h:form&#62;</em></p>
<p><em> &#60;a4j:poll id="poll" interval="500" enabled="true" reRender="poll, time" /&#62;</em></p>
<p><em>&#60;/h:form&#62;</em></p>
<p><em>&#60;h:outputText value="#{BackingBean.time}" id="time" /&#62;</em></p></blockquote>
<p>This will cause it to refresh the time every 500 miliseconds! What a pleasure.</p>
<p>Although most people have probably written about this, I just thought I would do it to show how happy I am with the library.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[JSP + ExtJS = ExtTLD]]></title>
<link>http://pedrosaf.wordpress.com/?p=8</link>
<pubDate>Wed, 21 May 2008 16:18:15 +0000</pubDate>
<dc:creator>Fernando Pedrosa</dc:creator>
<guid>http://pedrosaf.wordpress.com/?p=8</guid>
<description><![CDATA[Foi lançado a algum tempo uma biblioteca bastante interessante para a criação de aplicações Jav]]></description>
<content:encoded><![CDATA[<p>Foi lançado a algum tempo uma biblioteca bastante interessante para a criação de aplicações<!--more--> <a href="http://java.sun.com/javaee" target="_blank">Java EE</a> usando <a href="http://pt.wikipedia.org/wiki/AJAX_%28programa%C3%A7%C3%A3o%29" target="_self">AJAX</a>. Trata-se do  <a href="http://www.exttld.com/" target="_blank">ExtTLD</a>, biblioteca que contém um conjunto de tags que facilitam o uso do <a href="http://www.extjs.com/" target="_blank">ExtJS</a>.</p>
<p><img style="border:0 none;vertical-align:baseline;" src="http://www.exttld.com/img/examples/code/window.png" alt="" width="550" height="250" /></p>
<p>Figura 1 - Exemplo de Codificação</p>
<p><img style="border:0 none;vertical-align:baseline;" src="http://www.exttld.com/img/examples/components/window.png" alt="" width="329" height="273" /></p>
<p>Figura 2 - Exemplo do resultado do código da Figura 1</p>
<p>Olhando o demo dele, parece bem simples de usar, e há várias tags bem interessante, como é o caso da tag para tabela de dados, blocos de conteúdo, abas e etc. Vale a pena conferir.</p>
<p><img src="///home/pedrosa/Documentos/Imagens/Msn/eusou_fxdeveloperadesivo_.jpg" alt="" /></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Hello EJB 3!]]></title>
<link>http://dhydrated.wordpress.com/?p=5</link>
<pubDate>Wed, 21 May 2008 12:30:12 +0000</pubDate>
<dc:creator>dhydrated</dc:creator>
<guid>http://dhydrated.wordpress.com/?p=5</guid>
<description><![CDATA[I&#8217;ve been reading EJB 3 book for some days now and I&#8217;m loving it. For those who has a fa]]></description>
<content:encoded><![CDATA[<p>I've been reading EJB 3 book for some days now and I'm loving it. For those who has a fair share of hardship on developing with EJB 2.x, would really appreciate the simplicity of EJB 3. Since JEE supports annotation and DI (Dependency Injection), it really helps in making EJB 3 a really good competitor with other POJO oriented services. Prior learning EJB 3, I'm always goes for Spring beans, since it is a better alternative to EJB 2.x. But now, EJB 3 will be one of my top choices. However, Spring framework still is and always be my favorite since it is rich with useful modules. One of my favorite  is the security module. I can start building an application with a full-fledged security in a snap and no other can top that.</p>
<p>After 2 weeks without any real work, I was called for a technical interview. It is a norm in my company, where a staff will be interviewed before joining any project. So, I guess, I would excel in being interviewed if I stay in the company long enough. They asked mostly on old technologies such as JSP and JDBC in Java. I just hope I could leverage on EJB 3 in my upcoming projects.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Articles about SailFin and Neil Young]]></title>
<link>http://javawire.wordpress.com/?p=20</link>
<pubDate>Wed, 07 May 2008 13:33:56 +0000</pubDate>
<dc:creator>Olle</dc:creator>
<guid>http://javawire.wordpress.com/?p=20</guid>
<description><![CDATA[Two more articles published today, one about project SailFin, based on an interview with Sreeram Duv]]></description>
<content:encoded><![CDATA[<p>Two more articles published today, <a href="http://www.ericsson.com/mobilityworld/sub/articles/other_articles/080507_sailfin">one about project SailFin</a>, based on an interview with Sreeram Duvur at Sun, and <a href="http://www.ericsson.com/mobilityworld/sub/articles/other_articles/080507_rich">one about Rich Green's general session</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Web Quiz - Step 3: Finally time for some code]]></title>
<link>http://tootoorials.wordpress.com/?p=10</link>
<pubDate>Wed, 07 May 2008 13:33:50 +0000</pubDate>
<dc:creator>Albin Theander</dc:creator>
<guid>http://tootoorials.wordpress.com/?p=10</guid>
<description><![CDATA[It&#8217;s time to pull our fingers out of the holster and start coding. Lets plunge straight in and]]></description>
<content:encoded><![CDATA[<p>It's time to pull our fingers out of the holster and start coding. Lets plunge straight in and try to figure out what happens later:</p>
<ol>
<li>Start by right clicking the Quiz project and choose to create a new Servlet.</li>
<li>Go through the wizard and fill in the following fields (some of them have these values, by default):
<ul>
<li> Project: Quiz</li>
<li> Folder: \Quiz\src</li>
<li> Java Package: quiz</li>
<li> Class name: ShowNextQuestion</li>
<li> Superclass: javax.servlet.http.HttpServlet</li>
<li> Name: ShowQuestion</li>
<li> URL Mappings: /ShowQuestion</li>
</ul>
</li>
<li>Locate the doGet method and add the following code inside of it:</li>
</ol>
<p>PrintWriter out = response.getWriter();<br />
out.println("&#60;html&#62;&#60;head&#62;&#60;title&#62;Question&#60;/title&#62;&#60;/head&#62;");<br />
out.println("&#60;body&#62;&#60;form action=\"/Quiz/ShowQuestion\"&#62;");<br />
out.println("&#60;h1&#62;Question 1&#60;/h1&#62;&#60;p /&#62;&#60;p&#62;");<br />
out.println("What is a duck?&#60;/p&#62;");<br />
out.println("&#60;input type=\"radio\" value=\"1\" name=\"Answer\"&#62;A bird&#60;br&#62;");<br />
out.println("&#60;input type=\"radio\" value=\"2\" name=\"Answer\"&#62;A boat&#60;br&#62;");<br />
out.println("&#60;input type=\"radio\" value=\"3\" name=\"Answer\"&#62;A tiny, yellow java programmer floating in a tub&#60;br&#62;");<br />
out.println("&#60;input type=\"submit\" value=\"Ok\"");<br />
out.println("&#60;/form&#62;&#60;/body&#62;&#60;/html&#62;");</p>
<p>Save the file and run it on the server. (You can right-click on the file and choose run, or just stand in the editor and press the run button)</p>
<p>If you copied the code meticulously (or figured out how copy and paste works), you will see a web page with the question on it. Selecting a radio button and pressing OK will bring you back to the same page again, with the selected answer in the url.</p>
<p>So what happens here? Well, the browser tries to open "http://localhost:8080/Quiz/ShowQuestion". When we run the servlet, our application is automatically installed on the tomcat server on the path /Quiz/. (In a real environment we would choose the "base" path to our application when we installed it.) So the first part (http://localhost:8080/Quiz/) will bring the server to our application. For the next step, we need to take a peek in our web.xml. (It's in WebContent/WEB-INF, remember?). There are two entries that together maps the path "/ShowQuestion" to our servlet (quiz.ShowQuestion, remember the package name). First look at the servlet mapping:</p>
<p>&#60;servlet-mapping&#62;<br />
&#60;servlet-name&#62;ShowQuestion&#60;/servlet-name&#62;<br />
&#60;url-pattern&#62;/ShowQuestion&#60;/url-pattern&#62;<br />
&#60;/servlet-mapping&#62;</p>
<p>This entry says "If there is an incoming URL ending on /ShowQuestion, then execute the servlet named ShowQuestion". Next, we look at the servlet tag:</p>
<p>&#60;servlet&#62;<br />
&#60;description&#62;&#60;/description&#62;<br />
&#60;display-name&#62;ShowQuestion&#60;/display-name&#62;<br />
&#60;servlet-name&#62;ShowQuestion&#60;/servlet-name&#62;<br />
&#60;servlet-class&#62;quiz.ShowQuestion&#60;/servlet-class&#62;<br />
&#60;/servlet&#62;</p>
<p>This one says "There is a servlet named ShowQuestion, and the code is in quiz.ShowQuestion." The connection between these two entries is the servlet-name tag.</p>
<p>That brings into the servlet code. Depending on which method is used to call the servlet, different methods will be executed. Just opening a page uses GET, resulting in the doGet method being executed. If POST was used, the doPost method would have been called instead. Both these methods have two parameters: an HttpServletRequest and an HttpServletResponse. The Request represents the incoming data, this includes data that is sent to the servlet and which url was used to call it. The Response represents whatever we want to send back to the browser. In this example, we only sent back HTML, but we coule have set different status codes or cookies.</p>
<p>Let's finish this lesson with using our new knowledge to check if the correct answer was submitted. First, change the line in doGet which prints the form tag to:</p>
<p>out.println("&#60;form action=\"/Quiz/ShowQuestion\" method=\"POST\"&#62;");</p>
<p>This will post the information back to the servlet instead of sending it in the url. It also means that the doPost method will be called instead. Remember that the request parameter represents the incoming data? That's where we go digging for the answer. The field on the html form is called Answer, so add the following code to the doPost method:</p>
<pre style="font-size:12px;">
String answer = request.getParameter("Answer");
String sarcasticReaction = null;
if (answer.equals("1")) {
   sarcasticReaction = "Oh, it's a bird? I never would have guessed";
} else if (answer.equals("2")) {
   sarcasticReaction = "A duck-boat, huh? I wished for that when I was 5, too";
} else if (answer.equals("3")) {
   sarcasticReaction = "I didn't ask what &#60;i&#62;You&#60;/i&#62; were.";
}

PrintWriter out = response.getWriter();
out.println("&#60;html&#62;&#60;head&#62;&#60;title&#62;Question&#60;/title&#62;&#60;/head&#62;");
out.println("&#60;body&#62;");
out.println("&#60;h1&#62;Answer&#60;/h1&#62;&#60;p /&#62;&#60;p&#62;");
out.println(sarcasticReaction);
out.println("&#60;/body&#62;&#60;/html&#62;");
</pre>
<p>Note especially the first part where we get the answer from the request and checks it.</p>
<p>Try to run it again. The first time, GET is used, making our doGet to get executed. When the user pressed the Ok button, the browser submitts the answer with POST, triggering our doPost method.</p>
<p>It seems like a whole lot of steps from the moment the user presses ok to the point where the users sees the answer in the browser. But it's a real Speedy King. Even with more complex applications, these steps are executed in a jiffy.</p>
<p>Next time, I'll tell you why most of the lines of code written here are wrong and should be removed.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Published pre-JavaOne articles]]></title>
<link>http://javawire.wordpress.com/?p=3</link>
<pubDate>Wed, 30 Apr 2008 09:30:42 +0000</pubDate>
<dc:creator>Olle</dc:creator>
<guid>http://javawire.wordpress.com/?p=3</guid>
<description><![CDATA[Two articles I have written about JavaOne sessions that will be held by Ericsson employees was publi]]></description>
<content:encoded><![CDATA[<p>Two articles I have written about JavaOne sessions that will be held by Ericsson employees was published yesterday.</p>
<p>One is about Kristoffer Gronowski's sessions about developing end-to-end SIP communication services (TS-5802) and the SailFin SIP servlet container project (TS-5866 - held together with Binod Pg from Sun). Read the article <a href="http://www.ericsson.com/mobilityworld/sub/articles/other_articles/080428_gronowski">here</a>.</p>
<p>The other article is about a Birds Of a Feather (BOF) session held by Peter Kristiansson. Kristiansson will present an innovative way of enabling dynamic reconfiguration of high availability applications running in clustered environments. If you didn't understand that last sentence, read more <a href="http://www.ericsson.com/mobilityworld/sub/articles/other_articles/080429_kristiansson">here</a>.</p>
<p>UPDATE: Thanks <a href="http://weblogs.java.net/blog/binod/archive/2008/05/sailfin_at_java_1.html">Binod</a> for linking to the SailFin SIP servlet container project article...</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Deploying JHSDK in a Java EE environment]]></title>
<link>http://davidwburns.wordpress.com/?p=75</link>
<pubDate>Tue, 22 Apr 2008 16:56:34 +0000</pubDate>
<dc:creator>davidwburns</dc:creator>
<guid>http://davidwburns.wordpress.com/?p=75</guid>
<description><![CDATA[Introduction
Deploying a web application that uses the JHSDK is not as simple as throwing a jar file]]></description>
<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Deploying a web application that uses the JHSDK is not as simple as throwing a jar file in your lib directory. The JHSDK is a little different than other java libraries on three counts:</p>
<ol>
<li>it is a java wrapper for a C++ library. Allfusion Software Change Manager 7.x is a C++ application. The upcoming v12 release is a java application, so this C++ layer will go away. But for now, we're stuck with it.</li>
<li>it is a bridge for communicating with another enterprise system. Harvest is a non-web, n-tier system for managing change on software and documents. It has a proprietary front controller that brokers requests from various Harvest clients.<br />
<a href="http://davidwburns.files.wordpress.com/2008/04/fig18.jpg"><img class="alignnone size-medium wp-image-72" src="http://davidwburns.wordpress.com/files/2008/04/fig18.jpg?w=300" alt="Harvest Architecture from \" width="300" height="227" /></a></li>
<li>it's classes are not serializable, which presents problems when using it in Java EE environment</li>
</ol>
<p>So, for your Java EE application to use JHSDK it must</p>
<ol>
<li>know where the C++ libraries reside</li>
<li>run in an environment that has a Harvest client installed</li>
<li>use serializable wrappers for the JHSDK classes that you need to persist</li>
</ol>
<p>CA provides detailed documentation for setting up the environment in their Installation Guide. If you're not accustomed to installing a Harvest client, this can be somewhat challenging. I found it very easy to deploy my web application to my local windows installation of Glassfish because I already have a working Harvest client installed; however, I worked for nearly three weeks with my Sun admin, Harvest admin, and CA Support to configure our development Solaris environment. We had never used a Harvest client on Solaris before, and you know how UNIX environments are: SOME ASSEMBLY REQUIRED.</p>
<h2>Windows Deployment</h2>
<p>This is an account of my deployment to a Java EE platform on Windows</p>
<p>OS: Windows XP SP2</p>
<p>Application Server: Sun Java System Application Server 9.0 Update 1 (glassfish v2 ur1)</p>
<p>Harvest: AllFusion Harvest Change Manager 7.0</p>
<p>I didn't have to set up the Harvest Client because it was already done, so I won't comment on that.</p>
<p>In Windows, there are two files that Glassfish needs to know about: jhsdk.jar and JHSDK.dll. Both of these files need to be your Glassfish's path.</p>
<p>You can put them in</p>
<p>GLASSFISH_HOME\lib</p>
<p>or</p>
<p>GLASSFISH_HOME\domains\domain1\lib</p>
<p>If you deploy the jhsdk.jar file without the JHSDK.dll file, then you will receive the following error:</p>
<p><code>java.lang.UnsatisfiedLinkError: no JHSDK in java.library.path</code></p>
<p>At this point in the development process, my application provides a list of versions for a particular Harvest Package. The JCaVersion class does not implement java.io.Serialiable, so I was not able to bind it to my JSF component. So I wrote my own version of JCaVersion. I looped through my array of JCaVersions (which is returned from JCaPackage getVersionList()), and built an array of MyVersion instances with the same data. Then I could bind my array of MyVersion instances to my JSF component.</p>
<p>Finally, I deployed my WAR file and I was ready to go. I was so excited. WOW! That was easy! I'll just deploy it on the Solaris box and I'll be ready for show and tell. And......PRESTO!!! 3 weeks, 5 support emails to CA Support, a chat fight with my Sun admin, 50 meetings with my Harvest Admin later, it's working!</p>
<h2>Solaris Deployment</h2>
<p>OS: Solaris 9</p>
<p>Application Server: Sun Java System Application Server 9.0 Update 1 (glassfish v2 ur1)</p>
<p>Harvest: AllFusion Harvest Change Manager 7.0</p>
<p>The first issue that arose was that the client was not fully installed on the Solaris box. Our app server and the Harvest server happen to be installed on the same machine, so the client <em>should</em> have been installed and available already. The key command-line utilities were there, and the HSDK and JHSDK are supposed to come with the command-line utilities, but they didn't. So, we reinstalled the command-line utilities, and that set up all the files and directories we were needing.</p>
<p>Once we had the client installed, we needed to configure an environment for using the JHSDK. CA's installation guide is pretty explicit, but I had trouble using it...perhaps because I'm not really that skilled with Solaris. Here's what my env looks like:</p>
<p>JAVA_HOME=/usr/java<br />
HARVESTHOME=/xxx/ca/harvest<br />
CACRYPTINI=/opt/CA/CAcrypto/cacrypt.ini<br />
CACRYPTDIR=/opt/CA/CAcrypto<br />
DVHOME=/xxx/ca/pec/graphics/sun4_solaris<br />
RTARCH=sun4_solaris<br />
RTARCH_UC=SUN4_SOLARIS<br />
RTHOME=/xxx/ca/pec<br />
_app=/xxx/ca/pec/app-defaults<br />
export JAVA_HOME HARVESTHOME CACRYPTDIR CACRYPTINI<br />
export DVHOME RTARCH RTARCH_UC RTHOME _app<br />
LD_LIBRARY_PATH=${CACRYPTDIR}:${RTHOME}/lib/sun4_solaris:${RTHOME}/graphics/sun4_solaris/lib:/usr/lib<br />
LD_LIBRARY_PATH=${HARVESTHOME}/lib:${HARVESTHOME}/HSDK/lib:${HARVESTHOME}/JHSDK/lib:$LD_LIBRARY_PATH<br />
PATH=${RTHOME}/bin:${HARVESTHOME}/bin:$PATH<br />
export LD_LIBRARY_PATH PATH</p>
<p>I recommend following CA's advice to test your environment with the sample JHSDK application as detailed in the Installation Guide. This will tell you whether or not you were successful.</p>
<p>The next step is to configure Glassfish. This is where it gets weird. Even though we've setup all this path info in the environment, we have to do it again in Glassfish. My guess as to why? The Java EE environment needs to know the paths to the native libs so the when the JHSDK classes are called, then can know where to find their C++ peers. The user environment needs to know the paths so that when when one of the native C++ classes is called, it knows where they are and where Harvest is. Again, that's my best guess. If I learn different, or if you know different please tell me and I will give an update.</p>
<p>So here's what my Native Library Path Suffix in Glassfish looks like:</p>
<p>:/xxx/ca/harvest/lib:/xxx/ca/harvest/HSDK/lib:/xxx/ca/harvest/JHSDK/lib:/opt/CA/CAcrypto:/xxx/ca/pec/lib/sun4_solaris:/xxx/ca/pec/graphics/sun4_solaris/lib:/usr/lib</p>
<p>Here's what my Classpath Suffix looks like:</p>
<p>:/usr/java/jre/lib:/usr/java/lib:/xxx/ca/harvest/lib:/xxx/ca/harvest/HSDK/lib:/xxx/ca/harvest/JHSDK/lib:/xxx/ca/harvest/JHSDK/lib/jhsdk.jar</p>
<p>Look for future posts here on my use of JHSDK in my Java EE application. The journey has only begun...</p>
]]></content:encoded>
</item>

</channel>
</rss>
