New Update to the Spring BlazeDS Integration Test Drive

I made some additional changes to the Spring BlazeDS Integration (RC1) Test Drive:

  • The Test Drive now includes an annotation-based configuration sample (the Company Manager sample). Spring annotations such as @Service, @RemotingDestination, @Autowired, @RemotingInclude, and @RemotingExclude make it really easy to configure your beans and make them available through Remoting. As an example, here is the source code for the CompanyDAO class:

    package flex.spring.samples.company;
    
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.sql.DataSource;
    
    import org.springframework.flex.remoting.RemotingDestination;
    import org.springframework.flex.remoting.RemotingExclude;
    import org.springframework.flex.remoting.RemotingInclude;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
    import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
    import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
    
    import flex.spring.samples.industry.IIndustryDAO;
    
    @Service("companyService")
    @RemotingDestination(channels={"my-amf"})
    public class CompanyDAO implements ICompanyDAO {
    
    	private final SimpleJdbcTemplate template;
    	private final SimpleJdbcInsert insertCompany;
    
    	private IIndustryDAO industryDAO;
    
    	private final ParameterizedRowMapper<Company> rowMapper = new ParameterizedRowMapper<Company>(){
    		public Company mapRow(ResultSet rs, int rowNum) throws SQLException {
    			Company company = new Company();
    			company.setId(rs.getInt("id"));
    			company.setName(rs.getString("name"));
    			company.setAddress(rs.getString("address"));
    			company.setCity(rs.getString("city"));
    			company.setState(rs.getString("state"));
    			company.setZip(rs.getString("zip"));
    			company.setPhone(rs.getString("phone"));
    			company.setIndustry(industryDAO.findById(rs.getInt("industry_id")));
    			return company;
    		}
    	};
    
    	@Autowired
    	public CompanyDAO(DataSource dataSource, IIndustryDAO industryDAO) {
    		template = new SimpleJdbcTemplate(dataSource);
    		insertCompany = new SimpleJdbcInsert(dataSource).withTableName("COMPANY").usingGeneratedKeyColumns("ID");
    		this.industryDAO = industryDAO;
    	}
    
    	@RemotingInclude
    	public Company findById(int id) {
    		return template.queryForObject("SELECT * FROM company WHERE id=?", rowMapper, id);
    	}
    
    	@RemotingInclude
    	public List<Company> findAll() {
    		return template.query("SELECT * FROM company ORDER BY name", rowMapper);
    	}
    
    	@RemotingInclude
    	public List<Company> findByName(String name) {
    		return template.query("SELECT * FROM company WHERE UPPER(name) LIKE ? ORDER BY name",
    				rowMapper,
    				"%" + name.toUpperCase() + "%");
    	}
    
    	@RemotingInclude
    	public Company create(Company company) {
    		Map<String, Object> parameters = new HashMap<String, Object>();
            parameters.put("name", company.getName());
            parameters.put("address", company.getAddress());
            parameters.put("city", company.getCity());
            parameters.put("state", company.getState());
            parameters.put("zip", company.getZip());
            parameters.put("phone", company.getPhone());
            parameters.put("industry_id", company.getIndustry().getId());
            Number id = insertCompany.executeAndReturnKey(parameters);
    		company.setId(id.intValue());
    		return company;
    	}
    
    	@RemotingInclude
    	public boolean update(Company company) {
            int count = template.update("UPDATE company SET name=?, address=?, city=?, state=?, zip=?, phone=?, industry_id=? WHERE id=?",
    				company.getName(),
    				company.getAddress(),
    				company.getCity(),
    				company.getState(),
    				company.getZip(),
    				company.getPhone(),
    				company.getIndustry().getId(),
    				company.getId());
    		return (count == 1);
    	}
    
    	@RemotingExclude
    	public boolean remove(Company company) {
    		int count = template.update("DELETE FROM company WHERE id=?", company.getId());
    		return (count == 1);
    	}
    
    }
    

  • The Test Drive is now using the M3 build of Spring 3 (as opposed to M2 in the previous builds of the Test Drive).
  • I modified the configuration of the long polling channel to support more persistent connections per domain based on the browser capabilities.
  • And of course compared to the M2 build, this version of the Test Drive includes a number of Messaging samples.

    Using the Messaging integration, setting up a destination can be as easy as:

    <flex:message-destination id="chat" />
    

    And here is how you configure a destination mapped to a JMS topic:

    <flex:jms-message-destination id="jms-chat" jms-destination="chatTopic" />
    

