Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: why <flex:message-broker> tag broke all the URL Handler Mapping

  1. #11

    Default

    I just tried a couple of things and messed around in my web.xml and now I don't know if I ever understood this url-pattern stuff inside the servlet-mapping. I just replaced my MessageBroker mapping with this:

    Code:
    <servlet-mapping>
    	<servlet-name>dispatcherServlet</servlet-name>
    	<url-pattern>/messagebroker/amf</url-pattern>
    </servlet-mapping>
    And now the mvc-stuff and my MessageBroker are working. As soon as I replace 'amf' with a '*' the MessageBroker stops working. That is kinda inexplicable to me because I can see that the DispatcherServlet is called when the DispatcherServlet tells me he finds no mapping, so the servlet-mapping should be be ok even with the '*' in it.

  2. #12
    Join Date
    Sep 2007
    Location
    Hamburg, Germany
    Posts
    54

    Default

    In a recent project i found out that you have to define a bean of type UrlPathHelper and set its property "alwaysUseFullPath" to true and set this UrlPathHelper to all your (Url)HandlerMappings.

    BTW:

  3. #13

    Default

    Yeah that really did the trick. Unfortunality the HandlerMapping that gets created by the MessageBrokerBeanDefinitionParser only has the default UrlPathHelper. There should really be a way to customize the UrlPathHelper or to specify a use-full-path="true" for the flex:message-broker configuration.

  4. #14
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Setting alwaysUseFullPath shouldn't be necessary. I've always been able to make things work without it. The only case I can think of where you might need it is if you are on a Servlet container that is returning odd values for things like request.getServletPath.

    If you really did need to go that far in customizing the HandlerMapping, you can turn off the default mapping behavior through the "disable-default-mapping" attribute and then providing your own SimpleUrlHandlerMapping. Something like:

    Code:
    <flex:message-broker disable-default-mapping="true" />
    	
    <bean id="mapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="alwaysUseFullPath" value="true"/>
        <property name="mappings">
            <value>
                /messagebroker/*=_messageBroker
    	</value>
        </property>
    </bean>
    I'm confused as to why you were trying to map "/messagebroker/*" in web.xml if you're trying to map both the MVC controllers and MessageBroker. I would think you'd use something more generic like "/app/*" or even just "/" (in conjunction with the relatively new default-servlet-handler support). I'm wondering if you're confusing things a bit. And are you appropriately compensation for your mapping changes in services-config.xml?
    Last edited by jeremyg484; Dec 8th, 2010 at 05:50 PM. Reason: Mistake in <flex:message-broker> example.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  5. #15

    Default

    Yeah, I'm more confused with this whole configuration thing than I was ever before. Until now I only used extension mappings inside my web.xml to map things like *.html to my DispatcherServlet and have a ViewResolver return a .jsp view so that the default JspServlet can render my view. That always worked for me because all my controllers had this exact extensions, no matter how complex some patterns of my HandlerMapping may have been. Everytime I put something like /* or / in my web.xml it'll override every extension mapping, even the *.jsp mapping of the default JspServlet. And until today I didn't knew that the DispatcherServlet won't get the full path for a mappings like /app/* unless you tell the HandlerMapping to always use the full path. But you're right, with the /app/* mapping I could get everything mapped to my servlet and even get the views dispatched to the default JspServlet (unless I don't put them in /app/) ... maybe I'll go with this. But as far as I understand, I then have to use rewrites to hide the /app/ from my urls, right?

  6. #16
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Ok, I see where some of the confusion might be coming from then. In web.xml, were you still trying to use both the extension mappings (i.e., *.html) and the path-based mappings? If that's the case, then I can see how alwaysUseFullPath might be necessary.

    There are actually some recent enhancements to MVC (that I worked on) that first landed in the 3.0.4 release that allow you to map your servlet to "/" while still preserving the behavior of the container's JspServlet and default servlet. Basically you just need to include:

    Code:
    <mvc:default-servlet-handler />
    and requests for static resources and JSP rendering will still get forwarded correctly when you map the DispatcherServlet to "/".

    Further background on that is here:
    http://static.springsource.org/sprin...ervlet-handler

    Also, for easiest results, I'd suggest configuring it in conjunction with:

    Code:
    <mvc:annotation-driven />
    so that you don't have to manually manage the DefaultAnnotationHandlerMapping, etc.

    More info on that here:
    http://static.springsource.org/sprin...otation-driven

    This is the approach that Roo-generated apps now use, and the Flex Addon sets up the MessageBroker within the same DispatcherServlet context, so that might be one way to see a complete example of this approach.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  7. #17
    Join Date
    May 2010
    Posts
    1

    Default

    When I encountered this, I found another way to solve this:

    I added this to my applicationContext, which restored all my bean handler mappings:

    Code:
    	<bean id="beanNameUrlHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
    	<bean id="controllerHandlerAdapter" class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

Posting Permissions

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