Archive

Archive for the ‘Installation / Configuration’ Category

How to install wordpress 2.9 in Apache on your localhost in Ubuntu 9.10

December 28th, 2009 Karthikeyan C No comments

This post contains the steps involved to setup wordpress on your local machine in Ubuntu. ( You may want to setup a wordpress blog on local machine to customize your blog (look and feel etc) so as to save the time to FTP to a remote location.)

  1. Install Apache server using the command sudo apt-get install apache2
  2. Install PHP with sudo apt-get install php5
  3. Install the MySQL Database  sudo apt-get install mysql-server
  4. Install the PHP module for the Database sudo apt-get install php5-mysql
  5. Download the latest stable version of wordpress from http://wordpress.org/download/
  6. Extract the wordpress tar.gz or zip file to /var/www (using the command tar -C /var/www -zxvf wordpress-2.9.tar.gz)
  7. Create a MySQL database and if needed a new user who has required privileges.
  8. Navigate to /var/www/wordpress and execute the following command cp wp-config-sample.php wp-config.php (You may do this logging in as root user with the command sudo su )
  9. Edit wp-config.php using the command nano wp-config.php (or use any other editor like gedit) and configure the values for Database connection.
  10. Edit /etc/apache2/httpd.conf file to add the following lines. 
    LoadModule php5_module modules/libphp5.so
    AddType application/x-httpd-php  .php .phtml
  11. Restart apache server using the command sudo /etc/init.d/apache2 restart
  12. You can access the blog using http://localhost/wordpress
  • Share/Bookmark
Categories: Installation / Configuration Tags:

JBoss Tricks – How to deploy WAR JAR EAR in an external folder (directory)

December 11th, 2009 Karthikeyan C No comments

With JBoss 6.0.0.M1 out to try out the new JSRs the following may be helpful in reducing time to deploy.

The usual way in which we deploy an application (war , jar or ear ) is to drop the application archive ( or in expanded mode with the folder name ending with .war or .ear) under deploy folder of the server.

But how to deploy an application archive or a folder when it is not residing under deploy folder but resides in some other external folder?

Let’s say the application ROOT folder is E:\javaapps\myapptodeploy\webapplication.war, then in jboss-service.xml (under conf folder of the JBoss server profile (like default, all)),  we mention the following. This is very helpful when we build the project using Maven as we can mention the target directory directly without copying the files after each build.


<attribute name="URLs">
 deploy/,file:///E:/javaapps/myapptodeploy
</attribute>
  • Share/Bookmark

Step By Step Guide – Setup Seam 2.2.0.GA based Integration testing with Maven TestNG Cobertura

December 7th, 2009 Karthikeyan C No comments

This step by step guide explains / contains the following

  • Configure a Seam 2.2.0.GA, Hibernate (as the JPA implementation provider), RichFaces, PrimeFaces based project to be built by Maven (tested on 2.0.9 plus).
  • A simple Seam based web application which allows us to save (create and update) Employee details (just name and email to keep it simple) in MySQL database.
  • Write Seam based Integration test cases that run in JBoss Embedded container that run with TestNG.
  • Code coverage report generation using Cobertura.
  • The given project in this post is deployed on Tomcat 6.0.x.

The executable project code is available in Google code and can be obtained by downloading  here. (Please note that I have excluded files that ship with embedded JBoss download. I have provided screen shots of the final folder structure to avoid any confusion)

  1. Choose a folder of your choice. This will be known as ROOT folder for the project. Create a folder called src under it. Also create an empty file called pom.xml
  2. Under this src folder, create two folders called main and test.
  3. Under main folder, we will create the following folders – java, resources, sql and webapp.
  4. Under test folder, we will create the following folders – java, resources and a empty file called testng.xml.

What have we done so far ?:

- We have almost created a Seam based Maven archetype. The main folder contains files that are bundled in the deployable web application. test folder contains files used in various testing (Unit, Integration etc).

The final folder structure is provided as screen shots.

mainfoldertestfolder

Let us start with the employee table in database.


CREATE TABLE employee (
 id INTEGER NOT NULL AUTO_INCREMENT,
 name varchar(100) NOT NULL,
 email varchar(70) NOT NULL UNIQUE,
 PRIMARY KEY  (id)
);

The related JPA entity class is as below. The package is com.karthik.entity (full source code available in the zip file that can be downloaded).[This file is under src/main/java/com/karthik/entity]


@Entity
@Table(name = "employee")
@NamedQueries({
 @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")})
public class Employee implements Serializable {
 private static final long serialVersionUID = 1L;
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Basic(optional = false)
 @Column(name = "id")
 private Integer id;
 @Basic(optional = false)
 @Column(name = "name")
 private String name;
 @Basic(optional = false)
 @Column(name = "email")
 private String email;

Now we need a Seam backing bean to save a new Employee data, update existing Employee data and retrieve all employees in database. The source code of the backing bean EmployeeSaveAction.java is provided below. [This file is under src/main/java/com/karthik/action]


package com.karthik.action;

import com.karthik.entity.Employee;
import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;

@Name("employeeaction")
public class EmployeeSaveAction implements Serializable{

 @In
 EntityManager em;
 private Employee employee;
 @DataModel
 List<Employee> employeeList;
 @DataModelSelection("employeeList")
 Employee selectedEmployee;

 @Create
 public void init() {
 employee = new Employee();
 }

 @Factory("employeeList")
 public void populateEmployeeList(){
 employeeList=em.createNamedQuery("Employee.findAll").getResultList();
 }

 public void createEmployee() {
 em.persist(employee);
 //clear UI values
 employee = new Employee();
 populateEmployeeList();
 }

 public void update(){
 selectedEmployee=em.merge(selectedEmployee);
 populateEmployeeList();
 }

 public Employee getEmployee() {
 return employee;
 }

 public void setEmployee(Employee employee) {
 this.employee = employee;
 }

}

Now we focus on configuring Seam to do the necessary injection in the above backing bean. First comes components.xml (this is under src/main/webapp/WEB-INF)


<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
 xmlns:core="http://jboss.com/products/seam/core"
 xmlns:persistence="http://jboss.com/products/seam/persistence"
 xmlns:transaction="http://jboss.com/products/seam/transaction"
 xmlns:web="http://jboss.com/products/seam/web"
 xmlns:security="http://jboss.com/products/seam/security"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:ui="http://jboss.com/products/seam/ui"
 xmlns:mail="http://jboss.com/products/seam/mail"
 xsi:schemaLocation=
 "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">

 <core:manager conversation-timeout="120000"
 concurrent-request-timeout="2000"
 conversation-id-parameter="cid"
 />
  <transaction:entity-transaction entity-manager="#{em}"/>
  <persistence:entity-manager-factory name="exampleDatabase"/>
  <persistence:managed-persistence-context name="em"
 auto-create="true"
 entity-manager-factory="#{exampleDatabase}"/>
 </components>

Now we need a UI to create, update values. Part of the source code of employee.xhtml is provided below [The file is under src/main/webapp]. Complete source code is provided in the zip file that can be downloaded  from Google code.


  <h:form>
            <rich:messages/>
            <s:validateAll>

                <rich:panel id="homepanel">
                    <f:facet name="header">
                       Seam Example
                    </f:facet>
                    <h:panelGrid columns="2">
                        <h:outputText value="Employee Name:"/>
                        <h:inputText value="#{employeeaction.employee.name}" required="true"/>

                        <h:outputText value="Email:"/>
                        <h:inputText value="#{employeeaction.employee.email}" required="true"/>

                        <h:commandButton action="#{employeeaction.createEmployee}" value="Create Employee"/>
                    </h:panelGrid>
                    <br/>
                    List of Existing Employees
                    <br/>
                    <rich:dataTable value="#{employeeList}" var="emp">
                        <rich:column>
                            <f:facet name="header">
                               Name
                            </f:facet>
                            <h:inputText value="#{emp.name}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                Email
                            </f:facet>
                            <h:inputText value="#{emp.email}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                Update
                            </f:facet>
                            <h:commandButton action="#{employeeaction.update}" value="Update"/>
                        </rich:column>

                    </rich:dataTable>
                </rich:panel>
            </s:validateAll>
        </h:form>

The faces-config.xml file is provided below (File is under src/main/webapp/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2"
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

    <!-- Facelets support -->
    <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    </application>

</faces-config>

We do not utilize pages.xml defining page navigation in Seam but for the sake of completeness it is provided below. (File is under src/main/webapp/WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<pages xmlns="http://jboss.com/products/seam/pages"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd">
</pages>

And here comes web.xml (The file is under src/main/webapp/WEB-INF].

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- Seam   -->

    <listener>
        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
    </listener>

    <filter>
        <filter-name>Seam Filter</filter-name>
        <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
        <init-param>
            <param-name>forceparser</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>enable-cache</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <url-pattern>/seam/resource/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>Document Store Servlet</servlet-name>
        <servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Document Store Servlet</servlet-name>
        <url-pattern>*.csv</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Document Store Servlet</servlet-name>
        <url-pattern>*.xls</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>Resource Servlet</servlet-name>
        <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Resource Servlet</servlet-name>
        <url-pattern>/primefaces_resource/*</url-pattern>
    </servlet-mapping>
     <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
     <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
    </servlet-mapping>
     <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <!-- JSF parameters -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>DEFAULT</param-value>
    </context-param>
    <context-param>
        <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
        <param-value>true</param-value>
    </context-param>
    <session-config>
        <session-timeout>20</session-timeout>
    </session-config>
  </web-app>

Dont get bored :) , there are only two more files left under main folder that are part of our web application.
We need to have a marker file called seam.properties under src/main/resources folder (that will eventually be under WEB-INF/classes of your web application).
Seam will scan and register our Seam components only if this file is detected.

And the last one is persistence.xml (The file is under src/main/resources/META-INF)

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="exampleDatabase" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!--Uncomment the below when you use Tomcat-->
   <jta-data-source>java:comp/env/jdbc/exampleDatabase</jta-data-source>
    <!--Uncomment the below when you run test cases in embedded server-->
    <!--<non-jta-data-source>java:/exampleDatabase</non-jta-data-source>-->

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="validate"/>
      <property name="hibernate.show_sql" value="false"/>
    </properties>
  </persistence-unit>
</persistence>

Now we shift our focus to test folder. Let us start with testng.xml (TestNG configuration file which is under src/test)

<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="KarthiksExampleSuite">
    <parameter name="datasourceJndiName" value="java:/exampleDatabase"/>
    <parameter name="database" value="MySQL" />
    <parameter name="binaryDir" value="img/" />
    <test name="Group Test">
        <packages>
            <package name="com.karthik.test" />
        </packages>
   </test>
</suite>

Next file is the Seam based TestNG test case which runs test cases to verify the creation of a new Employee in database. The file is under src/test/java/com/karthik/test
and the source code is provided below.


package com.karthik.test;

import com.karthik.entity.Employee;
import javax.faces.model.DataModel;
import org.jboss.seam.mock.DBUnitSeamTest;
import org.testng.annotations.Test;

public class EmployeeTest extends DBUnitSeamTest {

    private int numOfEmpBeforeAdd;
    private String name;
    private String email;

    @Test(groups = "embeddedcontainer")
    public void testEmployee() throws Exception {

        new FacesRequest("/employee.xhtml") {

            @Override
            protected void updateModelValues() throws Exception {
                name = "Name of employee" + System.nanoTime();
                email = "abc" + System.nanoTime() + "@xmail.com";

                setValue("#{employeeaction.employee.name}", name);
                setValue("#{employeeaction.employee.email}", email);
            }

            @Override
            protected void invokeApplication() {
                DataModel empList = (DataModel) getValue("#{employeeList}");
                numOfEmpBeforeAdd = empList.getRowCount();
                assert invokeAction("#{employeeaction.createEmployee}") == null;

            }

            @Override
            protected void renderResponse() {

                DataModel empList = (DataModel) getValue("#{employeeList}");
                assert empList.getRowCount() == (numOfEmpBeforeAdd + 1);
                empList.setRowIndex(numOfEmpBeforeAdd + 1);
                boolean isEmployeeAvailable = false;
                for (int ctr = 0; ctr < empList.getRowCount(); ctr++) {
                    empList.setRowIndex(ctr);
                    Employee employee = (Employee) empList.getRowData();

                    if (employee.getName().equals(name) && employee.getEmail().equals(email)) {
                        isEmployeeAvailable = true;
                    }

                }//for loop ends
                assert isEmployeeAvailable;
            }
        }.run();
    }

    @Override
    protected void prepareDBUnitOperations() {
    }
}

Now comes the most important part of configuring the embedded JBoss container. The configuration is involves 3 easy steps.
Step 1: Please download embedded-jboss-beta3.SP10.zip. Extract it to any temporary folder and copy the content of bootstrap folder (do not
copy bootstrap but only the content in it) and paste it under src/test/resources
Step 2: Configure the datasource for the embedded JBoss container. The file testmysql-ds.xml (The file is placed under src/test/resources/deploy)
is as below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources
    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
    "http://www.jboss.com/j2ee/dtd/jboss-ds_1_5.dtd">
<datasources>
   <local-tx-datasource>
      <jndi-name>exampleDatabase</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/ck</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      <password>password</password>
   </local-tx-datasource>
</datasources>

Step 3: In the above testng.xml configuration we had mentioned the binary folder as img. So create a folder called img under src/test/resources
and place an empty marker file called marker.txt (An empty marker file is needed so that Maven copies the empty folder also).

With that we complete the files under test folder. And now the most important file pom.xml which is under ROOT folder parallel to src folder.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<properties>
<seam.version>2.2.0.GA</seam.version>
<richfaces.version>3.3.2.GA</richfaces.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.karthik</groupId>
<artifactId>seamtest</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>karthiks Seam TestNG Example</name>
<build>
<finalName>seamtest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<configuration>
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.testOutputDirectory}/endorsed</outputDirectory>
</configuration>
<id>download-jaxb-api</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<copy todir="${project.build.testOutputDirectory}">
<fileset dir="${basedir}/src/main/webapp"/>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/testng.xml</suiteXmlFile>
</suiteXmlFiles>

<childDelegation>true</childDelegation>
<useSystemClassLoader>true</useSystemClassLoader>
<argLine>-Djava.endorsed.dirs=${project.build.testOutputDirectory}/endorsed -Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<check>
<haltOnFailure>false</haltOnFailure>
<regexes>
<regex>
<pattern>com.karthik.*</pattern>
<branchRate>70</branchRate>
<lineRate>70</lineRate>
</regex>

</regexes>
</check>
<instrumentation>
<includes>
<include>com/**/*.class</include>

</includes>
</instrumentation>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repository.jboss.org</id>
<url>http://repository.jboss.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>repository.central.org</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>primefaces.repo</id>
<name>Prime Technology Maven Repository</name>
<url>http://repository.prime.com.tr</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<!--Start of dependencies for embedded JBoss container required for Integration test cases-->
<dependency>
<groupId>org.jboss.embedded</groupId>
<artifactId>jboss-embedded-all</artifactId>
<version>beta3.SP10</version>
<exclusions>
<exclusion>
<groupId>org.jboss.embedded</groupId>
<artifactId>jboss-embedded</artifactId>
</exclusion>

<exclusion>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-client-spi</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-core-spi</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.embedded</groupId>
<artifactId>thirdparty-all</artifactId>
<version>beta3.SP10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.embedded</groupId>
<artifactId>jboss-embedded</artifactId>
<version>beta3.SP10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-client-spi</artifactId>
</exclusion>

</exclusions>
</dependency>
<!--End of dependencies for embedded JBoss container required for Integration test cases-->

<!--Start of TestNG dependency-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.10</version>
<scope>test</scope>
<classifier>jdk15</classifier>
</dependency>
<!--el is required to parse the SeamTest setValue and invokeMethod stuff-->
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<!-- If you use any database other than MySQL please change the below dependency accordingly-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--End of TestNG dependency-->
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<version>${seam.version}</version>
<exclusions>
<exclusion>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-ui</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-pdf</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-mail</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-ioc</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-remoting</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-rss</artifactId>
<version>${seam.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-excel</artifactId>
<version>${seam.version}</version>
</dependency>

<!-- Seam makes use of Hibernate which  depends on JTA and JPA-->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>

<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>1.2_12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_12</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-api</artifactId>
<version>${richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
<version>${richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>${richfaces.version}</version>

</dependency>

<!--Java Mail Related dependencies-->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>

<!--Log4j-->
<dependency>
<groupId>apache-log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.8a</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>1.0.0.RC</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
</project>

Things to consider:

To run the Integration test cases comment the Tomcat specific datasource configuration and uncomment JBoss specific datasource configuration as shown in the comment section of persistence.xml reproduced below. (You can avoid this ugly way of comment and uncomment by using Maven profiles – one profile for testing and the other for a deployable in Tomcat).


<!--Uncomment the below when you use Tomcat-->
<!--jta-data-source>java:comp/env/jdbc/exampleDatabase</jta-data-source-->
<!--Uncomment the below when you run test cases in embedded server-->
<non-jta-data-source>java:/exampleDatabase</non-jta-data-source>

The test cases are executed when we run a command like mvn install

To run cobertura and generate reports, the command is mvn cobertura:cobertura (The cobertura reports will be under target/site/cobertura. Please click on the index.html to view the report.)

coberturareport

To create a deployable, make the required change in persistence.xml (as explained in Things to consider) and run the command like mvn install -Dmaven.test.skip (As the test cases will not execute with a Tomcat specific data source configuration in persistence.xml. I will try to do more analysis on this and check if it is possible to pick up different files one for test and the other to be packaged in web application deployable).

Hope this post is of some use. Please provide your suggestions (to improve this configuration) as a comment.

Seam Example By Karthikeyan C Seam Example
List of Existing Employees
Name Email Update
  • Share/Bookmark

How to uninstall NetBeans from Ubuntu

December 6th, 2009 Karthikeyan C No comments

NetBeans has been releasing in short cycles (The difference between NetBeans 6.8 RC1 and RC2 was just 4 days). So how to uninstall (remove) the older installations in Ubuntu ?

There is a file uninstall.sh under the root (home) directory of NetBeans installation. Navigate to root directory and execute uninstall.sh. A window pops up and you can proceed with the uninstallation.

  • Share/Bookmark

Wordpress tricks useful for me

December 3rd, 2009 Karthikeyan C No comments

This link by perishablepress.com is rather a long post which is very useful and I badly needed the below trick as the wordpress database size was growing too fast.

- Disabling post revisions by adding the following line to wp-config.php

define('WP_POST_REVISIONS', FALSE);

-

  • Share/Bookmark

Redirecting permanently in HttpServlet from your old domain (website) to new domain

November 29th, 2009 Karthikeyan C No comments

Let us assume we face a scenario where we move from a old domain (website) to a new domain (website). You may do this when you expand your business offering and the old name may not be appropriate.

But your old domain has gained reputation (like a good page rank and a number of incoming links) which you wish to carry forward to your new domain. One way of doing this is respond with HTTP code 301 which is permanently moved.

You may also make use of use Google web master tools to inform the change in domain address (as Google is currently the #1 search engine ). This will prevent the decrease in hits to your website from search engines.

The below code shows how to implement it if you host a Java web application for your old domain.

In web.xml make the below entry.


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <servlet>
 <servlet-name>RedirectionServlet</servlet-name>
 <servlet-class>com.olddomain.web.servlet.RedirectionServlet</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>RedirectionServlet</servlet-name>
 <url-pattern>/*</url-pattern>
 </servlet-mapping>
 </web-app>

Next the code for RedirectionServlet.java


package com.olddomain.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectionServlet extends HttpServlet {

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {

 //Get the incoming URL request.
 response.setHeader("Location", "http://www.yournewdomain.com"+request.getRequestURI());
 response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
 }

 @Override
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 processRequest(request, response);
 }

 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 processRequest(request, response);
 }
}

Note: Using response.sendRedirect will produce only HTTP status code 302 which is temporarily moved and not 301 which indicates it is permanently moved.

  • Share/Bookmark

Configuring OsTicket for your website in shared server hosting

November 24th, 2009 Karthikeyan C No comments

Many of the shared server hosting providers do not enable email piping. Hence OsTicket may not work resulting in an error “local delivery failed”.

But they may provide an option to use IMAP/POP poll to retrieve the ticket information (This should be enabled in the Email related settings in OsTicket). Now to enable this poll we have to setup a cronjob. Before setting up cronjob, we can know the PHP location by running the following command.

which php

which will produce a result like

/usr/local/bin/php

.

Now set up a cronjob with the following command.

/usr/local/bin/php  /home/username/pathToOsTicketInstallation/api/cron.php

Note: Please ensure cron.php has executable rights (else run chmod +x)

  • Share/Bookmark

How to configure Log4j for a web application in Tomcat

November 18th, 2009 Karthikeyan C No comments

By default Tomcat uses JDK logging. I used the following  log4j.xml [which should go under WEB-INF\classes folder] to enable log4j for a SEAM based web application [infact  for any  web application] in Tomcat. In Maven please place it under, src\main\resources.


<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

 <appender name="CONSOLE">

 <param name="Target" value="System.out"/>

 <layout>
 <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
 </layout>
 </appender>
 <appender name="FILE">

 <param name="File" value="${catalina.base}/logs/yourwebappname.log"/>

 <param name="DatePattern" value="'.'yyyy-MM-dd"/>
 <layout>
 <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
 </layout>
 </appender>

 <root>
 <priority value="INFO"/>

 <appender-ref ref="FILE"/>
 <appender-ref ref="CONSOLE"/>
 </root>

 </log4j:configuration>

In a Maven based application add the below dependency to include log4j jar.

<dependency>
<groupId>apache-log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
  • Share/Bookmark

How to restore default panel in Ubuntu 9.10

November 17th, 2009 Karthikeyan C No comments

I messed up with my Ubuntu panel and lost the “Applications, Places and System” menu on the panel. This post helped me to restore and revert back to the default panel in Ubuntu 9.10.  http://martinwebster.info/2009/06/13/restore-default-ubuntu-panel/ (Though the post is for 9.04 it works fine for 9.10).

The commands to be used are

$ gconftool-2 --shutdown
$ rm -rf .gconf/apps/panel
$ pkill gnome-panel
  • Share/Bookmark

Valid Connection checking in JBoss application server 5.1.0 for MySQL

November 15th, 2009 Karthikeyan C No comments

MySQL connections in a pool times out after a long period of inactivity [I believe 8 hours is the time period by default.] Hence the connections in the pool become stale and this results in exceptions like java.sql.SQLException: Communication link failure.(The same scenario can also be simulated by bringing JBoss up when MySQL is up and running and then restarting MySQL server.) To avoid this we have to instruct JBoss to validate a connection by issuing a test SQL.

Option 1 and the preferred way
to do it is to place the following in the datasource configuration file for JBoss


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE datasources
 PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
 "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<datasources>
 <local-tx-datasource>
 <jndi-name>TestDB</jndi-name>
 <connection-url>jdbc:mysql://localhost:3306/seam</connection-url>
 <driver-class>com.mysql.jdbc.Driver</driver-class>
 <user-name>root</user-name>
 <password>password</password>
 <min-pool-size>4</min-pool-size>
 <max-pool-size>20</max-pool-size>
 <idle-timeout-minutes>10</idle-timeout-minutes>
 <exception-sorter-class-name>
 com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
 </exception-sorter-class-name>
 <valid-connection-checker-class-name>
 com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
 </valid-connection-checker-class-name>
 <background-validation>true</background-validation>
 <background-validation-minutes>10</background-validation-minutes>
 <metadata>
 <type-mapping>mySQL</type-mapping>
 </metadata>
 </local-tx-datasource>
</datasources>

Option 2 - We can also validate the connection by using the following.


<check-valid-connection-sql>select 1</check-valid-connection-sql>
 <new-connection-sql>select 1</new-connection-sql>

JBoss documentation suggests Option 1 is the preferred way.

  • Share/Bookmark