Announcement Announcement Module
Collapse
No announcement yet.
why <flex:message-broker> tag broke all the URL Handler Mapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    I want to add spring blazeDS support into current spring website. This is what I did:

    I added
    <flex:message-broker></flex:message-broker>
    tag to applicationContext.xml, now the flex can access all the <flex:remoting-destination /> annoted service, but unfortunately, all the previousely defined URL handler mapping is broken. Whenever I remove the <flex:message-broker> tag, all the URL mapping is back to work.

    Can anyone tell me how to add <flex:message-broker> tag to current applicaitonContext setting without breaking current URL handler mapping?

    Thanks

  • #2
    I assume you are just using a single DispatcherServlet? If so, you need to give a more specific mapping for the MessageBroker, as by default it uses a mapping of /*.

    Something like:
    Code:
    <flex:message-broker>
        <flex:mapping pattern="/messagebroker/*" />
    </flex:message-broker>

    Comment


    • #3
      I'm having trouble configuring spring-flex with just a single DispatcherServlet. No matter what I do, he keeps telling me:
      No mapping found for HTTP request with URI [<Context-Path>/messagebroker/amf]

      The index.html mapped to my IndexController works normal though and the startup log states he mapped /messagebroker/* to the MessageBroker. So what am I missing?

      web.xml
      Code:
      <servlet>
          <servlet-name>dispatcherServlet</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>/WEB-INF/config/applicationContext.xml</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
      </servlet>
      
      <servlet-mapping>
          <servlet-name>dispatcherServlet</servlet-name>
          <url-pattern>*.html</url-pattern>
      </servlet-mapping>
      
      <servlet-mapping>
          <servlet-name>dispatcherServlet</servlet-name>
          <url-pattern>/messagebroker/*</url-pattern>
      </servlet-mapping>
      applicationContext.xml
      Code:
      <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
      <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
      
      <context:component-scan base-package="spring.controller"/>
      
      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
          <property name="prefix" value="/WEB-INF/views/"/>
          <property name="suffix" value=".jsp"/>
      </bean>
      
      <flex:message-broker>
          <flex:mapping pattern="/messagebroker/*"/>
          <flex:message-service default-channels="my-amf"/>
      </flex:message-broker>
      Startup log
      Code:
      21:27:07,333 INFO  (org.springframework.web.servlet.FrameworkServlet [initServletBean]:302) - FrameworkServlet 'dispatcherServlet': initialization started
      21:27:07,363 INFO  (org.springframework.context.support.AbstractApplicationContext [prepareRefresh]:454) - Refreshing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Mon Dec 06 21:27:07 CET 2010]; root of context hierarchy
      21:27:07,403 INFO  (org.springframework.beans.factory.xml.XmlBeanDefinitionReader [loadBeanDefinitions]:315) - Loading XML bean definitions from ServletContext resource [/WEB-INF/config/applicationContext.xml]
      21:27:07,703 INFO  (org.springframework.beans.factory.support.DefaultListableBeanFactory [preInstantiateSingletons]:537) - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e90943: defining beans [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,indexController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,viewResolver,_messageBrokerHandlerAdapter,_messageBrokerDefaultHandlerMapping,_jsonConfigMapEditorConfigurer,_messageBrokerMessagingProcessor,_messageBrokerRemotingProcessor,_flexRemotingAnnotationPostProcessor,_hibernateSerializationConfigPostProcessor,org.springframework.flex.core.ExceptionTranslationAdvice#0,org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#0,org.springframework.flex.core.MessageInterceptionAdvice#0,org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1,_messageBrokerEndpointProcessor,_messageBroker,chatAdapter,chat,org.springframework.flex.core.io.JpaHibernateConfigProcessor#0]; root of factory hierarchy
      21:27:07,804 INFO  (org.springframework.flex.config.FlexConfigurationManager$ResourceResolverAdapter [getConfigurationFile]:184) - Loading Flex services configuration from: ServletContext resource [/WEB-INF/flex/services-config.xml]
      21:27:08,004 INFO  (org.springframework.flex.config.FlexConfigurationManager$ResourceResolverAdapter [getIncludedFile]:199) - Including Flex services configuration from: ServletContext resource [/WEB-INF/flex/messaging-config.xml]
      21:27:08,064 INFO  (org.springframework.flex.config.FlexConfigurationManager$ResourceResolverAdapter [getIncludedFile]:199) - Including Flex services configuration from: ServletContext resource [/WEB-INF/flex/remoting-config.xml]
      21:27:08,114 INFO  (org.springframework.flex.config.FlexConfigurationManager$ResourceResolverAdapter [getIncludedFile]:199) - Including Flex services configuration from: ServletContext resource [/WEB-INF/flex/proxy-config.xml]
      21:27:08,304 INFO  (org.springframework.flex.core.MessageBrokerFactoryBean [afterPropertiesSet]:152) - BlazeDS - Community Edition: 4.0.0.14931
      21:27:08,384 INFO  (org.springframework.flex.core.MessageBrokerFactoryBean [afterPropertiesSet]:162) - MessageBroker with id '_messageBroker' is starting.
      21:27:08,654 INFO  (org.springframework.flex.core.MessageBrokerFactoryBean [afterPropertiesSet]:181) - MessageBroker with id '_messageBroker' is ready (startup time: '270' ms)
      21:27:08,664 INFO  (org.springframework.web.servlet.handler.AbstractUrlHandlerMapping [registerHandler]:397) - Mapped URL path [/index.html] onto handler [spring.controller.IndexController@1e22632]
      21:27:08,744 INFO  (org.springframework.web.servlet.handler.AbstractUrlHandlerMapping [registerHandler]:397) - Mapped URL path [/messagebroker/*] onto handler [flex.messaging.MessageBroker@5f1ba8]
      21:27:08,775 INFO  (org.springframework.web.servlet.FrameworkServlet [initServletBean]:321) - FrameworkServlet 'dispatcherServlet': initialization completed in 1442 ms
      Thanks

      Comment


      • #4
        I did not test your setting, but you can following this minimum steps:
        1. web.xml
        <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <servlet>
        <servlet-name>flex</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
        <servlet-name>flex</servlet-name>
        <url-pattern>/spring/*</url-pattern>
        </servlet-mapping>


        </web-app>

        2. flex-servlet.xml
        <flex:message-broker >
        <flex:message-service
        default-channels="my-polling-amf, my-streaming-amf" />
        </flex:message-broker>

        <bean id="petStoreService" class="org.springframework.samples">
        <flex:remoting-destination />
        </bean>

        3. don't forget to put service-config.xml under web-inf/flex directory

        that's it!

        You can set a simple flex app to test, this is what I use;


        <fx:Script>
        <![CDATA[
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        private function init():void{
        ro.getAge("Frank");
        }
        private function resultHandler(event:ResultEvent):void{


        trace ("received" + event.result);

        }
        private function faultHandler(event:FaultEvent):void{
        trace ("worng");
        }
        ]]>
        </fx:Script>

        <fxeclarations>
        <mx:RemoteObject id="ro"
        destination="petStoreService"
        endpoint="http://localhost:8080/spring/amf"
        result="resultHandler(event)"
        fault="faultHandler(event)"/>
        </fxeclarations>

        Comment


        • #5
          But that way none of my spring controllers will work, because spring-flex maps everything to the MessageBroker. I can even get my setting to work that way, when I just remove this single line:
          <flex:mapping pattern="/messagebroker/*"/>

          But again, none of the spring controllers will work. But I need spring-mvc and spring-flex to work together in just one context.

          Comment


          • #6
            Why must be in one context?
            The simplest solution is to use two seperate context setting, one application-context.xml and flex-servlet.xml file

            Comment


            • #7
              Because I need to access flex channels from my mvc-context to push things to flex clients when someone calls specific webservices and/or controller, etc.

              Comment


              • #8
                This may explain how to do:
                http://static.springsource.org/sprin...and-spring-mvc

                Comment


                • #9
                  Originally posted by Peacemaker2000 View Post
                  I'm having trouble configuring spring-flex with just a single DispatcherServlet. No matter what I do, he keeps telling me:
                  No mapping found for HTTP request with URI [<Context-Path>/messagebroker/amf]
                  I would guess it's an ordering problem. Both the DefaultAnnotationHandlerMapping, and the HandlerMapping that gets registered by the <flex:message-broker> have the default precedence of MAX_INTEGER (which is essentially the same as being non-ordered and then it comes down to which bean got registered first, basically). Something like this should do the trick:

                  Code:
                  <flex:message-broker mapping-order="0">
                      <flex:mapping pattern="/messagebroker/*"/>
                      <flex:message-service default-channels="my-amf"/>
                  </flex:message-broker>

                  Comment


                  • #10
                    Good point, but I just tried and ... didn't work out. I even removed all mvc stuff and it won't work either when the flex:mapping is there. When I remove the mapping it works again. I just turned on logging for spring and found intresting differences in the results, but couldn't figure out why:

                    with mapping:
                    Code:
                    19:59:00,117 DEBUG (org.springframework.web.servlet.DispatcherServlet [getLastModified]:842) - DispatcherServlet with name 'dispatcherServlet' determining Last-Modified value for [/SpringServer/messagebroker/amf]
                    19:59:00,117 TRACE (org.springframework.web.servlet.DispatcherServlet [getHandler]:939) - Testing handler map [[email protected]d3ac0] in DispatcherServlet with name 'dispatcherServlet'
                    19:59:00,117 TRACE (org.springframework.web.servlet.handler.AbstractUrlHandlerMapping [getHandlerInternal]:222) - No handler mapping found for [/amf]
                    19:59:00,117 DEBUG (org.springframework.web.servlet.DispatcherServlet [getLastModified]:850) - No handler found in getLastModified
                    19:59:00,133 TRACE (org.springframework.web.servlet.FrameworkServlet [processRequest]:643) - Bound request context to thread: org.apache.catalina.connector.RequestFacade@35dc95
                    19:59:00,133 DEBUG (org.springframework.web.servlet.DispatcherServlet [doService]:690) - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/SpringServer/messagebroker/amf]
                    19:59:00,133 TRACE (org.springframework.web.servlet.DispatcherServlet [getHandler]:939) - Testing handler map [[email protected]d3ac0] in DispatcherServlet with name 'dispatcherServlet'
                    19:59:00,133 TRACE (org.springframework.web.servlet.handler.AbstractUrlHandlerMapping [getHandlerInternal]:222) - No handler mapping found for [/amf]
                    19:59:00,133 WARN  (org.springframework.web.servlet.DispatcherServlet [noHandlerFound]:962) - No mapping found for HTTP request with URI [/SpringServer/messagebroker/amf] in DispatcherServlet with name 'dispatcherServlet'
                    19:59:00,133 TRACE (org.springframework.web.servlet.FrameworkServlet [processRequest]:670) - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@35dc95
                    19:59:00,133 DEBUG (org.springframework.web.servlet.FrameworkServlet [processRequest]:677) - Successfully completed request
                    19:59:00,133 TRACE (org.springframework.context.support.AbstractApplicationContext [publishEvent]:299) - Publishing event in WebApplicationContext for namespace 'dispatcherServlet-servlet': ServletRequestHandledEvent: url=[/SpringServer/messagebroker/amf]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcherServlet]; session=[F3C0E327C8D55E7E0E9D6F0B2D385E8F]; user=[null]; time=[0ms]; status=[OK]
                    without mapping:
                    Code:
                    20:17:50,445 DEBUG (org.springframework.web.servlet.DispatcherServlet [getLastModified]:842) - DispatcherServlet with name 'dispatcherServlet' determining Last-Modified value for [/SpringServer/messagebroker/amf]
                    20:17:50,445 TRACE (org.springframework.web.servlet.DispatcherServlet [getHandler]:939) - Testing handler map [[email protected]e40274] in DispatcherServlet with name 'dispatcherServlet'
                    20:17:50,461 DEBUG (org.springframework.web.servlet.handler.AbstractUrlHandlerMapping [getHandlerInternal]:219) - Mapping [/amf] to handler 'flex.messaging.MessageBroker@1f2be27'
                    20:17:50,461 TRACE (org.springframework.web.servlet.DispatcherServlet [getHandlerAdapter]:976) - Testing handler adapter [[email protected]8ea]
                    20:17:50,461 DEBUG (org.springframework.web.servlet.DispatcherServlet [getLastModified]:858) - Last-Modified value for [/SpringServer/messagebroker/amf] is: -1
                    20:17:50,477 TRACE (org.springframework.web.servlet.FrameworkServlet [processRequest]:643) - Bound request context to thread: org.apache.catalina.connector.RequestFacade@94aa42
                    20:17:50,477 DEBUG (org.springframework.web.servlet.DispatcherServlet [doService]:690) - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/SpringServer/messagebroker/amf]
                    20:17:50,477 TRACE (org.springframework.web.servlet.DispatcherServlet [getHandlerAdapter]:976) - Testing handler adapter [[email protected]8ea]
                    20:17:50,477 INFO  (org.springframework.flex.servlet.MessageBrokerHandlerAdapter [handle]:106) - Channel endpoint my-amf received request.
                    20:17:50,493 DEBUG (org.springframework.web.servlet.DispatcherServlet [doDispatch]:805) - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
                    20:17:50,493 TRACE (org.springframework.web.servlet.FrameworkServlet [processRequest]:670) - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@94aa42
                    20:17:50,493 DEBUG (org.springframework.web.servlet.FrameworkServlet [processRequest]:677) - Successfully completed request
                    20:17:50,493 TRACE (org.springframework.context.support.AbstractApplicationContext [publishEvent]:299) - Publishing event in WebApplicationContext for namespace 'dispatcherServlet-servlet': ServletRequestHandledEvent: url=[/SpringServer/messagebroker/amf]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcherServlet]; session=[F3C0E327C8D55E7E0E9D6F0B2D385E8F]; user=[null]; time=[32ms]; status=[OK]
                    [Edit]
                    The question is why is he mapping '/amf' to MessageBroker instead of '/messagebroker/amf'? And why does that even work?
                    Last edited by Peacemaker2000; Dec 7th, 2010, 02:25 PM.

                    Comment


                    • #11
                      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.

                      Comment


                      • #12
                        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:

                        Comment


                        • #13
                          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.

                          Comment


                          • #14
                            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, 06:50 PM. Reason: Mistake in <flex:message-broker> example.

                            Comment


                            • #15
                              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?

                              Comment

                              Working...
                              X