Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: Help with Spring BlazeDS configuration

  1. #1
    Join Date
    Feb 2007
    Location
    Saint Louis
    Posts
    86

    Default Help with Spring BlazeDS configuration

    In the examples from Jeremy on this config setup I see this: web-application-config.xml file. Is this file taking the place of the applicationContext.xml? I'm not really sure what the purpose of this file is; as there is no real explanation on it in the docs. I have setup my Spring app. to use iBatis and I'm trying to use the BlazeDS integration to talk to my serviceImpl.I unfortunately have a gap in my understanding of how this is wired together from the perspective of the applicationContext.xml and the web.xml with this file mentioned above(web-application-config.xml). In your article here: http://blog.springsource.com/2008/12...ntegration-m1/ some of your files are unclear as to what configuration block is going where.

    Anyway I'm using JDK1.5, Spring2.5.5,BlazeDS3.2 -
    Here is my applicationContext.xml
    Code:
    <!--
    	  - Nestle primary business object (default implementation).
    		- Transaction advice gets applied through the AOP configuration below.
    		-->
    	<bean id="nestleDataService" class="com.talisen.domain.logic.NestleDataServiceImpl">
    		<property name="accountDao" ref="accountDao"/>
    		<property name="buildingDao" ref="buildingDao"/>
    		<property name="electricDao" ref="electricDao"/>
    	</bean>
    
    	<!-- Expose the nestleDataService bean foro BlazeDS remoting -->
    	<bean id="nestleService"
    		class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
    		<property name="messageBroker" ref="mySpringManagedMessageBroker"/>
    		<property name="service" ref="nestleDataService"/>
    	</bean>
    	
    	<!-- Maps request paths at /messagebroker to the BlazeDS MessageBroker -->
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<value>
    				/messagebroker/*=mySpringManagedMessageBroker
    			</value>
    		</property>
    	</bean>
    	
    	<!-- Dispatches requests mapped to a MessageBroker -->
    	<bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter"/>
    and of course the web.application-config.xml as mentioned in your post as well as the remoting-config.xml, services-config.xml and remoting-config.xml.
    Here is the web.xml-
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <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">
    
    	<display-name>Nestle Data Service</display-name>
    
    	<description>Nestle Data Application</description>
    
    	<!--
    		- Key of the system property that should specify the root directory of this
    		- web app. Applied by WebAppRootListener or Log4jConfigListener.
    	-->
    	<context-param>
    		<param-name>webAppRootKey</param-name>
    		<param-value>nestle.root</param-value>
    	</context-param>
    
    
    	<!--
    		- Location of the Log4J config file, for initialization and refresh checks.
    		- Applied by Log4jConfigListener.
    	-->
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>/WEB-INF/log4j.properties</param-value>
    	</context-param>
    
    	<!--
    		- Location of the XML file that defines the root application context.
    		- Applied by ContextLoaderServlet.
    		-
    		- Can include "/WEB-INF/dataAccessContext-local.xml" for a single-database
    		- context, or "/WEB-INF/dataAccessContext-jta.xml" for a two-database context.
    	-->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/dataAccessContext-local.xml /WEB-INF/applicationContext.xml</param-value>
    		
    	</context-param>
    
    	<!--
    		- Configures Log4J for this web app.
    		- As this context specifies a context-param "log4jConfigLocation", its file path
    		- is used to load the Log4J configuration, including periodic refresh checks.
    		-
    		- Would fall back to default Log4J initialization (non-refreshing) if no special
    		- context-params are given.
    		-
    		- Exports a "web app root key", i.e. a system property that specifies the root
    		- directory of this web app, for usage in log file paths.
    		- This web app specifies "petclinic.root" (see log4j.properties file).
    	-->
    	<!-- Leave the listener commented-out if using JBoss -->
    	
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>
    	
    
    	<!--
    		- Loads the root application context of this web app at startup,
    		- by default from "/WEB-INF/applicationContext.xml".
    		- Note that you need to fall back to Spring's ContextLoaderServlet for
    		- J2EE servers that do not follow the Servlet 2.4 initialization order.
    		-
    		- Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
    		- to access it anywhere in the web application, outside of the framework.
    		-
    		- The root context is the parent of all servlet-specific contexts.
    		- This means that its beans are automatically available in these child contexts,
    		- both for getBean(name) calls and (external) bean references.
    	-->
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    
    	<!--
    		- Spring web MVC servlet that dispatches requests to registered handlers.
    		- Has its own application context, by default defined in "{servlet-name}-servlet.xml",
    		- i.e. "petstore-servlet.xml" in this case.
    		-
    		- A web app can contain any number of such servlets.
    		- Note that this web app has a shared root application context, serving as parent
    		- of all DispatcherServlet contexts.
    	-->
    	<servlet>
    		<servlet-name>nestleDataFetcher</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>WEB-INF/config/web-application-config.xml</param-value>
    		</init-param>
    		<load-on-startup>11</load-on-startup>
    	</servlet>
    
    	<!--
    		- Dispatcher servlet mapping for the main web user interface.
    		- Either refering to "petstore" for the Spring web MVC dispatcher,
    		- or to "action" for the Struts dispatcher.
    		-
    		- Simply comment out the "petstore" reference in favour of "action"
    		- to switch from the Spring web tier to the Struts web tier.
    	-->
    	<servlet-mapping>
    		<servlet-name>nestleDataFetcher</servlet-name>
    		
    		<url-pattern>/spring/*</url-pattern>
    	</servlet-mapping>
    
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    	<error-page>
            <error-code>404</error-code>
            <location>/error.jsp</location>
        </error-page>
    
    
    </web-app>
    Anyway some explanation of what or how the web-application-config.xml gets called from all this or the app. knows about it would help or can I just move that logic out and put it in the applicationContext.xml?

    Thanks!
    Andrew W. McDougall

  2. #2
    Join Date
    Mar 2007
    Posts
    9

    Default

    web-application-config.xml is the default DispatcherServlet Configuration file.

    e.g if you DispatcherServlet is named nestleDataFetcher as shown the the web-application-config.xml should be named nestleDataFetcher-servlet.xml
    If you do this and you place it under WEB-INF dir the DispatcherServlet will auto pick it up because of the matching name.

    You web.xml config would then look like

    <servlet>
    <servlet-name>nestleDataFetcher </servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>admin</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>


    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/applicationContext.xml
    </param-value>
    </context-param>


    If you however name it something different from what your DispatcherServlet

    then you would reference it the the Dispatcher Configuration as you have it



    e.g.

    <servlet>
    <servlet-name>nestleDataFetcher </servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/some-name-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>

  3. #3
    Join Date
    Mar 2007
    Posts
    13

    Default more help

    I think I read through every post, and still no luck for me..

    my web.xml
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    	</context-param>
    
        <context-param>
          <param-name>log4jConfigLocation</param-name>
          <param-value>/WEB-INF/classes/log4j.xml</param-value>
        </context-param> 
    	<context-param>
    		<param-name>flex.class.path</param-name>
    		<param-value>/WEB-INF/flex/hotfixes</param-value>
    	</context-param>
    	<filter>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<filter-class>
    			org.springframework.web.filter.DelegatingFilterProxy
    		</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	
    	<listener>
    	  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
        <listener>
            <listener-class>flex.messaging.HttpFlexSession</listener-class>
        </listener>
    	
    	<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
    	<servlet>
    	    <servlet-name>webapp</servlet-name>
    	    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	    <load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
        	<servlet-name>webapp</servlet-name>
        	<url-pattern>/spring/*</url-pattern>
        </servlet-mapping>
    my webapp-servlet.xml
    Code:
    	<!-- Bootstraps and exposes the BlazeDS MessageBroker -->
    	<bean id="managedMessageBroker" class="org.springframework.flex.messaging.MessageBrokerFactoryBean" />
    
    	<!-- Maps request paths at /* to the BlazeDS MessageBroker -->
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    	    <property name="mappings">
    	        <value>
    	            /*=managedMessageBroker
    	        </value>
    	    </property>
    	</bean>
    	
    	<!-- Dispatches requests mapped to a MessageBroker -->
    	<bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter"/>
    
    	<bean id="firstFlexService" class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
    	    <property name="messageBroker" ref="managedMessageBroker"/>
    	    <property name="service" ref="firstService"/>
    	</bean>
    	<bean id="secondFlexService" class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
    	    <property name="messageBroker" ref="managedMessageBroker"/>
    	    <property name="service" ref="secondService"/>
    	</bean>
    In application-config.xml
    just import by wild card other bean defenition files.

    services-config.xml
    Code:
    	<channels>
    	
            <channel-definition id="channel-amf" class="mx.messaging.channels.AMFChannel">
                <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf"
                          class="flex.messaging.endpoints.AMFEndpoint"/>
            </channel-definition>
    
            <channel-definition id="secure-amf" class="mx.messaging.channels.SecureAMFChannel">
                <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfsecure"
                          class="flex.messaging.endpoints.SecureAMFEndpoint"/>
                <properties>
                    <add-no-cache-headers>false</add-no-cache-headers>
                </properties>
            </channel-definition>
            
            <channel-definition id="polling-amf" class="mx.messaging.channels.AMFChannel">
                <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfpolling"
                          class="flex.messaging.endpoints.AMFEndpoint"/>
                <properties>
                    <polling-enabled>true</polling-enabled>
                    <polling-interval-seconds>4</polling-interval-seconds>
                </properties>
            </channel-definition>
    	</channels>
    for destination I'm referring to this - firstFlexService ..
    Any help is much appreciated, as the SpringFactory solution was working. Thanks

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

    Default

    Do you have a default channel configured?
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  5. #5
    Join Date
    Mar 2007
    Posts
    13

    Default

    hi jeremy
    remoting-config.xml
    Code:
    	<adapters>
    		<adapter-definition id="java-object"
    			class="flex.messaging.services.remoting.adapters.JavaAdapter"
    			default="true" />
    	</adapters>
    
    	<default-channels>
    		<channel ref="channel-amf" />
    	</default-channels>
    I've run out of ideas, on what else I could be doing.
    code : InvokeFailed, message : [MessagingError message='Destination 'firstFlexService' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']

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

    Default

    And do you have the default channel set in your services-config as well? For example:

    Code:
    <services>
    
            <service-include file-path="remoting-config.xml" />
            <service-include file-path="proxy-config.xml" />
            <service-include file-path="messaging-config.xml" />        
    
            <default-channels>
               <channel ref="my-amf"/>
            </default-channels>
    
    </services>
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  7. #7
    Join Date
    Mar 2007
    Posts
    13

    Default

    thanks jeremy
    I was missing that, also I didn't realize that the spring-springmvc with 2.5.6 release, was required, but is obvious now. overall pretty awesome.

  8. #8
    Join Date
    Jan 2009
    Posts
    10

    Default

    Hi Jeremy,

    Quote Originally Posted by jeremyg484 View Post
    And do you have the default channel set in your services-config as well? For example:

    Code:
    <services>
    
            <service-include file-path="remoting-config.xml" />
            <service-include file-path="proxy-config.xml" />
            <service-include file-path="messaging-config.xml" />        
    
            <default-channels>
               <channel ref="my-amf"/>
            </default-channels>
    
    </services>
    I also stumbled over this.

    This should really be documented as it is for sure something that you don't have to do when using BlazeDS directly. Actually, it looks like a hack to me.

    Do you mind explaining why this is needed?

    Thanks,
    Dirk.

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

    Default

    Basically, when using dynamic destinations with BlazeDS (which is what we're doing under the hood), if you don't have an application-wide default channel in services-config, then you have to explicitly set the channel on the RemoteObject on the ActionScript/MXML side.

    More details here:
    http://livedocs.adobe.com/blazeds/1/..._5.html#194376

    I agree we need to make a more explicit point of this in our own docs (beyond just doing it that way in the samples) as this has come up in several threads now.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  10. #10
    Join Date
    Jan 2009
    Posts
    10

    Default

    hey - thanks for the info!

    Dirk.

Posting Permissions

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