Sunday, October 10, 2010

J2EE Transactions and Attributes

Transaction attributes

 The following are a few notes on J2EE Transactions and Attributes
  • As per spec, deployer should define the transaction attribute.
  • In Weblogic the default transaction attribute is SUPPORTS
  • EJB Transaction is automatically rolled back only when a SystemException (or a subtype of it) is thrown.
  • Your ApplicationException can extend from javax.ejb.EJBException, which is a sub class of RuntimeException.
  • When an EJBException is encountered the container rolls back the transaction.
  • EJB Specification does not mention anything about Application exceptions being sub-classes of EJBException.
  • You can tell container to rollback the transaction, by using setRollBackOnly on SessionContext/EJBContext object as per type of bean you are using.

Transaction Attributes
A transaction attribute may have one of the following values:

    * Required
    * RequiresNew
    * Mandatory
    * NotSupported
    * Supports
    * Never

Required
If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method.

The Required attribute will work for most transactions. Therefore, you may want to use it as a default, at least in the early phases of development. Because transaction attributes are declarative, you can easily change them at a later time.

RequiresNew
If the client is running within a transaction and invokes the enterprise bean's method, the container takes the following steps:

   1. Suspends the client's transaction
   2. Starts a new transaction
   3. Delegates the call to the method
   4. Resumes the client's transaction after the method completes

If the client is not associated with a transaction, the container starts a new transaction before running the method.

You should use the RequiresNew attribute when you want to ensure that the method always runs within a new transaction.

Mandatory
If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container throws the TransactionRequiredException.

Use the Mandatory attribute if the enterprise bean's method must use the transaction of the client.

NotSupported
If the client is running within a transaction and invokes the enterprise bean's method, the container suspends the client's transaction before invoking the method. After the method has completed, the container resumes the client's transaction.

If the client is not associated with a transaction, the container does not start a new transaction before running the method.

Use the NotSupported attribute for methods that don't need transactions. Because transactions involve overhead, this attribute may improve performance.

Supports
If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container does not start a new transaction before running the method.

Because the transactional behavior of the method may vary, you should use the Supports attribute with caution.

Never
If the client is running within a transaction and invokes the enterprise bean's method, the container throws a RemoteException. If the client is not associated with a transaction, the container does not start a new transaction before running the method.

Installing IBM Websphere MQ on Solaris

Websphere MQ Version 6.0.1.0

This post describes the installation and configuration of IBM MQ 6 (6.0.1.0) on Solaris 10 (5.10)

Important

May be installed on a global zone
OR
If installed on a non-global zone, should be installed on a whole root zone(Cannot be installed on a sparse root zone)
Installation to be done as 'root'

Steps to be followed

1. Add the group called 'mqm'
groupadd mqm

2. Add the user 'mqm' - member of group 'mqm'
useradd -g mqm -d /export/home/mqm -m mqm

3. Run the command
project -l
If no project for group 'mqm' exist, use projadd

4. untar the installer(for example C87RWML.tar)
tar -xvf C87RWML.tar

5. Run './mqlicense.sh'
Read the license and accept the same

6. run the following command
pkgadd -d. (including the dot at the end)
This displays the list of all packages
Select the option 'all'

Note: Errors like the following may be ignored
Executing post install scripts
Insufficient privilege error

YOU HAVE SUCCESSFULLY INSTALLED WEBSPHERE MQ

Runs on default port 1414


To start using MQ:

1. Configure Q Manager
crtmqm (Create MQ Manager)
crtmqm HACSTG01

2. Start MQ Manager
strmqm (Start MQ Manager)
strmqm HACSTG01

3. Start MQ Listener
runmqlsr -m HACSTG01 -t TCP &

For many other administrative tasks open the MQ Command Prompt - This is an interactive program
runmqsc HACSTG01

You can create local/ remote/ trans, etc queues using the command 'DEFINE'
DEFINE QLOCAL(IMO.NM.IN)


Using Windows based MQ Explorer to administer MQ

Create an OS user(in the group mqm) with which the explorer will connect - (for example name can be mqadmin)
This should be the same name as the Windows account using which we are running the MQ Explorer.
Create a channel using runmqsc
SRVCON -channeltype
Channel name - SYSTEM.ADMIN.SRVCONN=

Installing and configuring FTP on RHEL - vsftpd

This post explains how to install and run the vsftpd - on Linux
  • Get root in case you are not logged in as root (su - )
  • Try starting vsftpd service

[root@sniff-box ~]# service vsftpd start
vsftpd: unrecognized service

  • If you get this, this means vsftpd is not installed.
  • So install and start. Then test... Note that root would not be given ftp access.

[root@sniff-box ~]# yum install -y vsftpd
Loading "security" plugin
Loading "rhnplugin" plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.0.5-12.el5 set to be updated
filelists.xml.gz 100% |=========================| 2.8 MB 00:00
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
vsftpd x86_64 2.0.5-12.el5 rhel 136 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 136 k
Downloading Packages:
(1/1): vsftpd-2.0.5-12.el 100% |=========================| 136 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: vsftpd ######################### [1/1]
Installed: vsftpd.x86_64 0:2.0.5-12.el5
Complete!

