Wednesday, May 29, 2013

Customize ATG Dynamo Administration Page for a Component

Default interface of each component in ATG Dynamo Administration displays properties and methods. Oracle ATG provides a way to override this default behavior by each component.One such example is /atg/dynamo/DeploymentAgent where a snapshot ID can be forced. 



How-to-Code: Override the method createAdminServlet and create either a subclass or nested class as show below.

   /**
    * This is the class to add new Magic Numbers for handling Product Support Issues with file uploads
    *  
    * @see atg.nucleus.GenericService#createAdminServlet()
    */
   @Override
   protected Servlet createAdminServlet() {
     return new AdminServlet(this, getNucleus());
   }
   /**
    * this class will implement methods needed to set new magic numbers
    *  
    * @author sgatupa
    */
   class AdminServlet extends ServiceAdminServlet {
     private static final long serialVersionUID = 1L;
     public AdminServlet(final Object pService, final Nucleus pNucleus) {
       super(pService, pNucleus);
     }
     @Override
     protected void printAdmin(final HttpServletRequest httpservletrequest,
                  final HttpServletResponse httpservletresponse,
                  final ServletOutputStream output) throws ServletException, IOException {
        printCustomform(httpservletrequest,httpservletresponse,output);
        processFormData(httpservletrequest,httpservletresponse,output);
     }
     protected void printCustomform(final HttpServletRequest httpservletrequest,
                            final HttpServletResponse httpservletresponse,
                            final ServletOutputStream output) throws ServletException,
                                            IOException {
       output.println("<H1>Form to set New Magic numbers</H1>");
       output.println("<ol>");
       output.println("<li>Enter the data</li>");
       output.println("<li>Then click on Add Magic Numbers</li>");
       output.println("</ol>");
       output.println(HTML_LINE_SEPARATOR);
       output.print("<form action=\"");
       output.print(formatServiceName(httpservletrequest.getPathInfo(), httpservletrequest));
       output.println("\" method=POST>");
       output.println("<input type=text size=70 name=field1>");
       output.println("<input type=submit name=submit value=\"Add Magic Numbers\">");
       output.println("</form>");
     }
     protected void processFormData(final HttpServletRequest httpservletrequest,
                            final HttpServletResponse httpservletresponse,
                            final ServletOutputStream output) throws IOException {
           String paramValue= httpservletrequest.getParameter("field1");
              this.propertyOne = paramValue;
         output.println("<b>Operation Success. Please verify the property <i>magicNumberToFileTypeMap</i> if new magic numbers are added: </b>: "
             + newMgNumbers);
         output.println(HTML_LINE_SEPARATOR);
     }
   }


How-to-Use: Navigate to the component http://host:port/dyn/admin/nucleus//shamg/Component1.



Wednesday, May 8, 2013

ATG OOTB SqlJMSAdmin

Today I would like to share about one of the less used but effective tool SQLJMSAdmin that is shipped by Oracle along with ATG install.

How does it help?
There is a need to administer and monitor JMS messages once you begin using SQL JMS Provider in your application. Since SQL JMS stores message states in database, you have two choices:

  1. Use DML statements as specified in documentation to query message build up or
  2. Use SQLJMSAdmin, a browser based administration tool for SQL JMS 

How to configure?
  1. If your application server
    • Jboss: Modify <ATG_INSTALL_FOLDER>\SQLJMSAdmin\j2ee-apps\sqlJmsAdmin\ejbModule\META-INF\jboss.xml with appropriate Core datasource (same as Order repository DataSource)
    • Weblogic: Modify all enterprise bean definitions in file <ATG_INSTALL_FOLDER>\SQLJMSAdmin\j2ee-apps\sqlJmsAdmin\ejbModule\META-INF\weblogic-ejb-jar.xml to include Core datasource, for example
    •  ...  
        <weblogic-enterprise-bean>  
         <ejb-name>DMSTopicSubscription</ejb-name>  
         <reference-descriptor>  
          <resource-description>  
          <res-ref-name>jdbc/datasource</res-ref-name>  
          <jndi-name>atg_core</jndi-name>  
          </resource-description>  
         </reference-descriptor>    
         <enable-call-by-reference>True</enable-call-by-reference>  
        </weblogic-enterprise-bean>  
       ...  
      
  2. You need to add "SQLJMSAdmin" to runAssembler task so that it is included in the ear file
