Friday, August 29, 2014

How to collect Thread Dump using Weblogic Console


This blog explains about how to get the thread dump using Weblogic Console

 - Login to Weblogic Console
 - Expand domain -> Environment -> Servers
 - Select the server, you want to collect the thread dump, Click on it
 - Monitoring -> 'Dump Thread Stacks'

Wednesday, August 27, 2014

How to prepare Custom UCM Query to search in UCM


This blog explains about how to perform a custom query similar to Webcenter out of box search query

       
import com.incresearch.common.constant.PortalConstant;
import com.incresearch.common.contentmanagement.UCMFile;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.logging.Level;

import oracle.adf.share.logging.ADFLogger;

import oracle.jbo.JboException;

import oracle.stellent.ridc.IdcClient;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.model.DataObject;
import oracle.stellent.ridc.model.DataResultSet;
import oracle.stellent.ridc.model.TransferFile;
import oracle.stellent.ridc.protocol.ServiceResponse;

        public List getCustomQuerySearchResults(String pSearchCriteria) {
        List fileList = new ArrayList();
        try {
            init("ohsadmin");
            String contributedPagesQuery =
                "(dDocTitle  `" + pSearchCriteria + "`" +
                "   (" + pSearchCriteria + "))";

            System.out.println("Custom Search Query: " +contributedPagesQuery);
            DataBinder dataBinder = myIdcClient.createBinder();
            dataBinder.putLocal("IdcService", "GET_SEARCH_RESULTS");
            dataBinder.putLocal("ResultCount", "50000"); 
            dataBinder.putLocal("QueryText", contributedPagesQuery);
            //setting date format
            dataBinder.putLocal("dInDate", "MMMM dd, yyyy hh:mm tt");
            
            ServiceResponse response;
            DataBinder serverBinder = null;
            response = myIdcClient.sendRequest(userContext, dataBinder);
            serverBinder = response.getResponseAsBinder();
            DataResultSet resultSet =
                serverBinder.getResultSet("SearchResults");
            int index = 0;
            if (resultSet != null) {
                UCMFile ucmFile = null;
                for (DataObject dataObject1 : resultSet.getRows()) {
                    String docName = dataObject1.get("dDocName");
                    ucmFile = new UCMFile();
                    ucmFile.setDocumentId(dataObject1.get("dID"));
                    ucmFile.setContentID(docName);
                    ucmFile.setDatasource("UCM#dDocName:" +
                                          dataObject1.get("dDocName"));
                    ucmFile.setDescription(dataObject1.get("xComments"));
                    ucmFile.setTitle(dataObject1.get("dDocTitle"));
                    ucmFile.setUrl(getDocWebUrl(dataObject1.get("dDocName")));
                    String date = formatDate(dataObject1.get("dInDate"));
                    ucmFile.setUploadDate(date);
                    ucmFile.setAuthor(dataObject1.get("dDocAuthor"));
                    ucmFile.setExt(dataObject1.get("dExtension"));

                    fileList.add(ucmFile);

                    index++;
                }
            }
        } catch (Exception ice) {
            System.out.println(ice.getMessage());
            ice.printStackTrace();
        } finally {

        }
        System.out.println("file size " + fileList.size());
        return fileList;
    }   
  
       
 

How to Download specific file from UCM using RIDC API ?

This blog explains about how to download a specific file from UCM using RIDC API

