Thursday, September 29, 2011

Location of java class file used by Application

Sometimes, while debugging the code, you will be wondering that which class is being picked by Java application from the current Classpath.
Here is some small code snippet to know the location of the class file.
Very simple, it just tries to get the system resource for the class file.


public class ClassSource {

    public static String getClassLocation(String fullQualifiedclassName) throws ClassNotFoundException {
        Class cls = Class.forName(fullQualifiedclassName);
        String classPath = fullQualifiedclassName.replace('.','/').concat(".class");
        if (cls!=null && cls.getClassLoader()!=null) {
            return cls.getClassLoader().getResource(classPath).toString();
        } else {
            return ClassLoader.getSystemResource(classPath).toString();
    public static void main(String[] args) throws Exception {
        System.out.println("Class Object source : " + getClassLocation("java.lang.Object"));
        System.out.println("Current Class : " + getClassLocation(""));

Output on my machine:

Class Object source : jar:file:/L:/Program%20Files/Java/jre1.5.0_09/lib/rt.jar!/java/lang/Object.class
Current Class : file:/I:/work/eclipse-workspace/Java-Test/classes/test/java/ClassSource.class

Tuesday, September 27, 2011

Redirecting or Ignoring System.out.println outputs

Recently one of my friend had following requirement. I guess it can be useful to anyone.
In case you want to redirect all the System.out.println() output to some file, you can do using following methods provided by System class.
System.setOut(), System.setIn() and System.setErr()

So, to redirect the output and error logs, you can simply say
    String outFile = "/tmp/sysout.log";
    System.setOut(new PrintStream(new FileOutputStream(outFile)));
    String errFile = "/tmp/syserr.log";
    System.setOut(new PrintStream(new FileOutputStream(errFile)));

Sometimes its required to hide all System.out.println outputs when the existing application is unnecessarily writing lot of outputs filling the system space and it would take some time to modify all the code. To do this, you can subclass PrintStream and override its methods for no-op.

    System.out.println("Hello, program started.");
    String filename = "D:\\sysout.log"; //or put some dummy filepath, need to this to construct PrintStream
    System.setOut(new PrintStream(new FileOutputStream(filename)) {
                public void print(String paramString) {
                  //do nothing

                public void println(String paramString) {
                  //do nothing
                //above will just hide the output for print(String) and println(String) methods.
                //override all other print/println methods so nothing gets printed at all.
    System.out.println("This is another string in sysout.");

Monday, September 19, 2011

Oracle Application R12 release setup

Few important environment variables and filepaths:

gives the context file which should be used to any global permanent update to the instance.

stores information about OC4J server classpath.

stores information about servet and jsp settings. New servlet needs to be defined here. If new jsps are added to the instance and they not getting recompiled automatically, following setting needs to be set for main_mode parameter in this file. Usually this setting is set to justrun which does not compile new jsp files.


Classpath for the Java Concurrent programs should be set in adovars.env file.

Look for following element in $CONTEXT_FILE
 <oa_environment type="adovars">
This element will contain parameters for actual adovars file referred by instance. Sometimes there can be multiple adovars environment files on the instance and this should point to currently used adovars file.

Set the value for AF_CLASSPATH element tag to append or prepend classpath for concurrent programs.

Use this file to setup new system properties for OC4J. For Configurator users, you will find cz init properties file reference in this file.

All log files are available here under respective directories like Apache, j2ee, oacore etc.

Apache/OC4J start/stop server scripts are available under $INST_TOP/admin/scripts/

Sunday, September 11, 2011

Print incoming and outgoing cookie through Apache Access log

Sometimes its really very useful to print the incoming and outgoing cookie (or any other http header) from Apache Server to debug Http Session or Loan Balancer related issues.

We can modify the LogFormat in httpd.conf file to print our custom logging. Following format will print incoming and outgoing cookies.

"%h %l %u %t %T \"%r\" %>s %b\n\t\t\t\
   Cookie %{Cookie}i\n\t\t\t\
   Set-Cookie %{Set-Cookie}o"

Saturday, September 10, 2011

Get Log4j File names dynamically for all registered loggers

Use following code to get the filenames registered for logging in log4j.xml file and use them to do whatever you want. Usually the processes in organization will take longer to get the log files, can you do something useful from this? Think and do it on your own and don't document it ever :)

    Enumeration currentLoggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
    while (currentLoggers.hasMoreElements()) {
      Logger logger = (Logger)currentLoggers.nextElement();
      System.out.println("Logger : " + logger.getName());
      Enumeration loggerApp = logger.getAllAppenders();
      if (loggerApp.hasMoreElements()) {
        Appender ap = (Appender) loggerApp.nextElement();
        if (ap instanceof FileAppender) {
          FileAppender fileAppender = (FileAppender)ap;
          System.out.println("   FileName : " + fileAppender.getFile());
          System.out.println("Not a file Appender, appender type=" + ap.getClass().getName());

Thursday, September 1, 2011

Oracle Configurator

Oracle Configurator is
  • an SCM (Supply Chain Management) family product in Oracle Applications
  • integrates with Order Management, Quoting, iStore and other custom applications allowing them to configure its product.
  • helps in building a Guide Selling flow
  • allows the product to be configured according to custom defined rules and User Interfaces (UIs).
  • manages the set of UIs (publications) for different application for different effectivity dates.
  • has CZ as code name in Oracle Applications
  • webbased product
From Oracle's website
Oracle Configurator application integrates with Oracle CRM and Supply Chain Management so you can offer guided selling to your customers. It actively gathers customer requirements and then maps them to a set of product or service options. Oracle Configurator supports Internet sales and telesales as well as other channels.

What to expect from this product:

To easily understand the end result CZ product, visit Dell website and configure any laptop.
While configuring the laptop, you will find that some items in the laptop product (like RAM and OS, Port and respective Accessories) may not be compatible with each other. Like, Windows Vista is not compatible with less than 1GB RAM. You may see some items selected/deselected automatically when you select certain items. You will also see some items appearing and disappearing in webpage UI based on certain selections.

Such compatibility and incompatibility of the items in product are created and managed by product developer. These are called Rules in CZ. CZ Rules can select/deselect certain items based on defined criteria.
The display layout of certain items, and their visibility/invisibility is defined in CZ UIs.
Once, you have the UIs, you can create a copy (although copy not an appropriate term, but gives good understanding about model publications) of UIs and send it to various applications registered in Oracle Applications. Process of creating this backup copy is called Publications.

Well, above example talked only about Laptop product model. You can create Rules and UIs for any product (having however complex its structure may be, usually a BOM-Bill of Materials model).
In addition to product's defined structure items, you can create additional nodes/items (in CZ, they are called non-BOM nodes) in the product model which help to create guided selling flow for the product. Like in above laptop example, first you may select the use of the laptop (like Home-use or Office-use) and certain selections will be made automatically (through CZ rules) for you to create laptop configuration according to selected requirement.