Weblogic as windows service error

There is a bug in BEA documentation for creating weblogic server instance as window service. The doumentation URL is here  

The example script (for creating weblogic as window service) in the documentation shows we need to have ADMIN_URL as below:

set ADMIN_URL=http://adminserver:7501

Actually we do NOT need to mention this url in the manual script. I had this URL mentioned and end up getting the error below.

java.rmi.NoSuchObjectException: The object identified by: '31' could not be found. Either it was has not been exported or it has been collected by the distributed garbage collector.

I removed this entry ran the script again. It worked.

To know more info on creating or installing weblogic as a window service,  please see this blog entry

How to implement breadcrumb in Weblogic Portal

Breadcrumbs is one of the cool features of weblogic portal framework for UI navigation. We have successfully implemented this functionality in one our portal applications. That was based on weblogic portal 10.2 version. I think it should work with weblogic portal 10.3 as well. Let me know if you are running into any issues with the code. This jsp should be included as part of page.jsp.

Breadcrumbs.jsp:
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.bea.netuix.servlets.controls.window.WindowPresentationContext,
                 com.bea.netuix.servlets.controls.window.TitlebarPresentationContext,
                 java.util.ArrayList,
                 java.util.Iterator,
                 com.bea.portlet.PageURL,
                 com.bea.netuix.servlets.controls.page.BookPresentationContext,
                 com.bea.netuix.servlets.controls.page.PagePresentationContext,
                 com.bea.netuix.servlets.controls.window.WindowCapabilities"
%>
<%@ page session="false"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/netuix/render" prefix="render" %>

<%--
    This is the JSP for the showing breadcrumbs in XYZ Eagle portal.
    It is part of the skeleton file page.jsp.

    Implementation based on WebLogic Portal 10.2.

    Author ::      Ananth Kannan
--%>

<%
    ArrayList breadcrumbTitles = new ArrayList();
    ArrayList breadcrumbURLs = new ArrayList();
    boolean isHidden = false;

    BookPresentationContext book = BookPresentationContext.getBookPresentationContext(request);
    PagePresentationContext pageCtx = PagePresentationContext.getPagePresentationContext(request);

    if (!(book.getDefaultPage().equals(pageCtx.getDefinitionLabel())))
    {
        breadcrumbTitles.add(book.getTitle());
        breadcrumbURLs.add(PageURL.createPageURL(request,response,book.getDefaultPage()).toString());
    }
   
        PagePresentationContext parentPage = book.getParentPagePresentationContext();
        while (parentPage != null)
        {
            breadcrumbTitles.add(parentPage.getTitle());

            if (parentPage instanceof BookPresentationContext)
            {
                BookPresentationContext parentBook = (BookPresentationContext)parentPage;
                breadcrumbURLs.add(PageURL.createPageURL(request, response,  parentBook.getDefaultPage()).toString());
            }
            else
            {
                breadcrumbURLs.add(PageURL.createPageURL(request, response, parentPage.getDefinitionLabel()).toString());
            }
   
            parentPage = parentPage.getParentPagePresentationContext();
        }
%>
         

<%            
            //DO NOT SHOW BREADCRUMBS IN MAIN HOME PAGE and also in hidden page
            if (pageCtx.isHidden())
            {
            }
            else
            {               
%>
     <ul class="breadcrumbs">
<%
        for (int i = breadcrumbTitles.size() - 1; i >= 0; i--)
        {
            if (((String)breadcrumbTitles.get(i)).equalsIgnoreCase("My Main Book")) {
                    breadcrumbTitles.set(i, "My Home");
            }
           
%>
            <li class="first"><a href="<%=breadcrumbURLs.get(i) %>" ><%=breadcrumbTitles.get(i)%></a></li> <img src="<render:getSkinPath imageName="/arrow_right.gif" />" />&nbsp;  <%
        }
%>
<%
    }
%>
        </ul>

