10 Replies Latest reply on Sep 13, 2002 2:50 AM by sgturner

    HELP!! Servlet WAR cannot read factories

    jparks

      Jboss3.0 with Tomcat 4

      I have a startup Mbean that loads a bunch of factories at startup. I also have a Servlet that I deploy as a war. Here is the problem: It seems that the Servlet cannot access the Factories. It keeps getting null values back.

      Why can't the servlet access factories that I know are there (all of my startup ojects use the factories)?

      What is the work around?

      Please help - Friday is my last day to prove to my team and managers taht JBOSS is viable against our currently working Weblogic solution (I am porting over our stuff as a proof of concept).

      Thanks so much for all of you that have have helped me so far, and advance thanks for this help!

        • 1. Re: HELP!! Servlet WAR cannot read factories
          joelvogt

          how are you trying to access them?

          • 2. Re: HELP!! Servlet WAR cannot read factories
            jparks

            Directly from the servlet ->

            Servlet does a FactoryA.makeInstance().methodX() call

            The factories are not deployed in both packages - here is a psuedo snippet of what I am doing :

            again - Servlet is deployed as a WAR

            Startup MBEan:

            FactoryA is packaged in stuff_classes.jar and dropped in ../default/lib

            1. create and call FactoryA's configurator FactoryAConfigurator.

            2. FactoryAConfigurator does a FactoryA.makeInstance().setArguments();

            3. FactoryA spits out a bunch of "I am alive messages"

            4. When I make a call to the servlet, it in turn makes a call to FactoryA.makeInstance().configLocation() which should return the location ("/opt/config/") but instead returns null. This value is correct in the factory (other factories use this factory - and the all succeed)

            I currently have no classpath's set - instead relying on ../default/deply and ../default/lib

            • 3. Re: HELP!! Servlet WAR cannot read factories
              sgturner

              Yea, I'm confused as well as to how you think you are accessing any of the factories created by the MBean. What does makeInstance() do? If the name of the method can be believed, you are making a new instance of something and not refering to what the MBean created.

              • 4. Re: HELP!! Servlet WAR cannot read factories
                jparks

                Factories by their decree are Singleton's. Therefore, the call to a factories makeInstance() just returns the single instance of the factory.

                public class FactoryA {

                private FactoryA () {
                "..do constructor stuff"
                }

                public synchronized static FactoryA makeInstance()
                {
                if (myInstance == null)
                {
                myInstance = new FactoryA();
                }
                return myInstance;
                }

                //private members
                private static FactoryA myFactory = null;

                This code has worked in production with Weblogic for several years. I suspect that either the Servlet is not packaged right in the WAR, though I can tickle it, or that for some reason it is in a different JVM then those of the singleton's...but that wouldn't make any sense.

                • 5. Re: HELP!! Servlet WAR cannot read factories
                  sgturner

                  OK. I see what the problem is, but don't know the solution. I hope you are aware that it is entirely possible to have multiple instances of the same static in a single JVM. Its because, every object instance relates back to it Class object which in turn relates back to the ClassLoader instance that created the Class object and because the Factory object in the servlet has a different class loader than the one in the MBean. Your WebLogic server obviously has a different class loader architecture than JBoss which allows it to work there. Without knowing anymore about the purpose of the Factory objects, its impossible to say what would be a good solution.

                  • 6. Re: HELP!! Servlet WAR cannot read factories
                    sgturner

                    One possible solution would be to throw out the Factories and change the MBean to provide whatever functionality the Factories now provide. Then, anywhere in your app you can talk to the MBean thru the MBeanServer.

                    • 7. Re: HELP!! Servlet WAR cannot read factories
                      sgturner

                      I think you could confirm my diagnosis by putting this line of code in both the servlet and MBean. If the output differs, my diagnosis is correct.

                      System.out.println (Factory.getClass().getClassLoader().getName());

                      • 8. Re: HELP!! Servlet WAR cannot read factories
                        sgturner

                        Try this instead:

                        System.out.println (Factory.getInstance().getClass().getClassLoader().getName());

                        • 9. Re: HELP!! Servlet WAR cannot read factories
                          jparks

                          I got it working, and it works just fine. The problem (as is usually the case) was me being stupid. I am new to MBeans and how they receive and pass arguments that they are declared with. A typo plus a mis-interpretation of the MBean set method was the culprit.

                          I need to support my application on both Weblogic and JBoss - therefore I do not want to make wholesale changes that will cause code management issues.

                          Thanks to all of you for your help- I have learned a lot!

                          • 10. Re: HELP!! Servlet WAR cannot read factories
                            sgturner

                            You are welcome. From your response, I guess I misdiagnosed your problem. Oh well. Glad you got it working.