New Update to the Spring BlazeDS Integration Test Drive

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

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • StumbleUpon
  • Twitter
This entry was posted in BlazeDS, Flex, Java, Spring. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

24 Comments

  1. Monger
    Posted May 12, 2009 at 5:26 pm | Permalink

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

  2. Rares
    Posted May 13, 2009 at 5:34 am | Permalink

    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
    Posted May 13, 2009 at 7:07 am | Permalink

    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
    Posted May 13, 2009 at 10:47 am | Permalink

    Hi Christophe, thank you, great work!

  5. claudio
    Posted May 13, 2009 at 12:51 pm | Permalink

    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
    Posted May 13, 2009 at 6:18 pm | Permalink

    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. Posted May 14, 2009 at 3:55 am | Permalink

    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
    Posted May 14, 2009 at 10:05 am | Permalink

    Hi Christophe,

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

    Thanks in advance!

  9. Posted May 14, 2009 at 4:19 pm | Permalink

    Excellent Job!

    Particularly on Spring Security and JMS Integrations. Great Updates…

    Thanks for sharing Christophe and Jeremy.

  10. Posted June 1, 2009 at 1:25 pm | Permalink

    Is there official support for Glassfish instead of Tomcat?

  11. robin bakkerus
    Posted June 4, 2009 at 12:05 am | Permalink

    Hi Christophe,

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

    Thank you in advance

  12. Oleg
    Posted June 12, 2009 at 10:35 am | Permalink

    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
    Posted June 22, 2009 at 11:59 am | Permalink

    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
    Posted June 23, 2009 at 2:14 pm | Permalink

    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. Posted July 5, 2009 at 8:54 pm | Permalink

    I gort some error for using this update

    the Spring BlazeDS Integration Test Drive

    Let me download and try again

    Thanks

  16. Alberto
    Posted July 20, 2009 at 4:09 pm | Permalink

    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
    Posted August 25, 2009 at 2:55 pm | Permalink

    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
    Posted October 15, 2009 at 12:45 am | Permalink

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

  19. Posted October 17, 2009 at 6:47 am | Permalink

    thank you man

  20. Posted November 4, 2009 at 2:08 pm | Permalink

    model ve mankenlik ajansı

  21. Posted November 4, 2009 at 2:09 pm | Permalink

    fotoğraf çekimleri

  22. Posted November 21, 2009 at 12:05 pm | Permalink

    program yükle Good admin than you

  23. Posted December 22, 2009 at 8:40 am | Permalink

    Christophe,

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

    Thanks!
    – Derrick

  24. xcom
    Posted February 17, 2010 at 2:40 am | Permalink

    version tomcat 6.18???? o not

3 Trackbacks

  1. By 14/05/2009 « Robertopriz’s Weblog on May 14, 2009 at 2:36 am
  2. [...] I used the testdrive project of Christophe [...]

  3. [...] 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 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>