Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Sunday, January 26, 2014

Oracle Configurator CIO and dependent jar files

Here are the some of the jar files required to build Configurator CX extensions and few other test cases around that.

It contains old com.sun.java.util.collections jar along with JDBC, FND, OC4J and other related jars. Its link to dropbox. These jars are from Oracle applications 12.1.x version.

Although these files are here for reference purpose, its always good to get them from your instance where you are going to deploy your changes. You can get all of the following classes from $JAVA_TOP directory on instance middle-tier.

UPDATE: Link to jar file is removed now. Jar file can be created with following commands from middletier unix box.

bash>cd $JAVA_TOP
bash>jar cvf oracle.apps.cz.jar oracle/apps/cz
bash>jar cvf oracle.apps.fnd.jar oracle/apps/fnd

Saturday, November 30, 2013

Update Java Extension ClassName for Configurator CX rules using query

Following query will update the java classname (from xxcz.cx.MyOldClass to xxcz.cx.MyNewClass ) for all the models which are under repository folder name 'Models - In Process'

UPDATE cz_rules ru
SET ru.class_name        = 'xxcz.cx.MyNewClass'
WHERE exists(SELECT
  rpf.name folder_name,
  p.name model_name,
  p.devl_project_id,
  r.name rule_name,
  r.rule_id,
  r.class_name
FROM cz_rules r,
  cz_devl_projects p,
  cz_rp_entries rpp,
  cz_rp_entries rpf
WHERE r.devl_project_id=p.devl_project_id
AND r.rule_type = 300 -- CX rules
AND rpp.object_id       =p.devl_project_id
and rpp.enclosing_folder = rpf.object_id
AND rpp.object_type     ='PRJ'
AND R.DISABLED_FLAG=0  --update only enabled rules
AND rpf.object_type = 'FLD'
--AND P.DEVL_PROJECT_ID=1037298 --add this if you want to update specific model only
AND class_name LIKE 'xxcz.cx.MyOldClass'
AND RPF.NAME LIKE 'Models – In Process'
AND r.rule_id=ru.rule_id
);

Tuesday, October 30, 2012

Validate Existing OAF Session in JSP/Servlet

One way to validate OAF session in custom jsp/servlet in Oracle applications. Method will return "INVALID" if the current session is invalid, "EXPIRED" if current session is expired and "VALID" if current session is valid.
You can also create new session if current session is invalid, wiill post detail in some other post. But, usually if Functionality is part of existing oracle application module, then you will just want to validate if current session is valid or not. If not, you may want to redirect to /OA_HTML/AppsLocalLogin.jsp page.

public static String validateOAFSession(HttpServletRequest request, HttpServletResponse response) {
    WebAppsContext appsContext = null;
    try {
        appsContext = WebRequestUtil.createWebAppsContext(request, response);
        if (appsContext != null) {
            String sessionCookie = WebRequestUtil.getSessionCookie(request, response, appsContext);
            if (sessionCookie == null) {
                return "INVALID";
            }
            if (!appsContext.validateSession(sessionCookie, true)) {
                return "EXPIRED";
            }
        }
    } catch (IOException ioe) {
        return "INVALID";
    } finally {
        if (appsContext != null) {
            appsContext.freeWebAppsContext();
        }
    }
    return "VALID";
}

Tuesday, March 27, 2012

Start Configuration from Jdeveloper

I have seen everyone working on Configurator Extensions wondering if we can start Configuration session from local machine Jdeveloper. Well, the answer is Yes. You can! I have done it in past.

Follow these steps:
  • Install Jdeveloper.
  • You need is DBC file and put it in local machine directory. Refer DBC file path in your java program in System properties - DBCFILE and JTFDBCFILE.
  • Refer Configurator Extension Guide to create configuration using CIO from Java program.
  • Get all the classes from middletier required by Configurator (fnd classes). You can start with none and as you start getting error, you can create jar for specific packages like oracle.apps.fnd and put it in your jdev. If you want to know class location on server, you can use CZInfo.jsp file. More info on CZInfo.jsp file is here.

Its very useful for debugging purpose, but its very very slow is what I experienced - depending on your model size and how your db responds to your machine. It actually executes plenty of queries (to get model/rule details from database) to create configuration on local machine and load all those classes which makes it very slow.

Using this you can test/debug-step through your Extension code.

Friday, October 14, 2011

Compressing and Decompressing String in Java using GZIP streams

Following code can be used to compress or decompress any data in Java using the GZIP streams - java's built in zip streams.
    public static String compress(String str) throws IOException {
        if (str == null || str.length() == 0) {
            return str;
        }
        System.out.println("String length : " + str.length());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(str.getBytes());
        gzip.close();
        String outStr = out.toString("ISO-8859-1");
        System.out.println("Output String lenght : " + outStr.length());
        return outStr;
     }
    
    public static String decompress(String str) throws IOException {
        if (str == null || str.length() == 0) {
            return str;
        }
        System.out.println("Input String length : " + str.length());
        GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(str.getBytes("ISO-8859-1")));
        BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "ISO-8859-1"));
        String outStr = "";
        String line;
        while ((line=bf.readLine())!=null) {
          outStr += line;
        }
        System.out.println("Output String lenght : " + outStr.length());
        return outStr;
     }
  
     public static void main(String[] args) throws IOException {
        String filePath = ".\response.txt";
        
        String string = getFileData(filePath);
        System.out.println("after compress:");
        String compressed = compress(string);
        System.out.println(compressed);
        System.out.println("after decompress:");
        String decomp = decompress(compressed);
        System.out.println(decomp);
 
      }
     
     public static String getFileData(String filepath) throws FileNotFoundException,
                                                           IOException {
       BufferedReader bf = new BufferedReader(new FileReader(filepath));
       String data="";
       String line;
       while ((line=bf.readLine())!=null) {
         data += line;
       }
       return data;
     }

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.

package test.java;

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("test.java.ClassSource"));
    }
    
}

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)) {
   
                @Override
                public void print(String paramString) {
                  //do nothing
                }

                @Override
                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.");

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());
        }else{
          System.out.println("Not a file Appender, appender type=" + ap.getClass().getName());
        }
      }
    }