getting a handle on ServletContext so I can grab my Spring beans

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

getting a handle on ServletContext so I can grab my Spring beans

devnewb
Hi Guys.

I have just started playing with Unfiltered.  Is there a way I can get a handle on ServletContext so I can use my Spring Beans ?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: getting a handle on ServletContext so I can grab my Spring beans

n8han
Administrator
You should be able to use Spring's built in Filters that create a context around the request. Just be sure it is in the filter chain before your application filter, whether you're configuring with a web.xml or unfiltered's interfaces to embedded Jetty.

If that doesn't work you would need to establish the context yourself, and I know that's possible because I've done it for Wicket request cycles in the past, but the standard Filter approach should work. If it doesn't we'll figure out why and fix it.

Nathan
Reply | Threaded
Open this post in threaded view
|

Re: getting a handle on ServletContext so I can grab my Spring beans

devnewb
Thanks for your help, will try this out when back from holiday later in the week.
Reply | Threaded
Open this post in threaded view
|

Re: getting a handle on ServletContext so I can grab my Spring beans

Dustin Whitney
I just did this very thing to set the max form content size - it's ugly, but it works:

//set the maximum size post for a form
    for(handler <- server.underlying.getHandlers){
      if(handler.isInstanceOf[ContextHandlerCollection]){
        for(h <- handler.asInstanceOf[ContextHandlerCollection].getHandlers){
          if(h.isInstanceOf[ServletContextHandler]){
            h.asInstanceOf[ServletContextHandler].setMaxFormContentSize(...)
          }
        }
      }
    }

On Mon, Nov 22, 2010 at 12:38 PM, devnewb [via Databinder] <[hidden email]> wrote:
Thanks for your help, will try this out when back from holiday later in the week.



Reply | Threaded
Open this post in threaded view
|

Re: getting a handle on ServletContext so I can grab my Spring beans

devnewb
Thanks, thats very useful.  Agreed though, it is a bit long winded.  Until a better alternative presents itself I will use it.
Reply | Threaded
Open this post in threaded view
|

Re: getting a handle on ServletContext so I can grab my Spring beans

devnewb
In reply to this post by n8han
Sorry guys, unable to get a lead here... just inexperience probably.  Does anyone have any sample code pulling in a simple Spring bean ?

Thanks for your help.