How to create weblogic domain template using weblogic template builder?

Domain templates are used to create(or extend weblogic server domains) with pre-configured resources such as JDBC, security realms, external libraries, log4j components. So when you create new domain you do not need to go to server console and create resources such as data source, etc.  While creating domain by using template you will have those resources configured already for you.

Lets say, you have a team of 10 people and you like everybody to have same configuration, then create a template share with the team. Even it is very much useful if you have new member in the team.

Domain templates can be built in many ways. This blog covers how to built using weblogic domain template builder.

Lets get started.

Step 1:

Go to Start Menu->All programs->weblogic10gR3->Tools->Domain Template Builder
or

go to c:\bea\wlserver_10.3\common\bin in command prompt. and type config_builder.cmd












Step 2:

Select create a domain template. If you are creating template for the first time.
Select create extension template if you are extending a existing template.

We will go with create domain template.

Step 3: Select a Template tab. Click on Basic Weblogic Server domain option. Click next











Step 4: Enter the name of template and other info. Click next.












Step 5:  Using Add Button, Select libraries you want to add under lib folder. copy jdbc data sources you would like to have under config/jdbc folder. If you want to have log4j configuration, copy log4j.xml under domain_root folder.

Click next










 Step 6: Select data base for the domain and click next.











Step 7: Enter Admin Server Name and port numbers. Click next.










Step 8: Enter username and password. Click next. Select No if you don want to add users/groups/roles











Step 9: Click next










Step 10: Click next












Step 11: Click next











Step 12: Click Create











Step 13: Click done.










This will create a domain template(jar file) which can be used to create domain.

When creating domain using domain config wizard, do select  2nd option which is "base this domain on existing template" as shown below and browse the template jar file and continue.











Good luck. Please let me know if you have any issues.

How to create weblogic domain template?


This blog has been moved. Please refer to this entry.  Sorry for the inconvenience. Thank you.


Configure Apache with multiple weblogic server instances

I came across a unique situation at work where I needed to configure Apache web server to forward requests to multiple weblogic server instances running on same box but different port numbers. Here is the scenario:

Instance A - http://test_server:7001/App1(Domain I)
Instance B - http://test_server:7003/App2 (Domain II)
Instance C - http://test_server:7005/App3 (Domain III)

I have App1 deployed on instance1 which is running in domain I. Similarly App2 deployed on instance 2, app3 deployed on instance 3. Needless to say all domains running in different ports(non-clustered environment).

Now I would like to configure my Apache to forward request to respective URLs based on what do they type in the URL.

If they type http://test_server/App1 should go to instance A.
If they type http://test_server/App2 should go to instance B.
If they type http://test_server/App3 should go to instance C.

When I use <IfModule> tag with location combination it did not work for me. But when I use <Location> tag for each app/instance in httpd.conf, it worked. Hope this information helps. 

#### for Instance 1/App1
<Location /App1>
       SetHandler weblogic-handler
       WebLogicHost test_server
       WebLogicPort 7001
       WLCookieName cookie1
       DynamicServerList OFF
       MaxPostSize     2048
       Debug ALL
       WLLogFile logs/httpd_proxy1.log
</Location>

#### for Instance2/App2

<Location /App2>
       SetHandler weblogic-handler
       WebLogicHost test_server
       WebLogicPort 7003
       WLCookieName cookie2
       DynamicServerList OFF
       MaxPostSize     2048
       Debug ALL
       WLLogFile logs/httpd_proxy1.log
</Location>


#### for Instance3/App3
<Location /App3>
       SetHandler weblogic-handler
       WebLogicHost test_server
       WebLogicPort 7005
       WLCookieName cookie3
       DynamicServerList OFF
       MaxPostSize     2048
       Debug ALL
       WLLogFile logs/httpd_proxy1.log
</Location>

How to change log4j log levels at runtime?

