4 Replies Latest reply on Mar 24, 2009 3:15 PM by reneger

    No application context when instantiating

    reneger
      I'm using an HTTP servlet in my SEAM project. This is for the communication with a bunch of devices, the actual SEAM pages e.g. are used for the administration login.

      The servlet is defined as follow:
      public class RdmHttpServlet extends HttpServlet{

      which works great. The servlet is added in the web.xml and is started on Jboss start.
      But when i try to instantiate a DAO, i get an "No application context active" exception.
      The instantiation is done with
      final PhysicalDeviceDAO physicalDeviceDAO = (PhysicalDeviceDAO) Component.getInstance("physicalDeviceDAO");
      which works fine from the seam context.
      What do i miss?

      I'm using the following configuration:
      Jboss 4.2.3
      Seam 2.1.1 GA
      Java 1.6.0_11

      Many thanks in advance.

      René
        • 1. Re: No application context when instantiating
          chawax

          Try the following :


          Component component = Component.componentForName("physicalDeviceDAO");
          PhysicalDeviceDAO physicalDeviceDAO = (PhysicalDeviceDAO) component.newInstance();


          • 2. Re: No application context when instantiating
            reneger

            Component.componentForName isn't available in my config...

            • 3. Re: No application context when instantiating
              chawax

              Not available ? I can't understand, it is part of Seam core ! Did I miss something ?

              • 4. Re: No application context when instantiating
                reneger
                I dont know, i couldn't find the function anywhere.

                But i've found the solution. I wrapped the servletrequest in my own ContextualServletRequest, found somewhere on the internet (http://sfwk.org/Documentation/ReplacingServletsWithSeamResources)

                public class RdmHttpServlet extends HttpServlet{

                    @Logger
                    private static Log log;

                    private static final long serialVersionUID = -1859937460510960239L;

                    /**
                     *  XML Processor.
                     */
                    protected Processor processor = Processor.getInstance();

                    protected void service(final HttpServletRequest request, final HttpServletResponse response)
                    throws ServletException, IOException {

                        new ContextualHttpServletRequest(request) {
                            @Override
                            public void process() throws Exception {
                                handleRequest(request, response);
                            }
                        }.run();
                    }

                The handlerequest is the old function which was called by the doGet and doPost functions.
                The handlerequest is now a Seam object, and therefore i can get my instances for my DAO's.