3 Replies Latest reply on Feb 6, 2008 11:51 AM by Christian Bauer

    Context management for custom servlets

    thatrichard Newbie

      I'm using Seam-2.0.0.Beta1. According to the docs:

      25.1.4.6. Context management for custom servlets

      ...Seam provides a servlet filter that can be applied to any other servlet that needs access to Seam components.

      This filter allows custom servlets to interact with the Seam contexts. It sets up the Seam contexts at the beginning of each request, and tears them down at the end of the request


      I'm reading this as saying that I can configure Seam to inject components into a simple on-JSF servlet.

      The relevant bits of my servlet are as follows:
      @Name("documentDownloader")
      public class DocumentDownloadServlet extends HttpServlet {
      
       @Logger
       private Log log;
      
       @In( create=true )
       private Session hibernateSession;
      
       @Override
       protected void doGet( HttpServletRequest request, HttpServletResponse response )
       throws ServletException, IOException {
      
      //etc.
      


      My components.xml file contains

      <components xmlns="http://jboss.com/products/seam/components"
      ...
       xmlns:web="http://jboss.com/products/seam/web"
      ...
      >
      <web:context-filter url-pattern="/dimmer/dim/*" />


      However, no injection is taking place.

      What am I doing wrong?

      Thanks

      Richard

        • 1. Re: Context management for custom servlets
          Pete Muir Master

           

          "thatrichard" wrote:
          I'm using Seam-2.0.0.Beta1. According to the docs:

          25.1.4.6. Context management for custom servlets

          ...Seam provides a servlet filter that can be applied to any other servlet that needs access to Seam components.

          This filter allows custom servlets to interact with the Seam contexts. It sets up the Seam contexts at the beginning of each request, and tears them down at the end of the request


          I'm reading this as saying that I can configure Seam to inject components into a simple on-JSF servlet.


          No, it just sets up the context - no injection is available - you'll have to get Seam components programatically e.g. using Component.getInstance() or Logging.getLog()

          • 2. Re: Context management for custom servlets
            Paul Connor Newbie

            Not sure how realistic this suggestion is... is it possible for a future release to support injection in a custom servlet? If so, are there any plans to support add that capability?

            • 3. Re: Context management for custom servlets
              Christian Bauer Master

              Why would Seam support that? With lookup through Component.getInstance(), I can easily unit test methods of my servlet, even without running the servlet in an actual servlet container, just instantiating it in a SeamTest. If I'd use injection, I'd have to run a servlet container that has the special injection magic.