Here is the source code for log4jAdmin.jsp. I have copied under root of my WAR. Once you deployed the WAR, you can change the log levels on the fly without bouncing the servers. Remember you should have configured log4j in your applications properly. Please follow this link if you have any trouble in configuring log4j.
Once you copy this log4jAdmin.jsp under root of your web app, you can access it by entering
http://host_name:port/webapp/log4jAdmin.jsp

log4jAdmin.jsp:

<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.log4j.Level" %>
<%@ page import="org.apache.log4j.LogManager" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Arrays" %>
<% long beginPageLoadTime = System.currentTimeMillis();%>

<html>
<head>
    <title>Log4J Administration</title>
    <style type="text/css">

        <!--
        #content {
            margin: 0px;

            padding: 0px;
            text-align: center;
            background-color: #ccc;

            border: 1px solid #000;
            width: 100%;
        }

        body {
            position: relative;
            margin: 10px;

            padding: 0px;
            color: #333;
        }

        h1 {
            margin-top: 20px;
            font: 1.5em Verdana, Arial, Helvetica sans-serif;
        }

        h2 {
            margin-top: 10px;
            font: 0.75em Verdana, Arial, Helvetica sans-serif;
            text-align: left;
        }

        a, a:link, a:visited, a:active {
            color: red;
            text-decoration: none;
            text-transform: uppercase;
        }

        table {
            width: 100%;
            background-color: #000;
            padding: 3px;
            border: 0px;
        }

        th {
            font-size: 0.75em;
            background-color: #ccc;
            color: #000;
            padding-left: 5px;
            text-align: center;
            border: 1px solid #ccc;
            white-space: nowrap;

        }

        td {
            font-size: 0.75em;
            background-color: #fff;
            white-space: nowrap;

        }

        td.center {
            font-size: 0.75em;
            background-color: #fff;
            text-align: center;

            white-space: nowrap;
        }

        .filterForm {

            font-size: 0.9em;
            background-color: #000;
            color: #fff;
            padding-left: 5px;
            text-align: left;
            border: 1px solid #000;

            white-space: nowrap;
        }

        .filterText {

            font-size: 0.75em;
            background-color: #fff;
            color: #000;
            text-align: left;

            border: 1px solid #ccc;
            white-space: nowrap;

        }

        .filterButton {
            font-size: 0.75em;

            background-color: #000;
            color: #fff;

            padding-left: 5px;
            padding-right: 5px;

            text-align: center;
            border: 1px solid #ccc;

            width: 100px;
            white-space: nowrap;
        }

        -->
    </style>
</head>
<body onLoad="javascript:document.logFilterForm.logNameFilter.focus();">

<%
    String containsFilter = "Contains";
    String beginsWithFilter = "Begins With";

    String[] logLevels = {"debug", "info", "warn", "error", "fatal", "off"};
    String targetOperation = (String) request.getParameter("operation");
    String targetLogger = (String) request.getParameter("logger");
    String targetLogLevel = (String) request.getParameter("newLogLevel");
    String logNameFilter = (String) request.getParameter("logNameFilter");
    String logNameFilterType = (String) request.getParameter("logNameFilterType");

%>
<div id="content">
<h1>Log4J Administration</h1>

<div class="filterForm">

    <form action="log4jAdmin.jsp" name="logFilterForm">Filter Loggers:&nbsp;&nbsp;
        <input name="logNameFilter" type="text" size="50" value="<%=(logNameFilter == null ? "":logNameFilter)%>"

               class="filterText"/>
        <input name="logNameFilterType" type="submit" value="<%=beginsWithFilter%>" class="filterButton"/>&nbsp;

        <input name="logNameFilterType" type="submit" value="<%=containsFilter%>" class="filterButton"/>&nbsp;

        <input name="logNameClear" type="button" value="Clear" class="filterButton"

               onmousedown='javascript:document.logFilterForm.logNameFilter.value="";'/>
        <input name="logNameReset" type="reset" value="Reset" class="filterButton"/>

        <param name="operation" value="changeLogLevel"/>
    </form>
</div>

<table cellspacing="1">
    <tr>
        <th width="25%">Logger</th>

        <th width="25%">Parent Logger</th>
        <th width="15%">Effective Level</th>

        <th width="35%">Change Log Level To</th>
    </tr>

    <%
        Enumeration loggers = LogManager.getCurrentLoggers();

        HashMap loggersMap = new HashMap(128);
        Logger rootLogger = LogManager.getRootLogger();

        if (!loggersMap.containsKey(rootLogger.getName())) {

            loggersMap.put(rootLogger.getName(), rootLogger);
        }

        while (loggers.hasMoreElements()) {
            Logger logger = (Logger) loggers.nextElement();

            if (logNameFilter == null || logNameFilter.trim().length() == 0) {

                loggersMap.put(logger.getName(), logger);
            } else if (containsFilter.equals(logNameFilterType)) {

                if (logger.getName().toUpperCase().indexOf(logNameFilter.toUpperCase()) >= 0) {

                    loggersMap.put(logger.getName(), logger);
                }

            } else {
// Either was no filter in IF, contains filter in ELSE IF, or begins with in ELSE
                if (logger.getName().startsWith(logNameFilter)) {

                    loggersMap.put(logger.getName(), logger);
                }

            }
        }
        Set loggerKeys = loggersMap.keySet();

        String[] keys = new String[loggerKeys.size()];

        keys = (String[]) loggerKeys.toArray(keys);

        Arrays.sort(keys, String.CASE_INSENSITIVE_ORDER);
        for (int i = 0; i < keys.length; i++) {

            Logger logger = (Logger) loggersMap.get(keys[i]);

// MUST CHANGE THE LOG LEVEL ON LOGGER BEFORE GENERATING THE LINKS AND THE
// CURRENT LOG LEVEL OR DISABLED LINK WON'T MATCH THE NEWLY CHANGED VALUES
            if ("changeLogLevel".equals(targetOperation) && targetLogger.equals(logger.getName())) {

                Logger selectedLogger = (Logger) loggersMap.get(targetLogger);

                selectedLogger.setLevel(Level.toLevel(targetLogLevel));
            }

            String loggerName = null;
            String loggerEffectiveLevel = null;
            String loggerParent = null;
            if (logger != null) {
                loggerName = logger.getName();
                loggerEffectiveLevel = String.valueOf(logger.getEffectiveLevel());
                loggerParent = (logger.getParent() == null ? null : logger.getParent().getName());

            }
    %>
    <tr>
        <td><%=loggerName%>
        </td>

        <td><%=loggerParent%>
        </td>
        <td><%=loggerEffectiveLevel%>

        </td>
        <td class="center">
            <%
                for (int cnt = 0; cnt < logLevels.length; cnt++) {

                    String url = "log4jAdmin.jsp?operation=changeLogLevel&logger=" + loggerName + "&newLogLevel=" + logLevels[cnt] + "&logNameFilter=" + (logNameFilter != null ? logNameFilter : "") + "&logNameFilterType=" + (logNameFilterType != null ? logNameFilterType : "");

                    if (logger.getLevel() == Level.toLevel(logLevels[cnt]) || logger.getEffectiveLevel() == Level.toLevel(logLevels[cnt])) {

            %>
            [<%=logLevels[cnt].toUpperCase()%>]

            <%
            } else {
            %>
            <a href='<%=url%>'>[<%=logLevels[cnt]%>]</a>&nbsp;

            <%
                    }
                }
            %>
        </td>
    </tr>

    <%
        }
    %>
</table>
<h2>
    Revision: 1.0<br/>
    Page Load Time (Millis): <%=(System.currentTimeMillis() - beginPageLoadTime)%>
</h2>
</div>
</body>
</html>