PicoContainer
  1. PicoContainer
  2. PICO-123

proposed org.picoextras.servlet.ServletRequestContainerFilter

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-5
    • Fix Version/s: None
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Environment:
      Any Servlet Container
    • Number of attachments :
      1

      Description

      The picoextras servlet stuff is very nice, and the ServletContainerListener makes the creation of containers for the context and session nice and automatic. For requests, however, one has to manually use the ServletRequestContainerLauncher to create request containers and remember to call startContainer() at the beginning of request handling and killContainer() at the end. Why not make this automatic as well? Servlet filters to the rescue!

      I've create a filter to perform this magic as well so that the only thing a user ever needs to do is implement a ContainerComposer to register their components and then use those components. I will attach it right after this post. BTW, here is what the web.xml config might look like (btw, note the change in the context param name based on the patch I just attached to Pico Issue 116)...

      <web-app>
      <context-param>
      <param-name>picoextras-container-composer</param-name>
      <param-value>org.picoextras.servlet.sample.SampleContainerComposer</param-value>
      </context-param>

      <listener>
      <listener-class>org.picoextras.servlet.ServletContainerListener</listener-class>
      </listener>

      <filter>
      <filter-name>pico</filter-name>
      <filter-class>org.picoextras.servlet.ServletRequestContainerFilter</filter-class>
      </filter>

      <filter-mapping>
      <filter-name>pico</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>
      </web-app>

        Activity

        Hide
        Jacob Kjome added a comment -

        proposed ServletRequestContainerFilter.java to ease the burden of creating and killing request-scoped containers.

        Jake

        Show
        Jacob Kjome added a comment - proposed ServletRequestContainerFilter.java to ease the burden of creating and killing request-scoped containers. Jake
        Jacob Kjome made changes -
        Field Original Value New Value
        Attachment ServletRequestContainerFilter.java [ 11360 ]
        Hide
        Jacob Kjome added a comment -

        Oh, I almost forgot. Before someone calls me on it, I better make sure to credit whoever wrote the sourcecode in PICO-73 (Thomas Heller?). The servlet filter is based of of that work. In fact, it is nearly identical in structure except it uses the the code from the current CVS to build/kill the container. If you want to add Heller's name to the author list, that's fine with me. Might also think about using the counter example as a reference sample usage of the servlet stuff. It was helpful for me in figuring stuff out.

        Jake

        Show
        Jacob Kjome added a comment - Oh, I almost forgot. Before someone calls me on it, I better make sure to credit whoever wrote the sourcecode in PICO-73 (Thomas Heller?). The servlet filter is based of of that work. In fact, it is nearly identical in structure except it uses the the code from the current CVS to build/kill the container. If you want to add Heller's name to the author list, that's fine with me. Might also think about using the counter example as a reference sample usage of the servlet stuff. It was helpful for me in figuring stuff out. Jake
        Hide
        Paul Hammant added a comment -

        Jake, any chance you could make a wiki page to indtroduce the filter and give a couple of examples of use. Clearly your half way there with the wordage above. We credit authors on docs pages too

        Show
        Paul Hammant added a comment - Jake, any chance you could make a wiki page to indtroduce the filter and give a couple of examples of use. Clearly your half way there with the wordage above. We credit authors on docs pages too
        Paul Hammant made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Hide
        Thomas Heller added a comment -

        hi, yeah I did that filter.

        Just for a heads-up. I'm using the filter for quite some time now with a slightly modified servlet framework (no session containers) and one thing you should put into the docs/notes is that it is very important to watch in which order you put your filters in the web.xml. I had a very annoying time when I tried to find out why my filter didn't filter correclty until I found out that I messed up the order (Note: I got 2 filters, 1 pico and 1 that uses pico). Of course this only applies when you got multiple filters.

        Anyways, I thought this might be helpful.

        Show
        Thomas Heller added a comment - hi, yeah I did that filter. Just for a heads-up. I'm using the filter for quite some time now with a slightly modified servlet framework (no session containers) and one thing you should put into the docs/notes is that it is very important to watch in which order you put your filters in the web.xml. I had a very annoying time when I tried to find out why my filter didn't filter correclty until I found out that I messed up the order (Note: I got 2 filters, 1 pico and 1 that uses pico). Of course this only applies when you got multiple filters. Anyways, I thought this might be helpful.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jacob Kjome
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: