Showing posts with label code. Show all posts
Showing posts with label code. 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

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";
}

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

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());
        }
      }
    }