Friday, July 8, 2011
Thursday, March 24, 2011
Friday, March 4, 2011
AspectJ Example with Weblogic Server
Overview
This example provide steps to configure AspectJ Load Time Weaving with WebLogic Server. Also provide steps to run sample application
Configuration
modify $DOMAIN_HOME/bin/startWebLogic.cmd
To add following"
1) include -javaagent:%ASPECTJ_HOME%\lib\aspectjweaver.jar to JAVA_OPTIONS
search for following line in startWebLogic.cmd
set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%
Add following snippet below it:
set ASPECTJ_HOME=C:\softwares\aspectj1.6
set JAVA_OPTIONS=-javaagent:%ASPECTJ_HOME%\lib\aspectjweaver.jar
2) include aspectjrt.jar in classpath
search for echo WLS Start Mode=%WLS_DISPLAY_MODE% in startWebLogic.cmd
Add following line below it:
set CLASSPATH=C:\softwares\aspectj1.6\lib\aspectjrt.jar;%CLASSPATH%
Sample Application
The sample app contains a servlet which make jdbc calls. And the aspectj will monitor for any calls made from classes present in java.sql package. I'll reuse code from Ramnivas Laddad's book (AspectJ in Action)
Servlet
package demo;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JDBCServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
// Load (and therefore register) the Oracle Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// Get a Connection to the database
con = DriverManager.getConnection(
"jdbc:oracle:thin:@host:port:SID", "username", "pwd");
// Create a Statement object
stmt = con.createStatement();
// Execute an SQL query, get a ResultSet
rs = stmt.executeQuery("SELECT name, address FROM Employees");
// Display the result set as a list
while(rs.next()) {
out.println(rs.getString("name") + " " + rs.getString("address"));
}
}
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
// Always close the database connection.
try {
if (con != null) con.close();
}
catch (SQLException ignored) { }
}
}
}
Aspect Sample
/*
Copyright 2009 Ramnivas Laddad
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//Listing 7.10 Performance monitoring aspect using an around() advice
package ajia.monitoring;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
//import ...
@Aspect
public abstract class Monitoring {
@Pointcut
public abstract void monitored();
@Around("monitored()")
public Object measureTime(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.nanoTime();
Object ret = pjp.proceed();
long endTime = System.nanoTime();
System.out.println("Method " + pjp.getSignature().toShortString()
+ " took " + (endTime - startTime));
return ret;
}
}
AOP.xml [from chapter 8 section 4 .4 LoadTimeWeaver ]
Application Structure

jdbc-aspect.jar structure

Deployment Steps
Deploy servlet in nostage mode from weblogic console
Create a jar which contains the aspect and aop.xml
Copy this jar to WEB-INF/lib folder of the servlet application.
Start weblogic using $DOMAIN_HOME/startWebLogic.cmd
Invoke the servlet : http://localhost:7001/JDBCServlet/JDBCServlet
Now messages from Aspectj are printed to console
This example provide steps to configure AspectJ Load Time Weaving with WebLogic Server. Also provide steps to run sample application
Configuration
modify $DOMAIN_HOME/bin/startWebLogic.cmd
To add following"
1) include -javaagent:%ASPECTJ_HOME%\lib\aspectjweaver.jar to JAVA_OPTIONS
search for following line in startWebLogic.cmd
set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%
Add following snippet below it:
set ASPECTJ_HOME=C:\softwares\aspectj1.6
set JAVA_OPTIONS=-javaagent:%ASPECTJ_HOME%\lib\aspectjweaver.jar
2) include aspectjrt.jar in classpath
search for echo WLS Start Mode=%WLS_DISPLAY_MODE% in startWebLogic.cmd
Add following line below it:
set CLASSPATH=C:\softwares\aspectj1.6\lib\aspectjrt.jar;%CLASSPATH%
Sample Application
The sample app contains a servlet which make jdbc calls. And the aspectj will monitor for any calls made from classes present in java.sql package. I'll reuse code from Ramnivas Laddad's book (AspectJ in Action)
Servlet
package demo;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JDBCServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
// Load (and therefore register) the Oracle Driver
Class.forName("oracle.jdbc.driver.OracleDriver");
// Get a Connection to the database
con = DriverManager.getConnection(
"jdbc:oracle:thin:@host:port:SID", "username", "pwd");
// Create a Statement object
stmt = con.createStatement();
// Execute an SQL query, get a ResultSet
rs = stmt.executeQuery("SELECT name, address FROM Employees");
// Display the result set as a list
while(rs.next()) {
out.println(rs.getString("name") + " " + rs.getString("address"));
}
}
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
// Always close the database connection.
try {
if (con != null) con.close();
}
catch (SQLException ignored) { }
}
}
}
Aspect Sample
/*
Copyright 2009 Ramnivas Laddad
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//Listing 7.10 Performance monitoring aspect using an around() advice
package ajia.monitoring;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
//import ...
@Aspect
public abstract class Monitoring {
@Pointcut
public abstract void monitored();
@Around("monitored()")
public Object measureTime(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.nanoTime();
Object ret = pjp.proceed();
long endTime = System.nanoTime();
System.out.println("Method " + pjp.getSignature().toShortString()
+ " took " + (endTime - startTime));
return ret;
}
}
AOP.xml [from chapter 8 section 4 .4 LoadTimeWeaver ]
jdbc-aspect.jar structure
Deployment Steps
Deploy servlet in nostage mode from weblogic console
Create a jar which contains the aspect and aop.xml
Copy this jar to WEB-INF/lib folder of the servlet application.
Start weblogic using $DOMAIN_HOME/startWebLogic.cmd
Invoke the servlet : http://localhost:7001/JDBCServlet/JDBCServlet
Now messages from Aspectj are printed to console
Sunday, October 3, 2010
How to install sun jdk in ubuntu
ubuntu version : ubuntu 9.10
pre-requisite:

Use apt-get:
apt-get install sun-java6-jdk sun-java6-jre
when download is complete, you get license popup, select "Ok" and then from next popup select "Yes". Installation will start.
after installation set JAVA_HOME environment variable.
pre-requisite:
- enter root shell
- If root account is not enabled, then enable it. Navigate to System > Administration > Users and Groups. And click 'lock icon' and set password for root. Then run "su" to enter root shell.

Use apt-get:
apt-get install sun-java6-jdk sun-java6-jre
when download is complete, you get license popup, select "Ok" and then from next popup select "Yes". Installation will start.
after installation set JAVA_HOME environment variable.
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
Saturday, December 19, 2009
HTML 5 Promises
Web is becoming a client-side computing platform and the fancy features in HTML5 promises to accelerate it. It will help to create more complex and rich web applications. The ability to link to a video/audio file as simply as an image file is a very powerful.
Though its in specification stage, browsers and we sites are betting big on it. Youtube has a demo page which doesn't use Flash. It uses HTML 5 video tag. Several other demos are listed here.
Though its in specification stage, browsers and we sites are betting big on it. Youtube has a demo page which doesn't use Flash. It uses HTML 5 video tag. Several other demos are listed here.
Thursday, November 19, 2009
AJAX Libraries
Recently I came across open source AJAX libraries like JQuery, prototype, script_aculo_us etc. Most of them offer similar features and developers wonder which one to use and how to keep up with new versions, bug fixes, etc.
The AJAX Libraries API is an effort from Google to takes the pain out of staying up to date with these libraries. Google works directly with the key stake holders for each library effort and accepts the latest stable versions. And host them forever.
Developers would just need to use google.load(...) to use the required version of the api.
Friday, July 24, 2009
How to export all tables in a schema without specifying table names
exp utility doesn't have an option to export all tables in a schema. One has to give list of tables which is painful when the schema is huge.
The Data Pump Utility has an option [INCLUDE=TABLE_DATA] to achieve this.
example: expdp username/password dumpfile=username.dmp INCLUDE=TABLE_DATA
The Data Pump Utility has an option [INCLUDE=TABLE_DATA] to achieve this.
example: expdp username/password dumpfile=username.dmp INCLUDE=TABLE_DATA
Subscribe to:
Posts (Atom)