Search This Blog

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

I have a Customer who has an application which prints java.lang.NullPoinerException and no stack trace associated with this.
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

This note explains how to run a simple JMX script using the groovy scripting language.
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

This note explains how to run a simple JMX script using the groovy scripting language.
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:


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:\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