Installation Instructions:

  1. Download the Spring / Flex TestDrive here: http://coenraets.org/downloads/spring-flex-testdrive-RC1v2.zip
  2. Unzip it in your root directory
  3. Navigate to /spring-flex-testdrive/tomcat/bin and start Tomcat (for instance: catalina run)
  4. Open a browser and access http://localhost:8080
  5. Follow the instructions

32 Responses to New Update to the Spring BlazeDS Integration Test Drive

  1. Monger May 12, 2009 at 5:26 pm #

    Amazing. Thank you, Christophe for making my life easier. You’re doing some amazing work! Keep it up!

  2. Rares May 13, 2009 at 5:34 am #

    Hi, the examples work fine but it would be wonderful if you include in the archive the project’s build scripts (ant or maven) beside the source files. I am unable to find on the web an official post about how Java and Flex 3 projects should be build using maven/ant. I’m trying for about a week now to create a deployment script and still didn’t find the best way to do it, especially what maven plugins to use… It would be great to have such an example. Thanks in advance !

  3. Kannan May 13, 2009 at 7:07 am #

    Hi,

    It is a fantastic work. I would like to know some information related to search box, Currently I think the pop-up list position is like list.move(point.x – 30, point.y + 24);

    but if I wanted to reuse this search box in many screens , where the box can be at various position, the pop up appears in different location, instead I always wanted to have it like a drop down. Can you please help on how to fix this.(since I am a java programmer and new to flex, please help, as we are planning to start a new project with spring blazeDS)

  4. Yeudy May 13, 2009 at 10:47 am #

    Hi Christophe, thank you, great work!

  5. claudio May 13, 2009 at 12:51 pm #

    Hi, very nice,

    The problem for me, and creating an environment to test. I purchased Flex Builder 3 but I do not understand how to set up for Spring-Hibernate-Mysql
    help me.

    Tanks.
    Claudio Italy

  6. Rahul May 13, 2009 at 6:18 pm #

    Hi,
    I am trying to upgrade my existing HelloWorld Blazeds Integration web application to 1.0.0.RC1 Release. I just annoted my Service class with @Service(“helloWorldService”) ,@RemotingDestination(channels={“my-amf”})
    and method with @RemotingInclude.
    I removed the bean declaration and flex:remote-service tag from web-application-config.xml. Although flex:message-broker tag still there.
    With these changes in place, I am expecting the application to work, but it just deploys successfully. When tried to invoke method from flex client, nothing happens.
    Am I missing something? Please help.

    Cheers,
    Rahul

  7. François May 14, 2009 at 3:55 am #

    Thanks for sharing this Christophe !

    I’m glad that SpringSource finally released that annotation mechanism, that we had for long in our flex-spring-contrib lib.
    cf. http://fna.googlecode.com/svn/trunk/fna/site/flex-contrib-spring/index.html

    Would you Christophe if they plan on adding springsecurity/blazeds_channel_security integration annotations as well ?

  8. Rocky May 14, 2009 at 10:05 am #

    Hi Christophe,

    I would appreciate if you can provide some details regarding “using my-secure-amf”.

    Thanks in advance!

  9. Jhun Geronimo May 14, 2009 at 4:19 pm #

    Excellent Job!

    Particularly on Spring Security and JMS Integrations. Great Updates…

    Thanks for sharing Christophe and Jeremy.

  10. Stacey Reiman June 1, 2009 at 1:25 pm #

    Is there official support for Glassfish instead of Tomcat?

  11. robin bakkerus June 4, 2009 at 12:05 am #

    Hi Christophe,

    Could you also supply a working testdrive that runs on the new Springsource dm server.

    Thank you in advance

  12. Oleg June 12, 2009 at 10:35 am #

    Christophe,

    Excellent work !

    Couple of things:
    1) it would be very beneficial to everybody if there is a good documentation on these samples, e.g. describing steps to configure it in Tomcat and Flex/FlashBuilder;
    2) Spring-to-Flex integration API documentation ?
    3) Can you provide Flex4 version of samples? Any limitations/problems to make it work with Flex4 ?
    4) Can it work with Spring2.x and earlier versions of BlazeDS & LCDS ?

    Thank you,
    Oleg.

  13. Oleg June 22, 2009 at 11:59 am #

    Christophe,

    When are you planning to release 1.0 GA testdrive.
    I got latest one from SpringSource and started playing with it.

    I have imported 1.0 GA testdrive source code into FlexBuilder3 and trying to run on Tomcat6 which came up with testdrive M2
    (on Christophe Coenraets’ site).
    I did create another app context (feedstarter1 and traderdesktop1), so it should not interfere with existing M2 ones.
    Have not changed anything in the code or testdrive config.

    It compiles and shows on the page fine, but as soon as I start a Market Feed, getting exception:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at traderdesktop/messageHandler()[C:\Documents and Settings\Oleg\workspace\TraderDesktop\src\traderdesktop.mxml:95]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.messaging::AbstractConsumer/http://www.adobe.com/2006/flex/mx/internal::messageHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\AbstractConsumer.as:727]
    at mx.messaging::ConsumerMessageDispatcher/messageHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ConsumerMessageDispatcher.as:251]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.messaging::ChannelSet/messageHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1363]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at PollCommandMessageResponder/resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:746]
    at mx.messaging::MessageResponder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:199]

    line 95 of
    94: var changedStock:Stock = event.message.body as Stock;
    95: var stock:Stock = stockMap[changedStock.symbol];

    What am I missing ?

    Please help !

    TIA,
    Oleg.

  14. Oleg June 23, 2009 at 2:14 pm #

    Christophe,

    It would be great if you can implement a Flex client from the real JMS like ActiveMQ using JMSadapter, e.g. the same TraderDesktop.

    Similar JMS chat with ActiveMQ & BlazeDS:
    http://www.agimatec.de/blog/2008/08/extended-blazeds-and-jms-example/

    Thank you,
    Oleg.

  15. sambamoon July 5, 2009 at 8:54 pm #

    I gort some error for using this update

    the Spring BlazeDS Integration Test Drive

    Let me download and try again

    Thanks

  16. Alberto July 20, 2009 at 4:09 pm #

    Hi Christophe,

    On the Flex side, I see you have commented the streaming-amf channel from any ChannelSet. Is there any reason for this? cause I can’t make a message destination based on this channel to work :/

    Longpolling, polling, etc seem to work fine but streaming-amf channel is not working. Im using latest spring-for-blazeds jar, etc.

    Any ideas?

    Thank you in advance.

    A.

  17. Paul August 25, 2009 at 2:55 pm #

    Hi, I´m very new to java but I know flex.
    Do you know a tutorial to create a new project from scratch in eclipse. like a best practices for new projects ?

  18. enigma October 15, 2009 at 12:45 am #

    Thank you very much !! … test drive is very useful.

  19. kayyu October 17, 2009 at 6:47 am #

    thank you man

  20. model ajansı November 4, 2009 at 2:08 pm #

    model ve mankenlik ajansı

  21. fotograf çekimleri November 4, 2009 at 2:09 pm #

    fotoğraf çekimleri

  22. Program yükle November 21, 2009 at 12:05 pm #

    program yükle Good admin than you

  23. Derrick December 22, 2009 at 8:40 am #

    Christophe,

    Thanks for all your hard work. It has not only taught me a LOT, but has helped me tremendously!

    Thanks!
    – Derrick

  24. xcom February 17, 2010 at 2:40 am #

    version tomcat 6.18???? o not

  25. Darin Boyd October 22, 2010 at 12:00 pm #

    I couldn’t get it to run.

  26. spedest November 27, 2010 at 9:22 am #

    I’m trying for about a week now to create a deployment script and still didn’t find the best way to do it, especially what maven plugins to use… It would be great to have such an example. Thanks in advance !

  27. Ruby @ Animal Camp December 30, 2010 at 12:38 pm #

    Great coding! It’s great that you have included the codes and examples for us readers to follow.

  28. Victor February 2, 2012 at 7:27 pm #

    Not Found

    The requested URL /downloads/spring-flex-testdrive-RC1v2.zip was not found on this server.
    Apache/2.2.21 (Amazon) Server at coenraets.org Port 80

    Can someone please upload the file again?

Trackbacks/Pingbacks

  1. 14/05/2009 « Robertopriz’s Weblog - May 14, 2009

    […] Christophe Coenraets http://coenraets.org/blog/2009/05/new-update-to-the-spring-blazeds-integration-test-drive/ […]

  2. Using SpringMVC next to BlazeDS « 3 character abbreviation - January 12, 2010

    […] I used the testdrive project of Christophe […]

  3. Jacob Heric » Blog Archive » Spring Flex integration with BlazeDS - February 23, 2010

    […] already pretty widely available. The Spring BlazeDS Integration test drive (originally developed by Adobe Evangelist Christophe Coenraets) is excellent. The fine fellows at Gridshore have also provided an excellent sample application […]

Leave a Reply

css.php