Configure log4j in weblogic server

I have recently configured log4j for our web applications deployed in weblogic 10.3 domain. The steps are given below:

1. Copy log4j-1.2.9.jar & wllog4j.jar under domain_root/lib folder.
2. Create log4j.xml and drop it under domain_root folder. If you have log4j.xml inside the application(EAR/WAR), I would recommend to move outside EAR/WAR as changing severity (log level) would require re-deployment. To avoid this, we can move log4j.xml into domain root folder but again the server needs to be bounced. But there is a fix. Click here for more info.
3. Login to weblogic server console. Go to Servers ->  Admin Server-> Logging. Click on advanced mode. Change the logging implementation from JDK to Log4J. Click save.
4. Activate changes. Re-start the admin server.

This should enable log4j and should write logging into log file mentioned in log4j.xml or properties file.

Hang on! There is a catch here. Say now I want to change the log level from DEBUG into WARN or ERROR. How do i do? We go to log4j.xml and change the level. Now how does this change take into effect? It needs bouncing of the server. That part i didn't like it. But guess what I have a solution for this. Please click here for changing the log levels on the fly at run time. Log4jAdmin.jsp will do the trick.

Some of our readers asked for example of log4j.xml. If you google it you will get plenty of them, still I am honoring your requests. Here you go, folks:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
             value="%d [%t] %-5p %c - %m%n"/>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/log/myApp.log"/> 
    <param name="Append" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{ISO8601} %t %-5p %c{2} - %m%n"/>
  <logger name="org.apache">
    <level value="WARN"/>
  <logger name="org.springframework">
    <level value="WARN"/>
    <level value="DEBUG"/>
    <appender-ref ref="FILE"/>
<!--   <appender-ref ref="CONSOLE"/> -->

I have disabled log4j to write into weblogic console by commenting out. If you want to enable it just uncomment it and bounce the server, you are done!

Weblogic Portal Interview Questions

I thought i share some of weblogic portal interview questions I come across. One would expect this kind of questions during interview and should be able to answer them. My intentions was to let the people know what kind of questions asked. The questions are not in any particular order.

      1. Difference between a website and a portal?
Website is collection web pages, typically it contains information about particular company. A portal is a powerful web site that gives users a single point of access (or gateway) to applications and information in a unified interface. For eg, page) is great example of a portal.  
      2. What are the features of portal?
 Portal has got many features. To name a few: Personalization,  Authentication(single sign-on) and content aggregation.
     3. What are components of weblogic portal?
Look and feel components, header & footer(Shell), Menus, layouts, books & pages, portlets.    
     4. What is the difference between streaming portal and file-based portal?
To know more about this, please do visit my latest blog entry.
     5. What is backing file?
Backing file is java class used to pre-processing before portal object is rendered. The following portal controls support backing files:
    * Desktops
    * Books
    * Pages
    * Portlets
    * JspContent controls.
    6. How to create streaming portal/desktop?
Streaming desktop can be created using portal admin tool.
    7. What are the components of look-and-feel?
     Look & feel determines the appearance portal applications, it can be modified by developers programmatically or administrators using portal admin tool in staging and production environment. The following are components of look and feel:
  • Look & Feel file(.laf)
  • Skins
  • Skeletons
  • Themes
  • Chromosomes and Genes
  • Shells
  • Layouts
  • Menus  
     8. Difference between skin and skeleton?
Skins are collections of images, cascading style sheets (CSS), and JavaScript files that allow changes to be made to the look and feel of a portal without modifying the portal components directly. Skins basically provide the overall colors, graphics, and styles used by all components in a desktop interface.
Skeletons provide the physical boundaries of the portal components and provides references to the images, CSS, and JavaScript functions from the skin needed to render the portal. A portal web project can have multiple skeletons. When you select a Look & Feel for a desktop, a specific skin and skeleton is used. Each type of portal component, from a desktop to a portlet's title bar, has an associated JSP file, called a skeleton file that renders it.
     9. Difference between Genes and chromosomes?
Genes are implemented as simple text strings that are inserted into CSS styles or JavaScript files as variables. You define genes in an XML .chromosome file. In a .chromosome file, you could define a gene called "bodyColor" and assign it a value of "red," like this:
<gene name="bodyColor">
In your CSS file, you could use bodyColor as a variable:

body {
     border:1px solid ${bodyColor}
When the page is rendered in a browser, the inlined style definition becomes:

body {
     border:1px solid #FF0000
When you use this gene in your CSS files, you only need to modify the gene value itself to cascade the change throughout all configured CSS files rather than changing the value manually in each CSS file.
Chromosomes are simply the files that contain one or more genes. You can create multiple chromosome files that contain the same gene names, though with different gene values. By simply referencing a different chromosome in your Look & Feel file, you can simulate a completely different Look & Feel without changing any of your core Look & Feel files. 
10. What is shell?
Shells define the header and footer regions of a portal. Shells control the content that appears in a desktop's header and footer regions. You can configure a shell to use specific JSPs, page flows, HTMLs to display content in a header or footer. You can place portlets too in a header or footer of a shell.
11. Difference types of portlets?
  • JSP and HTML Portlets
  • JSR 168 portlets
  • Java Page Flow Portlets
  • Java Server Faces (JSF) Portlets
  • Struts Portlets
  • Remote Portlets
  • Browser (URL) Portlets
12. How is IPC (inter-portlet communication) happening?
Watch this page soon for an answer...

13. What are portlet modes?
Portlet Modes allow you to affect the end user’s ability to edit the portlet or display Help for the portlet. You add icon buttons to a portlet’s title bar to indicate the availability of a mode. The following pre-defined modes exist for WebLogic Portal:
    * Edit – Lets you specify a custom file that lets users modify the portlet's content when they click the Edit button.
    * Help – Lets you specify a custom file that shows users help content for the portlet when they click the Help button.
You can also create your own custom portlet modes using WebLogic Portal.
14. Types of portlet states?
Portlet states determine the end user’s ability to affect the rendering of a portlet. WebLogic Portal supports following portlet states:
  •     Normal – the typical rendered appearance of the portlet.
  •     Minimize – Collapses the portlet, leaving only the title bar, when the user clicks the Minimize button.
  •     Maximize – Makes the portlet take up the entire desktop area (not including the desktop header and  footer) when the user clicks the Maximize button.
  •     Float – Displays the portlet in a popup window when the user clicks the Float button.
  •     Delete – Removes the portlet from the desktop when the user clicks the Delete button.When you use the Portlet Wizard to create a portlet, state and mode settings are available on the Portlet  Details dialog. These settings can also be edited in the portlet’s Properties view. 
 15. What are different life cycles of backing files?
         init(), handlePostBackData(), preRender(), dispose().

16. Have you involved in any content propagation? Describe the different ways of weblogic portal content  propagation?
         Please see this blog entry for different types of content propagations strategy in weblogic.

17. What is federated portal?
         Please see this blog entry for detailed explanation.

Useful Links:
Weblogic portal interview questions Latest
More articles in Weblogic Portal

Set up custom user registry in Websphere 6.1 Application Server

Websphere doesn't provide out of box feature of data base authentication. This is really annoying if you want your web/ear applications deployed in WAS to be authenticated against the relational databases such as oracle, sybase, etc. Interestingly weblogic provides very good feature of configuring SQL authentication provider with Relational Database. It uses data source to configure. I have myself configured & authenticated successfully with Oracle in Weblogic. More info on that in feature.

But Websphere you need to write custom code for SQL authentication. You cannot use other WebSphere Application Server components, for example, data sources, to initialize the custom registry because other components, like the containers, are initialized after security and are not available during the registry initialization. A custom registry implementation is a pure custom implementation, independent of other WebSphere Application Server components. confusing? thats the way it is.

So I have custom code which authenticates with Oracle. This works OK. Obviously I also need to create the database schema for storing user/group/role information.

I wont be able to publish the code on the internet. But I can share with anyone if they are interested.

Cheers...Happy Deploying..

Setting up authentication alias in Websphere 6.1 application server

When you deploy application in websphere which uses Websphere application server JDBC resources, there are number of different ways for specifying security credentials. The simplest way is mention the user name/password programmatically when creating connection in clear text format. Needless to say this is a bad idea as we hard code these credentials in our application. one better way is create a component-managed authentication alias. This involves creating a mapping from an alias name to the userid and password. This alias name is then specified administratively on the connection factory or data source.

1. Go to websphere admin console
2. Under Security >> Secure administration, applications, and infrastructure >> JAAS >> J2C authentication data
3. Click New
4. Enter alias name
5. Enter Data base user id and password for connecting to database.
6. Click OK.

While creating data source for you application to connect to database, you should mention this alias name. So you can avoid entering clear text username/password while establishing connection in your application code.