Installation succeeded - So now try starting the FTP service

[root@sniff-box ~]# service vsftpd start
Starting vsftpd for vsftpd: [ OK ]

Great!! The service is ready for connections.
Try logging in - note that root login does not work - for obvious security reasons.

[root@sniff-box ~]# ftp localhost
Connected to localhost.localdomain.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): [root@sniff-box ~]# pwd
/root

The way back machine - history of any website

See the history of websites. The Internet Archive Wayback Machine puts the history of the World Wide Web at your fingertips. The Archive contains over 100 terabytes and 10 billion web pages archived from 1996 to the present.

The link is as below

http://web.archive.org/collections/web.html

GonG - Getting Groovy - 1 - Installing Groovy and Grails

This is a quick reference and packaged version of installing, developing and deploying Groovy on Grails (GonG) application.
Trust me, it is much faster, easier and fun that running JSP, JSF, Spring and Hibernate(We will see how to integrate some of these with GonG).
Statutory Warning You could go through the documentation on the Groovy site as well as the grails site instead of proceeding here.

GROOVY

Download Groovy from http://groovy.codehaus.org/Download
At the time of this writing, the latest version is Groovy 1.7.
Download the Groovy 1.7.5 Download zip: Binary Release

Now Unzip it to your installation location. (Windows users, try not to have a space (" ") in the path - if possible. It is fine even if you have one - in case you cant help it.)

Set GROOVY_HOME environment variable to the Groovy installation location.

I use JDK 1.6 - Please the latest one if you do not have this. Anyway the minimum version required for 1.7.5 is JDK 1.5.

Ensure that you have the JAVA_HOME set to your Java installation.

Double click on the groovyConsole.bat in the bin folder.

You get a GroovyConsole GUI. Type in a few Groovy statements like:
And select Run from the console or do Ctrl+R
-------------------------------------------------------------------
println "Yeah Groovy!!"
// Assign a value to a variable
x=1
// INcrement it
x++
// Print it
println x
//Define a Array/ List
y=[10,20,30,40,50]
// Getting one of the elements and printing the count of elements
println y[4]
println y.size()
//Defining a Map - key value pairs
z=["a":10,"b":11,"c":12]
// One way of getting the value using the key "a"
println z.a
// Adding a new map entry
z["d"]=14
// Retrieving Map Entry
println z["b"]
println z["d"]

// Getting a calendar instance, getting the year out of it and printing it
println Calendar.getInstance().get(Calendar.YEAR)
-------------------------------------------------------------------

For a person with a basic knowledge of programming, the comment lines (ones prefixed with //) is an overkill.
And if you are a Java programmer, you should be falling asleep by now.
Now that is the power of groovy. Hear its name, download it, Unzip it, set a few paths and start coding.
Do not underestimate the power of Groovy.
There are advanced features that I will take you through in the coming posts.

So if Groovy is this easy, what happens when it is combined with Grails.
Check out the next section.

GRAILS

Download Grails from http://www.grails.org/Download
Download the Binary Zip - I have downloaded version 1.3.5 (latest when I am writing this).

Unzip the contents to your installation location. (Windows users, try not to have a space (" ") in the path - if possible. It is fine even if you have one - in case you cant help it.)

Set GRAILS_HOME environment variable that points to the path where you extracted
Now append the %GRAILS_HOME>%\bin to the end of your PATH variable.
Make sure that PATH and GRAILS_HOME variable should be in the same environment variable level. (eg. 'System variables') rather than across environment variable levels (eg. PATH under 'System variables' and GRAILS_HOME under 'User variables' - not like this).

Take a command prompt and type in "grails".
You should get a help message, else fix the path issues.

Thats it!! You are all set to start building applications - Groooovy....

The next post discusses on how how to start building the application.

Friday, November 14, 2008

Perl FTP Test program - Net::FTP - useful for monitoring/ testing

The following is a Perl script that can be used to connect to and list an FTP directory.
This can be extended to accept the paremeters as required - host ip,user password, directory etc.
This also can be run in a loop or from cron to monitor connectivity or to monitor file movements(that is a not so good use!!)

use Net::FTP;
$host = '1x2.1xx.xx.xxx';
$user = 'User';
$pass = 'xxxxxxxxxxx';
$home = '/home/release;
print "Connecting...";
#connect
$ftp = Net::FTP->new($host);
#login
$ftp->login($user,$pass);
print "LoggedIn...";
#slurp
@result = $ftp->ls($home);
print "\nResult...";
for(@result)
{ print "\n";
print $_; }
$ftp->quit;
print "\n...Closed";

Finding lines of text following a text match - awk

Suppose you need to display x lines following a search condition.
For example, display the first 5 lines of trace following an Exception in Tomcat log.

If you are using Solaris/ Linux/ *nix, one way of doing it is to "awk" it.
Get the first five lines after a Keyword named "Exception". Feel free to change the keyword as required.
BEGIN {flag = 0}
/Exception/
{print;
flag = 5;
next}
flag >= 1 {print;
flag--;
next}

Use awk or nawk(if you have a long line - awk has a limitation on line length)
Run it as follows:
nawk -f checkex.awk *
Redirect to a file as follows
nawk -f checkex.awk * > output.txt