PDA

View Full Version : MessageBroker already defined exception after making non-flex client request



ewu119
Apr 2nd, 2009, 12:46 PM
Hi all,

I try to create an web application to support both html and flex client. The server started up succesfully without any error and the MessageBroker is created and started by Spring. But I encountered an configuration exception "MessageBroker already defined from MessageBrokerServlet with init parameter messageBrokerId = '_messageBroker'" after making the regular http request from browser. I am new to Spring+Flex integration and hope to get some help to solve this error.

The environment I using:
- BlazeDS - Community Edition: 3.2.0.3978
- Spring 2.5.6
- SpringFlex 1.0.0 M2
- JDK 1.6.0_10
- Windows Vista
- Flex SDK 4.0
- Flash Player 10 debug version

The details trace:
2009-04-02 09:48:33,970 http-8080-1 - MessageBroker with id '_messageBroker' is starting. (MessageBrokerFactoryBean:INFO:192)
[BlazeDS]04/02/2009 09:48:33.970 [DEBUG] [Configuration] MessageBroker id: _messageBroker classLoader is: the MessageBroker's class loader and the context class loader (classLoader hashCode: 15961328 (parent hashCode: 31658378 (parent system))
[BlazeDS]04/02/2009 09:48:33.970 [DEBUG] [Configuration] MessageBroker id: _messageBroker classLoader is: the MessageBroker's class loader and the context class loader (classLoader hashCode: 15961328 (parent hashCode: 31658378 (parent system))
[BlazeDS]04/02/2009 09:48:33.979 [ERROR] [Configuration] MessageBroker failed to start: Exception: flex.messaging.config.ConfigurationException: MessageBroker already defined from MessageBrokerServlet with init parameter messageBrokerId = '_messageBroker'
at flex.messaging.MessageBroker.registerMessageBroker (MessageBroker.java:1916)
at flex.messaging.MessageBroker.start(MessageBroker.j ava:350)
at org.springframework.flex.messaging.MessageBrokerFa ctoryBean.afterPropertiesSet(MessageBrokerFactoryB ean.java:206)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1335)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:380)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 02)
at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:316 )
at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:808)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

Many thanks in advance,

Eric

ewu119
Apr 2nd, 2009, 12:48 PM
This is follow up thread for all configuration files:

The web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:enfensa/application-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>eaf</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:enfensa/application-context.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>eaf</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

application-context.xml:

<import resource="blazeds.xml"/>
<import resource="eaf-servlet.xml"/>

blazeds.xml:

<flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml">
<flex:mapping pattern="/messagebroker/*"/>
</flex:message-broker>

eaf-servlet.xml:

<bean class="org.springframework.web.servlet.mvc.support.Contro llerClassNameHandlerMapping"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/index.htm">indexController</prop>
<prop key="/captchaDemo.htm">sampleFormController</prop>
<prop key="/captcha.jpg">captchaController</prop>
</props>
</property>
</bean>
<bean class="org.springframework.flex.messaging.servlet.Message BrokerHandlerAdapter"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver"
prefix="/WEB-INF/jsp/"
p:suffix=".jsp"
p:viewClass="org.springframework.web.servlet.view.JstlView" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.Parameterizabl eViewController"
p:viewName="index" />

service-config.xml:

<services-config>
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
</services>
<security>
<login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
</security>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>
<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
<channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>4</polling-interval-seconds>
</properties>
</channel-definition>
</channels>
<logging>
<target class="flex.messaging.log.ConsoleTarget" level="Debug">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
<pattern>Service.Message.JMS</pattern>
<!-- add jms pattern for flex/blazeds debugging -->
</filters>
</target>
</logging>
<system>
<redeploy>
<enabled>false</enabled>
</redeploy>
</system>
</services-config>

jeremyg484
Apr 2nd, 2009, 04:19 PM
It's not shown in your web.xml snippet, but I assume since you are using the contextConfigLocation context-param that you've also got a ContextLoaderListener configured? If so, you are loading your application context twice (once by the ContextLoaderListener, once by the DispatcherServlet), and in turn the MessageBroker is being configured twice which is the cause of the error. The reason you aren't seeing the error until the first request is because you do not have the DispatcherServlet configured to load on startup, otherwise you would see the error immediately upon starting the application.

ewu119
Apr 2nd, 2009, 05:42 PM
This is exactly the problem. After I remove the extra ContextLoaderListener, the problem went away. Thanks so much for your help.

Eric