Open the file using the JD-GUI utility
http://java.decompiler.free.fr/?q=jdgui
Click on a particular .class file , after this go to the menu option
Navigate -> Go to Line option
If this option is not grayed out then that particular jar file has the debug info included.
To find the line info you can also use the following
javap -l SearchJars
This will display LineNumberTable
LineNumberTable:
line 13: 0
line 14: 16
line 15: 27
If this comes up then that means the debugging info is included in to the class file.
Search This Blog
Friday, December 04, 2009
How do you find whether a Java file is compiled with the debugging info or not
Wednesday, November 11, 2009
Windows Mobile Programming Tips
How to start the Windows Mobile Emulators from the command line.
"C:\Program Files\Microsoft Device Emulator\1.0\DeviceEmulator.exe" "C:\Program Files\Windows Mobile 6 SDK\PocketPC\Deviceemulation\0409\PPC_USA.BIN" /memsize 128 /s "d:\EmulatorState_prof.dess"
"C:\Program Files\Microsoft Device Emulator\1.0\DeviceEmulator.exe" "C:\Program Files\Windows Mobile 6 SDK\Smartphone\Deviceemulation\0409\SP_USA_GSM_QVGA_LS_VR.bin" /memsize 128 /s "d:\EmulatorState_std.dess"
Monday, November 02, 2009
How to use the same server session with the Terminal Server's
1. First try to run the command mstsc /v:fmwbde
(If you are lucky you will be connected to the same session)
2. If you are not able to connect to the same session then run the command mstsc /v:fmwbde /admin
This will connect to the admin server console.
3. Open the terminal service manager and select a particulr session and try to connect to this session.
Monday, October 05, 2009
Deployment Management Links are not working On Weblogic 10. 3.1.0
When trying to access the Deployment Management Links Export and Import are not working with the Weblogic 10.3.1.0 version. This fails with the following error
Either Your Session timed out or you are trying to access a page without logging in.
How ever this works fine on WebLogic 10.3.0.0 version.
There is some change in the functionality due to cross-site scripting vulnerability reasons. Please refer to the Note 866405.1 Applet/Javascript does not have access to JSESSIONID (httponly) cookie for more details on this.
For the Deployment Management Links to work you need to edit the file
C:\oim_server\xellerate\OIMApplications\WLXellerateFull.ear\xlWebApp.war\WEB-INF\weblogic.xml
and add the following entries
<session-descriptor>
<cookie-http-only>false</cookie-http-only>
</session-descriptor>
After the changes the weblogic.xml should look like this ,
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<security-role-assignment>
<role-name>User</role-name>
<principal-name>User</principal-name>
</security-role-assignment>
<jsp-descriptor>
<encoding>UTF-8</encoding>
</jsp-descriptor>
<container-descriptor>
<filter-dispatched-requests-enabled>false</filter-dispatched-requests-enabled>
</container-descriptor>
<session-descriptor>
<cookie-http-only>false</cookie-http-only>
</session-descriptor>
</weblogic-web-app>
Restart the weblogic server after the above changes.
Friday, September 04, 2009
Friday, August 14, 2009
Sorting the files on the drive (USB Drive)
Sony music system in my car reads files in the order they are stored on the flash drive , which is very stupid in my opinion. Ideally it
should read the file in some alphabetical order or based on the last modified date. I found a program call DriveSort which reorganizes the files on a drive so they are in alphabetical order.
Download this program from the location http://www.anerty.net/software/file/DriveSort.php
and open the drive. After this sort the files and save the directory.
Please also refer to this URL for more details on this
Monday, July 27, 2009
Vncviewer clipboard operations like copy/cut+paste suddenly stops on linux
Many times you must have observed that clipboard operations like copy/cut and paste suddenly stops workings with the vncviewer. The main reason for this there is a program called as vncconfig responsible for these clipboard transfers. Some times the program may get closed because of some bug in vnc or some other reasons like you closed that window.
To get those clipboard operations back you need to run the program "vncconfig &".
After this your clipboard actions should work fine with out any problems.
Friday, July 24, 2009
Set up environment for linux to install Oracle Software
// Change sysctl.conf file to add the kernel parmeters
cat >> /etc/sysctl.conf << EOF
#This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
kernel.sem = 256 32000 100 142
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.msgmnb = 65535
kernel.msgmni = 2878
fs.file-max = 206173
EOF
// Persist the sysctl.conf entries
sysctl –p
// Change the ulimit values
cat >> /etc/security/limits.conf << EOF
# Oracle Application Server settings
* soft nofile 2048
* hard nofile 65536
* soft nproc 2047
* hard nproc 16384
EOF
cat >> /etc/pam.d/login << EOF
session required /lib/security/pam_limits.so
EOF
cat >> /etc/profile << EOF
ulimit -u 16384 -n 65536
EOF
#### Oracle requirements for 11gR2 database ########
kernel.sem = 256 32000 100 142
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.msgmnb = 65535
kernel.msgmni = 2878
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=4194304
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048576
fs.aio-max-nr = 1048576
RPMs needed for 11gR2 Database
libaio-devel-0.3.106-3.2.i386.rpm
sysstat-7.0.2-3.SEL5_2.i386.rpm
unixODBC-devel-2.2.11-7.1.i386.rpm
local copy at \\disco1bdeapac\home\oracle\softwares\RPM112DB (oracle/oracle) windows browseable
Saturday, July 18, 2009
How to Use Jmeter to do the LDAP/OID Load Testing
How to use Jmeter to load test Portal Application
1. Download the latest Jmeter version from http://jakarta.apache.org/jmeter/
2. Set the JDK 1.5 or JDK 1.6 in your path and run jmeter.bat batch file
3. Create a Thread Group with the following values
Set the number of Threads to 50 and the Loop Count to 10. This will send 500 requests to the server
4. Under the ThreadGroup create HTTP Cookie Manager with the following values
The CookieManager is required to pass the cookie values across the different page requests. Otherwise Jmeter ignores the cookie value.
In the cookie manager select the Check Bog Clear Cookies each iteration and set the Cookie Policy to Default.
5. Under the Thread group create a Loop Controller
Right Click on the Thread Group and Add Logical Controller –> Loop Controller
6. Under the Loop Controller Add Sampler –> HTTP Request HTTP Client
Set the Server Name as say xxx.xxx.oracle.com and Port as 7784 enter the Path as /portal/page?_pageid=33,1&_dad=portal&_schema=PORTAL&_mode=16 Select the CheckBox “Follow Redirects”
7. Under HTTP Request HTTP Client add the HTTP Authorization Manager
Add the Portal username and password in this example I used orcladmin and welcome1.
8. Add another Portal Page for testing
Under the Loop Controller Add Sampler –> HTTP Request HTTP Client
9. Add another SSO Protected Page for testing
Under the Loop Controller Add Sampler –> HTTP Request HTTP Client
Use the following values shown below
10. This is how the JMeter project looks like after doing the above steps
11. Now run the Jmeter project by Pressing Control+R or the Menu option Control+R
12. Check the access_log file for the requests from the Jmeter load test
Wednesday, June 10, 2009
SSH Setup for RAC
On the incq128ad machine(linux#1)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
/usr/bin/ssh-keygen -t rsa
/usr/bin/ssh-keygen -t dsa
touch ~/.ssh/authorized_keys
On the ipbde machine(linux#2)
mkdir -p ~/.ssh
chmod 700 ~/.ssh
/usr/bin/ssh-keygen -t rsa
/usr/bin/ssh-keygen -t dsa
touch ~/.ssh/authorized_keys
On the incq128ad machine(linux#1)
ssh incq128ad cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh incq128ad cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
ssh ipbde cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh ipbde cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys ipbde:.ssh/authorized_keys
On the incq128ad machine(linux#1)
cd $HOME
chmod 755 .
chmod 700 .ssh
cd $HOME/.ssh
chmod 600 authorized_keys
On the ipbde machine(linux#2)
cd $HOME
chmod 755 .
chmod 700 .ssh
cd $HOME/.ssh
chmod 600 authorized_keys
On both the machines run the following
ssh incq128ad hostname
ssh ipbde hostname
Wednesday, May 13, 2009
How to read a SSO protected page
You can use wget to get the SSO protected page using the following command
wget --debug --http-user=oc4jadmin --http-password=welcome1 -O dd.txt http://xxx.xxx.oracle.com:7777/private/dd.txt"
You can use the following code to get the SSO protected page. Download the following jar files
commons-logging.jar , httpcore-4.0.jar , commons-codec-1.3.jar , httpclient-4.0-beta2.jar and
httpmime-4.0-beta2.jar
Run the java program with the following options
d:\jdev10gmin\jdk\bin\javaw.exe -client -classpath D:\jdev10gmin\jdev\mywork\Testing\HTTPClient\classes;E:\ias10134\webservices\lib\commons-logging.jar;D:\httpcomponents-core-4.0\lib\httpcore-4.0.jar;D:\commons-codec-1.3\commons-codec-1.3.jar;D:\httpcomponents-client-4.0-beta2\lib\httpclient-4.0-beta2.jar;D:\httpcomponents-client-4.0-beta2\lib\httpmime-4.0-beta2.jar httpclient.ClientAuthentication1
package httpclient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* A simple example that uses HttpClient to execute an HTTP request against
* a target site that requires user authentication.
*/
public class ClientAuthentication1 {
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("xxx.xxx.oracle.com", 7777),
new UsernamePasswordCredentials("orcladmin", "welcome1"));
HttpGet httpget = new HttpGet("http://xxx.xxx.oracle.com:7777/private/dd.txt");
System.out.println("executing request \n" + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
System.out.println("None");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("- " + cookies.get(i).toString());
}
}
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
InputStream in = entity.getContent();
InputStreamReader inputstreamreader =
new InputStreamReader(in);
BufferedReader bufferedreader =
new BufferedReader(inputstreamreader);
System.out.println("--------- URL Contents -----------------");
String line;
while ((line = bufferedreader.readLine())
!= null) {
System.out.println(line);
}
bufferedreader.close();
inputstreamreader.close();
in.close();
System.out.println("----------------------------------------");
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
entity.consumeContent();
}
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
Monday, April 13, 2009
How to move the domains across the machines in WebLogic
I have a domain with the name test_domain on my Windows machine , here I have one managed server with some applications deployed.
I would like to move this domain from this machine to the other machine.
On Windows machine use the command pack.cmd to create the domain template
pack.cmd -domain=E:\bea\user_projects\domains\test_domain -template=C:\bea\user_templates\test_domain.jar -template_name="My WebLogic Test Domain"
Now move the test_domain.jar to the linux machine.
On the linux machine run the unpack.sh command to create the domain
unpack.sh -template=/home/ias/test_domain.jar -domain=/home/ias/bea/user_projects/domains/test_domain
After this go to the directory and run the command ,
cd /home/ias/bea/user_projects/domains/test_domain/bin
startWebLogic.sh
startManagedWebLogic.sh test http://localhost:7001
How to print the folder list that are available on a USB Drive
I am using the Sony MP3 player that can play from a USB drive, I have a difficulty in printing the folder list that are sorted on a last modifed date. This is how I generated the list
1. Use the program filelist ,
Download this from http://www.jam-software.com/filelist/filelist_readme_en.txt
2. filelist g:\ > dd.txt
3. type dd.txt | cut --delimiter=, --fields=2 > dd1.txt
4. After this generate the line numbers
type dd1.txt | uniq | nl > dd2.txt
3. Remove the characters like g:\ and “ etc
5. Now open the file in Excel or Word and Print the file
Monday, April 06, 2009
Wednesday, March 25, 2009
My OWSM Notes
1. The login username password is : admin/oracle
The URL is http://localhost:7779/ccore/
UN/PW : admin/oracle
2. The log file's you can find under the directory
E:\soa\j2ee\oc4j_soa\log
The important log file is "ccore.log"
3. For the OWSM Log levels check the note
Note 726219.1 How To Change Log Level for Oracle Web Services Manager (OWSM) ?
4. How to install OWSM on Windows/Unix
First run the irca.bat or irca.sh on the existing database
E:\10.1.3.1.0\install\soa_schemas\irca
For the upgrade you need to run upgrade_10131_10134_oracle.sql in the orabpel schema
and run the script upgrade_10133_10134_oracle.sql in oraesb schema.
Thursday, March 19, 2009
Printing Problems from IE7
I was having the small font problem printing from in IE7
Please see KB article http://support.microsoft.com/kb/932538/en-us
Scroll down to the section "More Information" edit registry as specified. But you manually have to add the key. It worked for me without installing any hotfix.
Or;
Copy paste and save the following text to a .reg file and run it.
---
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_STF_Scale_Min]
"iexplore.exe"=dword:00000064
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_STF_Scale_Min]
"outlook.exe"=dword:00000064
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_STF_Scale_Min]
"WinMail.exe"=dword:00000064
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_STF_Scale_Min]
"Msimn.exe"=dword:00000064
Wednesday, March 11, 2009
How to Configure network card (Nvidia Palit MB ) on Linux
1. Download version 1.25 of Linux nForce Drivers (http://www.nvidia.com/object/linux_nforce_archive.html) from archive (I don't know why they have version 1.23 in Unix drivers page)
2. Unzip and install RPM for RHEL5_U1
3. Copy and replace forcedeth.ko from /lib/modules/2.6.18-53.el5/kernel/drivers/net to /lib/modules/2.6.18-92.1.18.el5/kernel/drivers/net/ (make a backup just in case)
4. Add the following lines to /etc/modprobe.conf (replace eth0 for whatever is yours)
alias eth0 forcedeth
options forcedeth msi=0 msix=0 dma_64bit=0
5. Remove module if loaded
rmmod forcedeth
6. Install module
insmod /lib/modules/2.6.18-92.1.18.el5/kernel/drivers/net/forcedeth.ko msi=0 msix=0 dma_64bit=0
(you may reboot as well but this is faster for testing)
you should get something like this by dmesg
eth0: forcedeth.c: subsystem: 01019:2145 bound to 0000:00:0f.0
7. Configure ifcfg-eth0 (or whatever)
TYPE=Ethernet
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:XX:XX:XX:XX:XX
If you don't know your MAC then forget about that line and do ifconfig eth0 up
Thursday, February 19, 2009
How to Find out whether you are using 64 bit JDK or 32 bit JDK
Write this sample java program
import java.util.Enumeration;
import java.util.Properties;
public class Class1 {
public Class1() {
}
public static void main(String[] args) {
Class1 class1 = new Class1();
Properties p = System.getProperties();
Enumeration keys = p.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
String value = (String)p.get(key);
System.out.println(key + ": " + value);
}
}
}
Run the program
and check for the propert sun.arch.data.model if this shows 32 then you are running in a 32 bit JVM. If this shows 64 bit then you are in 64 bit JVM.
For the 64 bit you run the java using the following option $ORACLE_HOME/jdk/bin/java –d64
This shows sun.arch.data.model: 64
Resolving ClassNotFound Exceptions
When you are running a Java program or compiling a java program you got a class not found error, going through all the JAR files for finding this particular class file is quite tedious.
The program given below can help you to search inside the jar and/or zip files and tells you whether the file you are looking for is present or not.
Code Example
Below you will find the code example, how you use it and what result you can expect out of it.
SearchJars.java
package mypackage7;
import java.util.zip.*;
import java.io.*;
import java.util.*;
public class SearchJars {
static String s3;
static String s4 ="";
static int i1 = 0;
static int i2 = 0;
public static void main(String args[]) {
if (args.length != 2) throw new IllegalArgumentException("Wrong Number of Args !! java SearchJars Direcory_Name filename ");
File f1 = new File(args[0]);
s3 = args[1];
traverse(f1);
System.out.println("\n\n============== Results ============================");
System.out.println("Searced "+ i1 +" Files in "+ args[0] +" And Found "+i2 +" Entries. ");
System.out.println(s4);
}
public static void traverse(File f) {
String s1 = f.getAbsolutePath();
if (s1.toUpperCase().indexOf(".JAR") != -1 || s1.toUpperCase().indexOf(".ZIP") != -1 ) {
System.out.println("Searching "+ s1 +" .....");
i1++;
try {
ZipFile zf = new ZipFile(s1);
for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
String s2 = ((ZipEntry)entries.nextElement()).getName();
if (s2.indexOf(s3) != -1 ) {
System.out.println("Found "+s2 + " In " +s1);
i2++;
s4 = s4 + "Found "+s2 + " In " +s1 + "\n";
}
}
} catch (IOException e) {}
}
if (f.isDirectory()) {
String[] children = f.list();
for (int i=0; i<children.length; i++) {
traverse(new File(f, children[i]));
}
}
}
}
Program Usage
java.exe mypackage7.SearchJars D:\oracle\jdev1012\BC4J\jlib DateConvertor
Program Output
Searching D:\oracle\jdev1012\BC4J\jlib\adfjclient.jar .....
Found oracle/jbo/uicli/jui/DateConvertor.class In D:\oracle\jdev1012\BC4J\jlib\adfjclient.jar
Searching D:\oracle\jdev1012\BC4J\jlib\adfmejb.jar .....
Searching D:\oracle\jdev1012\BC4J\jlib\adftags.jar .....
Searching D:\oracle\jdev1012\BC4J\jlib\bc4jdatum.jar .....
============== Results ============================
Searced 4 Files in D:\oracle\jdev1012\BC4J\jlib And Found 1 Entries.
Found oracle/jbo/uicli/jui/DateConvertor.class In D:\oracle\jdev1012\BC4J\jlib\adfjclient.jar
Wednesday, February 18, 2009
Best Freeware Software
For the Folder Sizes http://www.jam-software.com/freeware/index.shtml (TreeSize Free)
For the English Dictionary WORDWEB FREE* VERSION http://wordweb.info/free/
Take a backup of the original DVD’s DVD Shrink http://www.dvdshrink.org/
Best Java Decompiler JD-Gui http://java.decompiler.free.fr/
Ftp Utility FileZilla http://filezilla-project.org/
Free RAR/Unzip utility http://www.tugzip.com/
File Editor NotePad Plus http://notepad-plus.sourceforge.net/uk/site.htm
Free Download Manager http://www.freedownloadmanager.org/
Ipod Backup Utlity
http://www.getsharepod.comCPU Information CPU-Z
Friday, February 13, 2009
How to Send/Browse Messages to AQ via OC4J in a Standalone Java program
Set up your queues and AQ resource adapter etc using the following article.
http://rreddy.blogspot.com/2009/02/how-to-use-simple-mdb-with-oracle.html
The only difference with the Servlet and the standalone code with the connection factories and the queues JNDI lookup’s.
<resource-ref-mapping location="TEST_AQ/QueueCF" name="CommonConnectionFactory">
For the standalone java program we use the ConnectionFactory as java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF
This can be found from the file oc4j-ra.xml file
For the queue we use the JNDI location for the Queue as
<message-destination-ref-mapping name="TestQueue" location="TEST_AQ/MyQueue/Queues/MYQUEUE" />
But for the standalone java client we use the java:comp/resource/TEST_AQ/Queues/MYQUEUE
Example to Send a Message to JMS
package mdbaq;
import java.io.*;
import java.net.URL;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.jms.* ;
import javax.jms.Queue;
import javax.naming.*;
public class SendJMS {
public SendJMS() {
}
public static void main(String[] args) {
SendJMS sendJMS = new SendJMS();
Queue queue=null;
QueueSession queueSession=null;
QueueSender queueSender=null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
try {
Hashtable env = new Hashtable();
// Standalone OC4J connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
env.put(Context.PROVIDER_URL, "ormi://localhost:23791");
jndiContext = new InitialContext(env);
} catch (NamingException e)
{ System.out.println("Exception occurred: " + e.toString()); }
try {
// queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("jms/qcf");
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF");
// queue = (Queue)jndiContext.lookup("jms/demoQueue");
queue = (Queue)jndiContext.lookup("java:comp/resource/TEST_AQ/Queues/MYQUEUE");
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession= queueConnection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
queueConnection.start();
} catch (Exception e) {
System.out.println("Exception occurred: " + e.toString());
e.printStackTrace();
}
try {
TextMessage message = queueSession.createTextMessage();
message.setText("Test "+new Date());
queueSender.send(message);
queueSession.commit();
} catch (JMSException e) {
System.out.println("Exception occurred: " +e.toString());
e.printStackTrace();
}
System.out.println( " Message Sent .....");
}
}
Example For Browsing the message
package mdbaq;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.QueueSession;
import javax.jms.QueueBrowser;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.TextMessage;
import javax.naming.Context;
public class Browser
{
public static void main(String[] args) throws Exception
{
// get the initial context
Hashtable env = new Hashtable();
// Standalone OC4J connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin");
env.put(Context.SECURITY_CREDENTIALS, "welcome1");
env.put(Context.PROVIDER_URL, "ormi://localhost:23791");
InitialContext ctx = new InitialContext(env);
// lookup the queue object
// Queue queue = (Queue) ctx.lookup("jms/demoQueue");
Queue queue = (Queue) ctx.lookup("java:comp/resource/TEST_AQ/Queues/MYQUEUE");
// lookup the queue connection factory
QueueConnectionFactory connFactory =
//(QueueConnectionFactory) ctx.lookup("jms/qcf");
// (QueueConnectionFactory) ctx.lookup("java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF");
(QueueConnectionFactory) ctx.lookup("java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF");
// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();
// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// create a queue browser
QueueBrowser queueBrowser = queueSession.createBrowser(queue);
// start the connection
queueConn.start();
// browse the messages
Enumeration e = queueBrowser.getEnumeration();
int numMsgs = 0;
// count number of messages
while (e.hasMoreElements()) {
Message message = (Message) e.nextElement();
TextMessage msg = (TextMessage) message;
System.out.println(msg.getText());
numMsgs++;
}
System.out.println(queue + " has " + numMsgs + " messages");
// close the queue connection
queueConn.close();
}
}
Run the Java program using the following option
java -classpath D:\MDB-AQ\classes;D:\temp2\jms.jar;D:\temp2\jta.jar;D:\temp2\pcl.jar;D:\temp2\aqapi13.jar;D:\temp2\ojdbc14.jar;D:\temp2\connector.jar;D:\temp2\jazncore.jar; D:\temp2\dms.jar;D:\temp2\bcel.jar;D:\temp2\mail.jar;D:\temp2\oc4j-internal.jar;D:\temp2\oc4jclient.jar;D:\temp2\adminclient.jar mdbaq.Browser
How to view AQ Queues via OC4J with the hermes tool
For the OC4J memory based JMS queues you can use the link below.
Hermes Configuration for OC4J memory based JMS
This article explains how to view AQ based queues with hermes.
Set up your queues and AQ resource adapter etc using the following article.
http://rreddy.blogspot.com/2009/02/how-to-use-simple-mdb-with-oracle.html
From an OC4J install copy all these files to a temp directory
adminclient.jar
aqapi13.jar
bcel.jar
connector.jar
dms.jar
javax77.jar
jazncore.jar
jms.jar
jndi.jar
jta.jar
oc4j-internal.jar
oc4jclient.jar
ojdbc14.jar
optic.jar
pcl.jar
From the Hermes Tool create a classpath using the following ,
<classpathGroup id="ORACLE-SOA">
<library jar="D:\TEMP\aqapi13.jar" noFactories="true"/>
<library jar="D:\TEMP\jms.jar" noFactories="true"/>
<library jar="D:\TEMP\optic.jar" noFactories="true"/>
<library jar="D:\TEMP\jta.jar" noFactories="true"/>
<library jar="D:\TEMP\oc4jclient.jar" noFactories="true"/>
<library jar="D:\TEMP\ojdbc14.jar" noFactories="true"/>
<library jar="D:\TEMP\bcel.jar" noFactories="true"/>
<library jar="D:\TEMP\connector.jar" noFactories="true"/>
<library jar="D:\TEMP\adminclient.jar" noFactories="true"/>
<library jar="D:\TEMP\oc4j-internal.jar" noFactories="true"/>
<library jar="D:\TEMP\dms.jar" noFactories="true"/>
<library jar="D:\TEMP\jazncore.jar" noFactories="true"/>
<library jar="D:\TEMP\pcl.jar" noFactories="true"/>
</classpathGroup>
Create a session using the following entries
<factory classpathId="ORACLE-SOA">
<provider className="hermes.JNDIQueueConnectionFactory">
<properties>
<property name="binding" value="java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF"/>
<property name="initialContextFactory" value="oracle.j2ee.rmi.RMIInitialContextFactory"/>
<property name="providerURL" value="ormi://localhost:23791"/>
<property name="securityCredentials" value="welcome1"/>
<property name="securityPrincipal" value="oc4jadmin"/>
</properties>
</provider>
<connection clientID="" connectionPerThread="false">
<session audit="false" id="OEMS" reconnects="0" transacted="true" useConsumerForQueueBrowse="false"/>
</connection>
<destination domain="1" name="java:comp/resource/TEST_AQ/Queues/MYQUEUE"/>
<extension className="hermes.ext.DefaultHermesAdminFactory">
<properties/>
</extension>
</factory>
The important entries are
binding ==>> java:comp/resource/TEST_AQ/QueueConnectionFactories/QueueCF
This can be found from the file oc4j-ra.xml file \
<connector-factory location="TEST_AQ/QueueCF" connector-name="TEST_AQ">
<config-property name="jndiLocation" value="QueueConnectionFactories/QCF"/>
For the MDB we use the ConnectionFactory as TEST_AQ/QueueCF but for the hemes tool we need to use this as QueueConnectionFactories/QCF.
destination domain==> java:comp/resource/TEST_AQ/Queues/MYQUEUE For the MDB we use this as TEST_AQ/MyQueue/Queues/MYQUEUE but for the hermes tool we need use TEST_AQ/Queues/MYQUEUE.
After this send a message to the AQ using the script
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
Message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
Message := Sys.Aq$_Jms_Text_Message.Construct;
Message.Set_Text(to_char(sysdate, 'DD/MM/YYYY HH24:MI:SS'));
dbms_aq.enqueue(queue_name => 'MYQUEUE',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
Wednesday, February 04, 2009
How to Get the HTTP request and responses with OC4J/OAS
For the Stand alone oc4j use the following
java -Doracle.oc4j.trace.finest=com.evermind.server.http -Dhttp.request.debug=true -jar oc4j.jar
09/02/05 12:58:22 FINE: EvermindHttpServletRequest.init GET /j2ee/test.jsp HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, applicat
ion/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/xaml+xml, applicati
on/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverligh
t, */*
Accept-Language: en-us
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Wi
ndows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; FDM; .NET CLR 3.0
.04506.648; .NET CLR 3.5.21022)
Host: xxx.xx.oracle.com:8888
Connection: Keep-Alive
Cookie: JSESSIONID=2009-02-05 12:58:22.734 NOTIFICATION J2EE JSP-0008 Unable to dispatch JSP Page : Exception:java.io.
FileNotFoundException: C:\oc4j10134\j2ee\home\default-web-app\j2ee\test.jsp (The system cannot find
the path specified)
09/02/05 12:58:22 FINEST: EvermindHttpServletResponse.commit *********** RESPONSE ************
09/02/05 12:58:22 FINEST: EvermindHttpServletResponse.commit HTTP/1.1 404 Not Found
Date: Thu, 05 Feb 2009 07:28:22 GMT
Server: Oracle Containers for J2EE
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
09/02/05 12:58:22 FINEST: EvermindHttpServletResponse.commit *********** RESPONSE DONE ************
For the OAS add the following in the opmn.xml file
-Doracle.oc4j.trace.finest=com.evermind.server.http -Dajp.debug=true -Dhttp.request.debug=true
How to use mod_security module with HTTP Server to check the request and response headers
You can also use mod_security module to check the requests and responses.
Add the following at the end of the httpd.conf
On linux
LoadModule security_module libexec/mod_security.so
On Windows
LoadModule security_module modules/ApacheModuleSecurity.dll
AddModule mod_security.c
<IfModule mod_security.c>
# Turn the filtering engine On or Off
SecFilterEngine On
# Make sure that URL encoding is valid
SecFilterCheckURLEncoding On
# Unicode encoding check
SecFilterCheckUnicodeEncoding Off
# Only allow bytes from this range
SecFilterForceByteRange 0 255
# Only log suspicious requests
SecAuditEngine On
# The name of the audit log file
SecAuditLog logs/audit_log
# Debug level set to a minimum
SecFilterDebugLog logs/modsec_debug_log
SecFilterDebugLevel 0
</IfModule>
and restart the HTTP Server.
Now check the audit_log file in $ORACLE_HOME/Apache/Apache/log directory.
========================================
UNIQUE_ID: Qw2LjJhFqD0AABvSLj8
Request: 152.69.168.191 - - [25/Aug/2005:14:42:57 +0530] "GET
/test_opencursor/Controller?recordID=2&counter=1 HTTP/1.1" 200 5
Handler: oc4j-handler
----------------------------------------
GET /test_opencursor/Controller?recordID=2&counter=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us
Connection: keep-alive
Host: localhost
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Oracle-ECID: 1124961164:152.69.168.61:7122:0:1,0
HTTP/1.1 200 OK
Set-Cookie:
JSESSIONID=9845a83dce5dad8a271451048cb9a5fc0cb23f83960.e3uMb3eObheLe34SchaNaNu
Na41ynknvrkLOlQzNp65In0; Path=/test_opencursor
Cache-Control: private
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/octet-stream
========================================
This gives the request and response.
Tuesday, February 03, 2009
How to use a Simple MDB with Oracle Database provider in 10. 1.3
1. Create the following entries in the data-sources.xml file
<managed-data-source connection-pool-name="AQ Connection Pool"
jndi-name="jdbc/aq"
name="AQ Connection Pool"/>
<connection-pool name="AQ Connection Pool">
<connection-factory
factory-class="oracle.jdbc.pool.OracleDataSource"
user="jmsuser" password="jmsuser"
url="jdbc:oracle:thin:@incq128ad:1521:ias1012"/>
</connection-pool>
2. Login to sql*plus and create the AQ objects
CONNECT system/manager;
DROP USER jmsuser CASCADE ;
GRANT CONNECT, RESOURCE,AQ_ADMINISTRATOR_ROLE TO jmsuser IDENTIFIED BY jmsuser ;
CONNECT jmsuser/jmsuser;
BEGIN
dbms_aqadm.create_queue_table ( queue_table=> 'TEST', queue_payload_type=> 'SYS.AQ$_JMS_TEXT_MESSAGE', sort_list=> '', comment=> '', multiple_consumers=> FALSE, message_grouping=> DBMS_AQADM.NONE, non_repudiation => DBMS_AQADM.NONE, storage_clause=> '', compatible=> '8.1', primary_instance=> '0', secondary_instance=> '0');
COMMIT;
END;
BEGIN
dbms_aqadm.create_queue(queue_name=> 'MYQUEUE', queue_table=> 'TEST', queue_type=> DBMS_AQADM.NORMAL_QUEUE, max_retries=> '5', retry_delay=> '0', retention_time=> '0', comment=> '');
COMMIT;
END;
BEGIN
dbms_aqadm.start_queue('JMSUSER.MYQUEUE', TRUE, TRUE);
COMMIT;
END;
3. Test whether the enqueing and dequing is working fine or not
Open a sqlplus window and login as jmsuser and run the following sql.
enque.sql
---------
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
Message SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
Message := Sys.Aq$_Jms_Text_Message.Construct;
Message.Set_Text(to_char(sysdate, 'DD/MM/YYYY HH24:MI:SS'));
dbms_aq.enqueue(queue_name => 'MYQUEUE',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
Open another sqlplus window and login as jmsuser and run the following sql.
deque.sql
---------
set serveroutput on;
declare
deqopt dbms_aq.dequeue_options_t;
mprop dbms_aq.message_properties_t;
msgid RAW(16);
payload SYS.AQ$_JMS_TEXT_MESSAGE;
begin
deqopt.navigation := DBMS_AQ.FIRST_MESSAGE;
--deqopt.wait := 1;
dbms_aq.dequeue(
queue_name => 'MYQUEUE',
dequeue_options => deqopt,
message_properties => mprop,
payload => payload,
msgid => msgid );
commit;
dbms_output.put_line('The Message Sent to the Queue is: ' || payload.TEXT_VC);
end;
Now you should see the message in the sql*plus window as
The Message Sent to the Queue is: 13/03/2008 17:48:34
4. Start the oc4j container and access the EM Application Server Control
Go to the Administration TAB
Click on the Database Persistence link.
5. In this screen click on the deploy Button
Give the "Resource Adapter Module Name" as : TEST_AQ
And select the Radio Button
"Add a new resource provider to be used by this connector" Give the "Resource Provider Name" as TEST_AQ and
select the "Datasource JNDI Location" as jdbc/aq.
This will add the following values to the application.xml file
<resource-provider name="TEST_AQ" class="oracle.jms.OjmsContext">
<description></description>
<property name="datasource" value="jdbc/aq" />
</resource-provider>
Restart the oc4j container after this.
6. Now click on this Resource Adapter
and select the TAB
Connection Factory and select the QueueConnectionFactory
TEST_AQ/QueueCF
7. Now Click On "Administrated Objects" TAB and enter the following value
Choose the ObjectClass as oracle.j2ee.ra.jms.generic.AdminObjectQueueImpl
Give the JNDI Location as TEST_AQ/MyQueue and resourceProviderName as
TEST_AQ.
Software Requirements/Prerequisites
8. From the JDeveloper Create a Message driven and change the OnMessage Methodpackage mdbaq;
import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
public class MessageDrivenEJBBean implements MessageDrivenBean,
MessageListener {
private MessageDrivenContext _context;
public void ejbCreate() {
}
public void setMessageDrivenContext(MessageDrivenContext context) throws EJBException {
_context = context;
}
public void ejbRemove() throws EJBException {
}
public void onMessage(Message message)
{
System.out.println("Received message: " + message);
TextMessage msg = null;
try {
if (message instanceof TextMessage) {
msg = (TextMessage) message;
System.out.println("MESSAGE BEAN: Message received: "
+ msg.getText());
} else {
System.out.println("Message of wrong type: "
+ message.getClass().getName());
}
} catch (JMSException e) {
e.printStackTrace();
} catch (Throwable te) {
te.printStackTrace();
}
}
}
9. Open the ejb-jar.xml and have the following entries
<?xml version = '1.0' encoding = 'windows-1252'?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee">
<enterprise-beans>
<message-driven>
<description>Message Driven Bean</description>
<display-name>MessageDrivenEJB</display-name>
<ejb-name>MessageDrivenEJB</ejb-name>
<ejb-class>mdbaq.MessageDrivenEJBBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<message-destination-type>
javax.jms.Queue
</message-destination-type>
</message-driven>
</enterprise-beans>
<assembly-descriptor/>
</ejb-jar>
Open the orion-ejb-jar.xml file
<?xml version = '1.0' encoding = 'windows-1252'?>
<orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" schema-major-version="10" schema-minor-version="0">
<enterprise-beans>
<message-driven-deployment name="MessageDrivenEJB"
connection-factory-location="TEST_AQ/QueueCF"
destination-location="TEST_AQ/MyQueue/Queues/MYQUEUE"/>
</enterprise-beans>
</orion-ejb-jar>
11. Create a simple Servlet to send the message to the Queue
package mdbaq;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.jms.* ;
import javax.jms.Queue;
import javax.naming.*;
import java.util.* ;
public class HelloWorld extends HttpServlet {
Queue queue;
QueueSession queueSession;
QueueSender queueSender;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello MDB </TITLE></HEAD>");
out.println("<BODY>");
try {
TextMessage message = queueSession.createTextMessage();
message.setText(req.getParameter("subject"));
queueSender.send(message);
queueSession.commit();
} catch (JMSException e) { System.out.println("Exception occurred: " +e.toString());}
out.println("<H3> " + req.getParameter("subject") +" Message Sent .....</H3>");
out.println("</BODY></HTML>");
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try {
jndiContext = new InitialContext();
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("CommonConnectionFactory");
queue = (Queue)jndiContext.lookup("TestQueue");
} catch (NamingException e)
{ System.out.println("Exception occurred: " + e.toString()); }
try {
queueConnection = queueConnectionFactory.createQueueConnection("jmsuser","jmsuser");
queueSession= queueConnection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
queueConnection.start();
} catch (JMSException e) {System.out.println("Exception occurred: " + e.toString());}
}
}
12. The web.xml
Add the following entries to the web.xml file
<resource-ref>
<res-ref-name>CommonConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<message-destination-ref>
<description></description>
<message-destination-ref-name>TestQueue</message-destination-ref-name>
<message-destination-type>javax.jms.Queue</message-destination-type>
<message-destination-usage>Produces</message-destination-usage>
<message-destination-link>TestQueue</message-destination-link>
</message-destination-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<?xml version="1.0"?>
<orion-web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-web-10_0.xsd" deployment-version="10.1.3.3.0"
deployment-time="1205407531953"
jsp-cache-directory="./persistence"
jsp-cache-tlds="standard"
temporary-directory="./temp"
servlet-webdir="/servlet/"
context-root="/aq"
schema-major-version="10" schema-minor-version="0" >
<resource-ref-mapping location="TEST_AQ/QueueCF" name="CommonConnectionFactory">
</resource-ref-mapping>
<message-destination-ref-mapping name="TestQueue" location="TEST_AQ/MyQueue/Queues/MYQUEUE" />
<web-app>
</web-app>
</orion-web-app>
14. Create a simple index.html to invoke the Servlet that sends the message to the AQ.
<html>
<head>
</head>
<body>
<form action="helloworld">
<b>Subject: </b><input type="text" name="subject"><br>
<input type="submit" value="Log">
</form>
</body>
</html>
Configuring the Sample Code
use Jdeveloper to open the project
Running the Sample Code
Run the URL http://xxx.xx.oracle.com:8888/aq/helloworld?subject=test123
Sample Code Output
08/03/13 18:50:44 Received message: oracle.j2ee.ra.jms.generic.TextMessageWrapper@bb5e2d
08/03/13 18:50:44 MESSAGE BEAN: Message received: test123
Sunday, February 01, 2009
Tuesday, January 20, 2009
Unix/Windows Scripts to Run a Task for "n" number of times
Windows Script
test.bat
FOR /L %%G IN (1,1,20) DO (
echo Ruuning ---> %%G Time
java -jar admin_client.jar deployer:oc4j:opmn://xxx.xx.oracle.com:37005/IAM01 oc4jadmin manager1 -undeploy IAM
java -jar admin_client.jar deployer:oc4j:opmn://xx.xx.oracle.com:37005/IAM01 oc4jadmin manager1 -deploy -file D:\bugs-download\Bug7252754\iam.ear -deploymentName IAM -bindAllWebApps
)
Unix Script
#!/bin/ksh
num=6
while [ $num -lt 20 ]
echo =========== Running for $num on `date` =============
do
opmnctl shutdown
opmnctl startall
opmnctl status
/refresh/jwc1013/product/jwc1013/jdk/bin/java -jar $ORACLE_HOME/j2ee/home/admin_client.jar deployer:oc4j:opmn://xx.xx.oracle.com:35005/IAM oc4jadmin manager1 -undeploy IAM
/refresh/jwc1013/product/jwc1013/jdk/bin/java -jar $ORACLE_HOME/j2ee/home/admin_client.jar deployer:oc4j:opmn://xx.xx.oracle.com:35005/IAM oc4jadmin manager1 -deploy -file $ORACLE_HOME/j2ee/home/iam2.ear -deploymentName IAM -bindAllWebApps
let num+=1
done
Script which runs a task 100 times and after every 5 iterations it will restart the oc4j conatiner.
#!/bin/ksh
num=0
while [ $num -lt 100 ]
do
echo =========== Running for $num on `date` =============
i1=$(expr $num % 5)
if [ $i1 -lt 1 ] ;
then
echo ======== Starting and Stopping OAS ===========
/home/ias/ias10131/opmn/bin/opmnctl shutdown
/home/ias/ias10131/opmn/bin/opmnctl startall
fi
/home/ias/ias10131/jdk/bin/java -jar $ORACLE_HOME/j2ee/home/admin_client.jar deployer:oc4j:opmn://xx.xx.oracle.com:6005/IAM oc4jadmin welcome1 -undeploy IAM
/home/ias/ias10131/jdk/bin/java -jar $ORACLE_HOME/j2ee/home/admin_client.jar deployer:oc4j:opmn://xx.xx.oracle.com:6005/IAM oc4jadmin welcome1 -deploy -file /home/ias/ias10131/iam.ear -deploymentName IAM -bindAllWebApps
let num+=1
done
Thursday, January 15, 2009
Using jdb with OC4J
For example take this JSP Code (test.jsp)
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="javax.sql.*" %>
<%@page import="javax.naming.*" %>
<%@page import="oracle.jdbc.pool.*" %>
<HTML>
<HEAD>
<TITLE>JSP Example</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffcc">
<CENTER>
<%
try {
String p1=null;
out.println(p1.indexOf("123"));
}
catch (Exception e1)
{
System.out.println(e1.toString());
}
%>
</CENTER>
</BODY>
</HTML>
When you run this program this only prints 09/01/15 17:58:15 java.lang.NullPointerException
and you have no idea from where this exception is coming from.
You can use JDB to find out from where this exception is coming from
Run the OC4J with the following option
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=10444 -jar oc4j.jar
Now open another command prompt
run the jdb command with the following option
jdb -connect com.sun.jdi.SocketAttach:port=10444
At the jdb prompt enter the follwoing command
catch java.lang.NullPointerException
Now run your Application , when the NPE exception comes up the jdb displays the following info
Exception occurred: java.lang.NullPointerException (to be caught at: _t1._jspService(), line=58 bci=144)"thread=HTTPThreadGroup-8", _t1._jspService(), line=56 bci=135
HTTPThreadGroup-8[1]
Now type the command
where
to get the stack that is causing this problem
This will display the following stack
HTTPThreadGroup-8[1]HTTPThreadGroup-8[1] where [1] _t1._jspService (_t1.java:56) [2] com.orionserver.http.OrionHttpJspPage.service (OrionHttpJspPage.java:59) [3] oracle.jsp.runtimev2.JspPageTable.service (JspPageTable.java:462) [4] oracle.jsp.runtimev2.JspServlet.internalService (JspServlet.java:594) [5] oracle.jsp.runtimev2.JspServlet.service (JspServlet.java:518) [6] javax.servlet.http.HttpServlet.service (HttpServlet.java:856) [7] com.evermind.server.http.ServletRequestDispatcher.invoke (ServletRequestDispatcher.java:713) [8] com.evermind.server.http.ServletRequestDispatcher.forwardInternal (ServletRequestDispatcher.java:370) [9] com.evermind.server.http.HttpRequestHandler.doProcessRequest (HttpRequestHandler.java:871) [10] com.evermind.server.http.HttpRequestHandler.processRequest (HttpRequestHandler.java:453) [11] com.evermind.server.http.HttpRequestHandler.serveOneRequest (HttpRequestHandler.java:221) [12] com.evermind.server.http.HttpRequestHandler.run (HttpRequestHandler.java:122) [13] com.evermind.server.http.HttpRequestHandler.run (HttpRequestHandler.java:111) [14] oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run (ServerSocketReadHandler.java:260) [15] oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket (ServerSocketAcceptHandler.java:239) [16] oracle.oc4j.network.ServerSocketAcceptHandler.access$700 (ServerSocketAcceptHandler.java:34) [17] oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run (ServerSocketAcceptHandler.java:880) [18] com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run (ReleasableResourcePooledExecutor.java:303) [19] java.lang.Thread.run (Thread.java:595)HTTPThreadGroup-8[1]
Now we know that we got the exception from t1.jsp.
After this run the command
run to proceede further.
Wednesday, January 14, 2009
How to run a Simple JMX-Groovy Example with OC4J
Software Requirements/Prerequisites
Download groovy software from http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.6.zip
Extract this to a directory say D:\groovy-1.5.6
Configuring the Sample Code
Make sure following startup options are set when either starting the OC4J standalone or the Oracle Application Server:
com.sun.management.jmxremote
com.sun.management.jmxremote.port=9004
com.sun.management.jmxremote.authenticate=false
com.sun.management.jmxremote.ssl=false
If you are using OAS , then please set these parameters in the configuration file $ORACLE_HOME/opmn/config/opmn.xml, for example:
<category id="start-parameters">
<data id="java-options" value="-server -XX:MaxPermSize=128M -ms512M -mx1024M -XX:AppendRatio=3 -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy -Djava.awt.headless=true -Dhttp.webdir.enable=false -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "/>
For OC4J standalone the startup command would look like:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar oc4j.jar
Running the Sample Code
Copy and Paste the sample code (see below) in a text file and save this file as say test.groovy
Set the following environment variables:
set ORACLE_HOME=c:\oc4j10133
set GROOVY_HOME=D:\groovy-1.5.6
set classpath=%GROOVY_HOME%\lib\commons-cli-1.0.jar;%GROOVY_HOME%\lib\groovy-1.5.6.jar;%ORACLE_HOME%\j2ee\home\admin_client.jar;%ORACLE_HOME%\j2ee\home\oc4jclient.jar;%GROOVY_HOME%\lib\asm-2.2.jar;%GROOVY_HOME%\lib\antlr-2.7.6.jar
Run the example using the command:
java -classpath %CLASSPATH% groovy.lang.GroovyShell test.groovy
Sample Code
import javax.management.remote.*
import oracle.oc4j.admin.jmx.remote.api.JMXConnectorConstant
import javax.management.remote.JMXConnectorFactory as JmxFactory
def serverUrl = new JMXServiceURL('service:jmx:rmi://localhost:23791')
def serverPath = 'oc4j:j2eeType=J2EEServer,name=standalone'
def jvmPath = 'oc4j:j2eeType=JVM,name=single,J2EEServer=standalone'
def provider = 'oracle.oc4j.admin.jmx.remote'
def credentials = [ (JMXConnectorConstant.CREDENTIALS_LOGIN_KEY): 'oc4jadmin'
, (JMXConnectorConstant.CREDENTIALS_PASSWORD_KEY): 'welcome1']
def env = [ (JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES): provider
, (JMXConnector.CREDENTIALS): credentials ]
def server = JmxFactory.connect(serverUrl, env).mBeanServerConnection
def serverInfo = new GroovyMBean(server, serverPath)
def jvmInfo = new GroovyMBean(server, jvmPath)
println """Connected to $serverInfo.node. \
Server started ${new Date(serverInfo.startTime)}.
OC4J version: $serverInfo.serverVersion from $serverInfo.serverVendor
JVM version: $jvmInfo.javaVersion from $jvmInfo.javaVendor
Memory usage: $jvmInfo.freeMemory bytes free, \
$jvmInfo.totalMemory bytes total
"""
def query = new javax.management.ObjectName('oc4j:*')
String[] allNames = server.queryNames(query, null)
def dests = allNames.findAll{ name ->
name.contains('j2eeType=JMSDestinationResource')
}.collect{ new GroovyMBean(server, it) }
println "Found ${dests.size()} JMS destinations. Listing ..."
dests.each{ d -> println "$d.name: $d.location" }
Sample Code Output
This is the expected output from the above groovy script
Connected to localhost.idc.oracle.com. Server started Tue Jul 22 12:32:55 IST 2008.
OC4J version: 10.1.3.3.0 from Oracle Corp.
JVM version: 1.5.0_15 from Sun Microsystems Inc.
Memory usage: 3657056 bytes free, 20709376 bytes total
Found 8 JMS destinations. Listing ...
jms/queues/ErrorQueue: jms/queues/ErrorQueue
jms/PSSPBasicInfo: jms/PSSPBasicInfo
jms/myTopic: jms/myTopic
Demo Queue: jms/demoQueue
jms/queues/ReceiveQueue: jms/queues/ReceiveQueue
Demo Topic: jms/demoTopic
jms/Oc4jJmsExceptionQueue: jms/Oc4jJmsExceptionQueue
jms/RAExceptionQueue: jms/RAExceptionQueue
How to run a Simple JMX-Groovy Example with OC4J
Software Requirements/Prerequisites
Download groovy software from http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.6.zip
Extract this to a directory say D:\groovy-1.5.6
Configuring the Sample CodeMake sure following startup options are set when either starting the OC4J standalone or the Oracle Application Server:
com.sun.management.jmxremote
com.sun.management.jmxremote.port=9004
com.sun.management.jmxremote.authenticate=false
com.sun.management.jmxremote.ssl=falseIf you are using OAS , then please set these parameters in the configuration file $ORACLE_HOME/opmn/config/opmn.xml, for example:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar oc4j.jar
Running the Sample Code
Copy and Paste the sample code (see below) in a text file and save this file as say test.groovy
Set the following environment variables:
set ORACLE_HOME=c:\oc4j10133set GROOVY_HOME=D:\groovy-1.5.6set classpath=%GROOVY_HOME%\lib\commons-cli-1.0.jar;%GROOVY_HOME%\lib\groovy-1.5.6.jar;%ORACLE_HOME%\j2ee\home\admin_client.jar;%ORACLE_HOME%\j2ee\home\oc4jclient.jar;%GROOVY_HOME%\lib\asm-2.2.jar;%GROOVY_HOME%\lib\antlr-2.7.6.jar
Run the example using the command:
java -classpath %CLASSPATH% groovy.lang.GroovyShell test.groovy