This discussion is archived
2 Replies Latest reply: Apr 24, 2012 2:21 PM by 931605 RSS

weblogic, eclipse plugin, ServletContextListener

931605 Newbie
Currently Being Moderated
I'm new to weblogic and I'm testing some existing tomcat code that's showing some strange behavior inside of eclipse. When I right click in the servers window and debug a weblogic test project I see contextInitialized called twice. During the first call I see some of the api's fail whereas the second call seems to run ok. Is there any way to prevent the two calls? When I launch tomcat, contextInitialized is called once so I would like the same thing to happen inside of weblogic. I know I could go w/ the application life cycle listener but for now I would like to keep the code in the current form. Just to make it clear, this code is called twice:

public class ContextLoaderListener implements ServletContextListener
{
public void contextInitialized(ServletContextEvent contextEvent)
{
// called twice, how to skip the first call?
}
...
}

is there a way to check a property or make a call so that the code only runs twice.

An example of where this causes problems is when I register a bean during startup:

call 1: ( beanServer.addNotificationListener(...) )

INFO: registerNotificationListenerInternal: watchRuntimeName = com.bea:ServerRuntime=AdminServer,Name=DiagnosticsJMXNotificationSource,Type=WLDFWatchJMXNotificationRuntime,WLDFWatchNotificationRuntime=WatchNotification,WLDFRuntime=WLDFRuntime>
####<Apr 18, 2012 1:47:05 PM CDT> <Notice> <StdErr> <BUSTX05NLKVB231> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1334774825919> <BEA-000000> <Apr 18, 2012 1:47:05 PM com.verizon.vidaas.metrics.MetricsManager registerNotificationListenerInternal
SEVERE: javax.management.InstanceNotFoundException: com.bea:ServerRuntime=AdminServer,Name=DiagnosticsJMXNotificationSource,Type=WLDFWatchJMXNotificationRuntime,WLDFWatchNotificationRuntime=WatchNotification,WLDFRuntime=WLDFRuntime
...




call2: ( beanServer.addNotificationListener(...) )

INFO: registerNotificationListenerInternal: watchRuntimeName = com.bea:ServerRuntime=AdminServer,Name=DiagnosticsJMXNotificationSource,Type=WLDFWatchJMXNotificationRuntime,WLDFWatchNotificationRuntime=WatchNotification,WLDFRuntime=WLDFRuntime>
<no exception here>


So, call2 works but for some strange reason call1 doesn't so if I could skip call1, then maybe that would fix the issue?

One final note: this is not an issue when run outside of eclipse.

thanks,
Paul.
  • 1. Re: weblogic, eclipse plugin, ServletContextListener
    164415 Oracle ACE
    Currently Being Moderated
    Hi Paul --

    The ServletContextListener should be getting called once per ServletContext creation. That's the behaviour the Servlet specifications prescribes and we follow.

    I just did a quick test on WLS 12c and saw it getting called once per deployment/activation of the web module.
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package sab.demo.otn2377518;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import javax.servlet.annotation.WebListener;
    
    /**
     * Web application lifecycle listener.
     *
     * @author sbutton
     */
    @WebListener()
    public class TestContextListener implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            System.out.printf("%s:%s\n",
                    this.getClass().getName(),
                    getMethodName());
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
            System.out.printf("%s:%s\n",
                    this.getClass().getName(),
                    getMethodName());
        }
        
        private String getMethodName() {
            return  Thread.currentThread().getStackTrace()[2].toString(); 
        }
            
    }
    <Apr 23, 2012 5:48:38 PM CST> <Notice> <LoggingService> <BEA-320401> <The log file has been rotated to /Users/sbutton/Java/wls-1211update-dev/domain/servers/AdminServer/logs/access.log00163. Log messages will continue to be logged in /Users/sbutton/Java/wls-1211update-dev/domain/servers/AdminServer/logs/access.log.>
    <Apr 23, 2012 5:48:40 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY.>
    <Apr 23, 2012 5:48:40 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>
    ...
    sab.demo.otn2377518.TestContextListener:sab.demo.otn2377518.TestContextListener.contextInitialized(TestContextListener.java:21)
    <Apr 23, 2012 5:48:51 PM CST> <Notice> <LoggingService> <BEA-320400> <The log file /Users/sbutton/Java/wls-1211update-dev/domain/servers
    ...
    <Apr 23, 2012 5:48:52 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
    <Apr 23, 2012 5:48:52 PM CST> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
    >

    If you are using OEPE, then I wonder if you have auto-publishing set to true so that any changes you make to the application in OEPE are resulting in automatic republishing of the application, which will restart the web
    module to pick up the change and thus call this listener method each time?

    -steve-
  • 2. Re: weblogic, eclipse plugin, ServletContextListener
    931605 Newbie
    Currently Being Moderated
    Thanks Steve for the information - it now looks like the code is working properly. I tried a project from scratch and the servlet listener code only executes once. I must have configured something incorrectly.

    Edited by: 928602 on Apr 24, 2012 2:20 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points