Use this method in FileDownloadListener component in .jsff or .jspx.

       

      public void downloadUCMFile(FacesContext facesContext,
                                OutputStream outputStream) {
        try {
  import org.apache.commons.io.IOUtils;
  
            String docName = "VMOHSKEND05482003131";
            String path =
                "https://privdev-oneinc.oracleoutsourcing.com/cs/groups/insight_application1/documents/document/ndgy/mdaz/~edisp/vmohskend05482003131.html";
            //need get docId dynamically
            Object obj =JSFUtils.getFromRequest("docID");
            System.out.println(obj);
            String docID = "2874";
            //String docID=downloadLink.getText();
            RIDCUtil ridc = new RIDCUtil();
            InputStream inputStream = ridc.getDocumentByID(docID, "ohsadmin");
            // copy hte data from the BlobDomain to the output stream
            IOUtils.copy(inputStream, outputStream);
            //   Tike tika = new Tika();
            //  System.out.println(tika.detect(inputStream));
            outputStream.flush();
        } catch (Exception e) {
            // handle errors
            e.printStackTrace();
            FacesMessage msg =
                new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(),
                                 "");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }
       
 

Saturday, August 23, 2014

How to configure Java Mission Control


Java Mission Control (JMC) is a tool that runs on Oracle JDK to perform Java monitoring, profiling and Java Application performance in both development and production environments. With this tool we can diagnose ADF application for any possible memory leaks, stuck threads or identify slowness of the application.
The JMX Console is used for monitoring and managing a running JVM instance.
Java Flight Recorder (JFR) is inbuilt in JMC and it produces detailed recordings about the running application. Once the recording is done, we can analyze it offline. The recording data include Memory and CPU usage statistics, Heap Statistics, Thread Dumps, Garbage collection Statistics, Object allocations, events etc.
JMC is included in JDK Package, It can be found in JAVA_HOME location.
E.g. C:\Oracle\Middleware\Oracle_Home\oracle_common\jdk\bin

You can run the tool directly from there or through command line or by adding it JDeveloper as External Tool.


Staring Weblogic with Flight Recording Enabled
You need to start Weblogic server using flight recording enabled, for the JMC flight Recorder to work.
To do that follow below steps
·       Right click viewcontroller and go to project properties à Run/Debug à Edit the default profile configuration (or your profile configuration).
·       Paste the following lines in Java Options
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder




 ·        Restart the server and run your application.
Using JMC
·        Open Java Mission control (JMC) after starting your application.


·        You can see Weblogic server running in JVM Browser Tab.
Optional Step:
If you are using a remote agent (This step is optional if you are running application locally)
·        Add the following parameters for Project properties / as VM arguments for running server
        -Dcom.sun.management.jmxremote=true
        -Dcom.sun.management.jmxremote.port=7091
        -Dcom.sun.management.jmxremote.authenticate=false
        -Dcom.sun.management.jmxremote.ssl=false
·        You can add/enable a remote agent using “Create New Custom JVM Connection “link


 ·        Right click on Weblogic and select à Start JMX console

·        In JMX Console you can see the live CPU, Memory usage in Graph , also there are tabs at the bottom to see detailed thread and memory usage.





q
Flight Recorder – recording data

·        Right click on Weblogic server and select “Start Flight Recording”. 
·        In Create flight recording dialog, choose name, and Recording time. Click finish to start flight recording

·        You can check Flight recorder by expanding Weblogic server à Flight Recorder. Also can stop and dump or edit the recording while it is in progress
·        Once recording is done, JMC opens the recording automatically or open it manually from location you choose to save or from default location (C:\Users\<user>\.jmc\5.3.0\).

·        Now you can analyze the data to find the problems

Analyzing a sample application:
·        Image below shows that High Memory Usage and Full Garbage collection was running sometimes, at that point application slows down and even freezes. 

·       Below Data shows there are 2 stuck threads and are running with high percentage and pointing to a method in the code.

·        Other Example Data

Check the below links for information and tutorials about how to analyze the JMC Flight recording.
·       Java Mission Control and Flight Recorder Demo Series http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/mc-jfr/index.html



More Information:

Monday, August 11, 2014

How to Configure Jdeveloper to Launch in various roles?


Below is the screen shot to know how to configure Jdeveloper to launch in different roles,

Customization Developer - If you want to launch the jdeveloper to customize out of box features, then launch the Jdeveloper in this mode.