How to use it?
Once the ear is built including SQLJMSAdmin module, you can access the administration tool at http://<host>:<port>/sqlJmsAdmin.
When prompted for credentials, use the same credentials as in Dynamo Administration Tool. Now you access to monitor message build up
Fig 1: SQLJmsAdmin Dashboard


Fig 2: Messages in a Queue

if you look at Fig2, you can see choices to move messages from let's say a DeadLetterQueue to a Normal Queue like "SubmitToOMS" to be retried.



Saturday, May 4, 2013

Profiling ATG CRS application using VisualVM

As and when order were huge, Modification of order took long time, of course right. But I wanted to get some metrics to get an idea. And I was surprised to find that ATG OOTB CartModifierFormHandler.java was missing hooks to Performance Monitor. So I went the route to use JVisualVM that comes default with JDK 1.6.

Step 1) Open VisualVM, navigate to Profiler tab and modify settings similar to the picture below.



Step 2) Add Java6-server.profile file to %JAVA_HOME%\lib. I did not have the file on my machine, I downloaded a copy from https://issuetracker.springsource.com/browse/DMS-424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel and added one line "org.netbeans.lib.profiler.*"

Step 3) Restart Jboss and open Jboss process in Visual VM

Step 4) Open your favorite browser and navigate to a product details page assuming you want to profile adding item to cart (don't click add item to cart yet)

Step 5) Go to Profiler Tab and then click on button "CPU", wait for about 3-4 secs until you see a message similar to  "profile running(256 methods instrumented)"

Step 6) Now click on CRS application, "Add to Cart" button (make sure you select Color and Size

Step 7) First time it takes long time to capture statistics, be patient. Once done, you can click on snapshot and save it for investigating later. Don't rely on the first time statistics repeat this step by resetting statistics and adding another item to cart. Then metrics should look like


Note:
1) on the command prompt where you start Jboss, make sure you run the command
    SET JBOSS_CLASSPATH=%JAVA_HOME%\lib\visualvm\profiler\lib\jfluid-server.jar;%JBOSS_CLASSPATH%

  if not you will see error in jboss server log
"org.netbeans.lib.profiler.server.ProfilerRuntimeCPUFullInstr.rootMethodEntry(ProfilerRuntimeCPUFullInstr.java:284)"

2) if you don't run Step 2 mentioned above, you will see in Server log

ArrayIndexOutOfBoundsException and Profiler Agent Error: Redefinition failed

3) If you leave org.jboss in starter class in profiler settings, then it will take long. It is good practice to have right classes in settings according to the scenario you are interested to profile. In the case above I wanted to profile "Adding Item to Cart"

Download java6-server.profile here

Friday, May 3, 2013

Weblogic Class Conflicts and Resolutions


CAT is a Web-based class analysis tool that comes with weblogic aids you in analyzing classloading issues, such as detecting conflicts, debugging application classpaths and class conflicts, and proposes solutions to help you resolve them.

Recently I ran into an issue where one of the method on ArrayUtils found in commons-lang was not found at runtime. CAT helped me to identify and the resolution was to add the jar file to the classpath in setDomainEnv.cmd

ar;C:\Oracle\Middleware\user_projects\domains\base_domain\lib\slf4j-log4j12-1.5.6.jar;C:\Oracle\Middleware\user_projects\domains\base_domain\lib\log4j-1.2.16.jar;C:\Oracle\Middleware\user_projects\domains\base_domain\lib\validation-api-1.0.0.GA.jar;C:\Oracle\Middleware\user_projects\domains\base_domain\lib\hibernate-validator-4.2.0.Final.jar;C:\Oracle\Middleware\user_projects\domains\base_domain\lib\commons-lang-2.6.jar




An outline of the steps will include:

  1. Start Weblogic Application Server
  2. Go to URL: http://localhost:7001/wls-cat 
  3. On the left select your application and then click "Generate Report"
  4. Select appropriate Class Loader and then enter fully qualified class name and you can see which jar is loaded
Resolution can include sometimes adding the jar to the classpath or pre-classpath in setDomainEnv.cmd file

You can find more info from Weblogic Documentation at You can find more information at http://docs.oracle.com/cd/E21764_01/web.1111/e13706/classloading.htm#BABHJGJJ