Setting up a CommonJ Timer Manager in Websphere

1.1k views Asked by At

In the Web.xml I have:

<resource-ref>
    <res-ref-name>java:/comp/env/tm/TimerManager</res-ref-name>
    <res-type>commonj.timers.TimerManager</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>

In the java code I have:

    TimerManager tm = (TimerManager) ic.lookup("tm/TimerManager");
tm.schedule(new CleanupListener(), 0, 10*1000); // CleanupListener class is my TimerListener

So when I run the code, the Timer kick in successfully but right after the code crash with the following exception:

javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: java

I have no idea why. when I change the lookup with this: TimerManager tm = (TimerManager) ic.lookup("java:/comp/env/tm/TimerManager"); This is even worst, the Timer never kick in and I do have this following exception: db.common.util.ServiceLocatorException: javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: java

Please help, very important. Thanks

3

There are 3 answers

2
njr On

Try using

java:comp/env/tm/TimerManager

in place of

java:/comp/env/tm/TimerManager

If that doesn't help. please post your full deployment descriptor and bindings file (web.xml and either ibm-web-bnd.xml or ibm-web-bnd.xmi) to ensure that the configuration within this files is correct.

Thanks for posting the files. I think the problem is that web.xml version 3.0 is not compatible with ibm-web-bnd.xmi. Try either using web.xml version 3.0 with ibm-web-bnd.xml, or otherwise use an earlier version web.xml with ibm-web-bnd.xmi.

0
user3648235 On

Here is the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>testApp</display-name>

    <welcome-file-list>
        <welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>

    <listener>
        <listener-class>
            or.tc.pack.context.listener.TestWebContextListener
        </listener-class>
    </listener>

    <!-- The master configuration file for this Spring web application -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/context/testway/webApplication-config-local.xml
        </param-value>
    </context-param>

    <!-- Loads the Spring web application context -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/services/eng/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/services/fra/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>480</session-timeout>
    </session-config>

    <resource-ref id="ResourceRef_1288099140976">
        <description>
        Business Update queue</description>
        <res-ref-name>jms/ZZZZ_ZZ_ZZZZ_BUS_UPD</res-ref-name>
        <res-type>javax.jms.Queue</res-type>
        <res-auth>Application</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

    <resource-ref>
        <description>
        </description>
        <res-ref-name>java:comp/env/tm/TimerManager</res-ref-name>
        <res-type>commonj.timers.TimerManager</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Unshareable</res-sharing-scope>
    </resource-ref>

</web-app>

Here is the ibm-web-bnd.xmi:

<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1263831088044">
  <webapp href="WEB-INF/web.xml#WebApp_ID"/>
  <resRefBindings xmi:id="ResourceRefBinding_1288099140976" jndiName="customs/commercial/tal/jms/ZZZZ_ZZ_ZZZZ_BUS_UPD">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1288099140976"/>
  </resRefBindings>
</webappbnd:WebAppBinding>
0
Simon Logic On

You reverted valid syntax.

Within web.xml:

<res-ref-name>tm/TimerManager</res-ref-name>

Within source code:

ic.lookup("java:comp/env/tm/TimerManager")