Mapping commonj work manager with weblogic work manager fails with NameNotFoundException

636 Views Asked by At

I have a (weblogic) singleton service that uses the commonj workManagerTaskExecutor to execute a task. I also have a work manager defined in my weblogic console with the name MyWorkManager. Now I am trying to map the commonj Work manager to the work manager in Weblogic so that I can use it in the workManagerTaskExecutor. But lookup of this workmanager fails in my application code with NameNotFoundException unable to find the workmanager.

I tried iterating through the initial context object and couldn't find the workmanager registered in it either.

I am using Weblogic 10.3 and am completely new to this. What am I doing wrong? please help me out.

public class MySingletonService implements weblogic.cluster.singleton.SingletonService {

private ApplicationContext applicationContext;

private void loadApplicationContext() {
    applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
}

public MySingletonService() {
    System.out.println("MySingletonService Object Initialized...");
}

public void activate() {
    try {
        loadApplicationContext();

        Runnable xy = new Runnable() {

            public void run() {
                if (applicationContext != null) {
                    runSomething();
                } else {
                    System.out.println("Application context is not initialized");
                }
            }
        };

        InitialContext ic = new InitialContext();
        WorkManager wm = (WorkManager)ic.lookup("java:comp/env/wm/MyWorkManager"); // this fails
        WorkManagerTaskExecutor taskExecutor = new WorkManagerTaskExecutor();
        taskExecutor.setWorkManager(wm);
        taskExecutor.execute(xy);
    } 
    catch (Exception ex) {

        ex.printStackTrace();
        deactivate();
        throw new RuntimeException("MySingletonService.activate()",ex);
    }
}

public void deactivate() {
    doSomething();
}
}

weblogic-application.xml

<work-manager>
<name>wm/MyWorkManager</name>
</work-manager>

web.xml

    <resource-ref>
    <res-ref-name>wm/MyWorkManager</res-ref-name>
    <res-type>commonj.work.WorkManager</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
0

There are 0 best solutions below