Results 1 to 3 of 3

Thread: Problems mapping DispatcherServlet with "/*" url p

Hybrid View

  1. #1

    Default Problems mapping DispatcherServlet with "/*" url p

    I want to create a webapplication which examines the url for every external http request, and then compares that url to a list of urls in a database table. If a match is found in the database an appropriate ModelAndView is returned.

    The problem is how do I configure the DispatcherServlet in the web.xml file so that it gets a chance to examine every incoming request? If I specify "/*" as the url-pattern in the servlet mapping then I end up with an infinite loop. I haven't looked at the code, but presumably when my Controller returns a ModelAndView, Spring does a dispatch and because of the mapping the same DispatcherServlet get calls.

    Note I really don't want to have to limit myself to urls that begin with a specific prefix, or end with a specific postfix (eg. .do). That's one of the major objectives of the web application.

    While the problem isn't completely Spring specific, its made more difficult by the fact that Spring's web framework provides a DispatcherServlet rather than a DispatcherServletFilter. If Spring provided a DispatcherServletFilter it would be fairly trivial since servlet filter mappings can be specified for incoming urls only (and not when dispatching).

    Does anyone have an elegant way to fix the infinite loop problem? The only idea I have so far is to specify the servlet mapping for the ServletDispatcher using a url-pattern like "/myprefix/*", and then create a ServletFilter with a url mapping of "/*". The servlet filter would basically extract the incoming url, preappend the "/myprefix" prefix and use the resulting string to dispatch the request to Spring Dispatcher. Kinda of ugly, but it might work.

    I'm fairly new to Spring MVC, so I'm hoping there is a better way. Any other ideas would be greatly appreciated.

    /Scott

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    I think it is possible to create a filter that extends org.springframework.web.filter.OncePerRequestFilte r. The filter can get access to Spring contexts using org.springframework.web.context.support.WebApplica tionContextUtils, checks the request against your database, and then dispatchs the request to Spring Dispatcher. This way, you do not need to change the url-pattern for DispatcherServlet.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    May 2008
    Posts
    4

    Default Hi did you find a solution for that?

    Hi did you find a solution for that?
    Thanks

    Quote Originally Posted by scott69taylor View Post
    I want to create a webapplication which examines the url for every external http request, and then compares that url to a list of urls in a database table. If a match is found in the database an appropriate ModelAndView is returned.

    The problem is how do I configure the DispatcherServlet in the web.xml file so that it gets a chance to examine every incoming request? If I specify "/*" as the url-pattern in the servlet mapping then I end up with an infinite loop. I haven't looked at the code, but presumably when my Controller returns a ModelAndView, Spring does a dispatch and because of the mapping the same DispatcherServlet get calls.

    Note I really don't want to have to limit myself to urls that begin with a specific prefix, or end with a specific postfix (eg. .do). That's one of the major objectives of the web application.

    While the problem isn't completely Spring specific, its made more difficult by the fact that Spring's web framework provides a DispatcherServlet rather than a DispatcherServletFilter. If Spring provided a DispatcherServletFilter it would be fairly trivial since servlet filter mappings can be specified for incoming urls only (and not when dispatching).

    Does anyone have an elegant way to fix the infinite loop problem? The only idea I have so far is to specify the servlet mapping for the ServletDispatcher using a url-pattern like "/myprefix/*", and then create a ServletFilter with a url mapping of "/*". The servlet filter would basically extract the incoming url, preappend the "/myprefix" prefix and use the resulting string to dispatch the request to Spring Dispatcher. Kinda of ugly, but it might work.

    I'm fairly new to Spring MVC, so I'm hoping there is a better way. Any other ideas would be greatly appreciated.

    /Scott

Similar Threads

  1. Replies: 5
    Last Post: Jan 5th, 2009, 11:23 AM
  2. URL mapping, why don't I get it?
    By cerebis in forum Web
    Replies: 6
    Last Post: Oct 10th, 2005, 04:31 PM
  3. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  4. Initialization of Connection Provider fails
    By DEVRocker in forum Data
    Replies: 2
    Last Post: Aug 9th, 2005, 10:14 AM
  5. Replies: 13
    Last Post: Dec 7th, 2004, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •