August 2012 Posts

Setting Up C3P0 Connection Pooling on Apache Tomcat

My using this configuration on my Apache Tomcat 7 for my heavy-load application, and it runs very well. I put this code on context.xml under Apache Tomcat’s conf folder.

<Resource name="myconnection" auth="Container"
	driverClass="com.mysql.jdbc.Driver"
	jdbcUrl="jdbc:mysql://localhost:3306/mydatabase"
	user="root"
	password="xxxx"                                                      
	factory="org.apache.naming.factory.BeanFactory" 
	type="com.mchange.v2.c3p0.ComboPooledDataSource" 
	maxPoolSize="50" 	
	minPoolSize="15" 
	acquireIncrement="3" 
	acquireRetryAttempts = "0"
	acquireRetryDelay = "3000"
	breakAfterAcquireFailure = "false"
	maxConnectionAge = "60"
	maxIdleTime = "30"
	maxIdleTimeExcessConnections = "10"
	idleConnectionTestPeriod = "15"
	testConnectionOnCheckout = "true"
	preferredTestQuery = "SELECT 1"
	debugUnreturnedConnectionStackTraces = "true"	
	autoCommitOnClose="true"
	/>

I use MySql’s command “SHOW PROCESSLIST” for checking on opened connection to MySql.

I hope it helped others.
:-[

Google+

Selamat Idul Fitri 1433H 2012AD

Let’s write all the mistakes down in the sand
And let the wind of forgiveness erase it away
Happy Idul Fitri, Minal Aidin wal Faidzin


Kartu Lebaran 1433H 2012AD

Google+

Menteri Sosial RI, Salim Segaf Al-Jufri yang Mirip dengan Admiral Kizaru

Sekedar iseng, entah kenapa waktu gw lagi liat-liat daftar Menteri di Wikipedia, perhatian gw tertuju kepada salah satu menteri di kabinet Indonesia Bersatu jilid 2, yaitu Bapak Salim Segaf Al-Jufri. Gw perhatikan sekilas beliau mirip-mirip dikit dengan Admiral Kizaru dari manga One Piece, berikut sekilas perbandingannya.



mirip kan? (Y)

Google+

Beginning Sitemesh

In this tutorial, im trying to create a simple application using Sitemesh. According to Wikipedia, Sitemesh is a web-page layout and decoration framework and web application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required. So basically, Sitemesh is a templating engine or a decorator pattern.

Let’s start with a simple application, first is a maven’s pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.edw</groupId>
    <artifactId>SitemeshExample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SitemeshExample Web App</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <netbeans.hint.deploy.server>Tomcat70</netbeans.hint.deploy.server>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>sitemesh</artifactId>
            <version>2.4.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>SitemeshExample</finalName>
    </build>
</project>

and this is my web.xml file,

<?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">
    <display-name>Sitemesh</display-name>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

next step is creating decorators.xml under WEB-INF folder

<?xml version="1.0" encoding="UTF-8"?>
<decorators>
    <excludes>
        <pattern>/index.jsp</pattern> <!-- exclude example -->
        <pattern>*.js</pattern> <!-- exclude css files -->
        <pattern>*.css</pattern> <!-- exclude js files -->
    </excludes>
    <decorator name="basic-theme" page="/template/theme.jsp">        
        <pattern>/*</pattern>        
    </decorator>
</decorators>

and a base html template

<?xml version="1.0" encoding="UTF-8" ?>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Title</title>
</head>
<body>
    <h1>Header</h1>
    <p><b>Menu</b></p>
    
    <decorator:body />
    
    <h1>Footer</b></h1>
</body>
</html>

And 2 .jsp files for example, index.jsp and dodol.jsp
index.jsp

<div>
    <h2>Hello WORLD...!! (Without Sitemesh)</h2>
</div>

and dodol.jsp

    <h1>Hello World! (With Sitemesh)</h1>

these is the screenshot when i deploy my application,

and this is my netbeans project structure

Google+

A Weird SpringSource Tool Suite (STS) Error, “No Java Virtual Machine was Found”

I had this weird error when i execute my Springsource Tool Suite, somehow it cannot found my JRE.

A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run STS. 

It looks like my “-vm” argument in STS.ini file still pointing at my uninstalled JRE location. I just do some minor change and replace it to my existing JDK location and my STS is running again.

Simple isnt it?

(W)

Google+