BlazeDS Simple Remoting (Part I – “Java”)


  • Flex Builder 2/3 (Since FlexBuilder is Eclipse Based we will use it for both flex and Java development)
    you can download trail version of FlexBuilder from following url : Flex Builder Trail Download
  • Java Web application Server (I use Tomcat in this example)
    you can download tomcat from following url: Tomcat Download

Server Side Tasks:

  • Create Simple Java web Application
  • Add BlazeDS Servlet definition…, Libraries, and Configuration files.
  • Create regular java Class, and add following two methods:
    • getAllEvents() returns List SportEvent Objects
    • getSportEvent(sportid) returns one SportEvent object (specific to sport id parameter)
  • Register Class with blaseDS so it can serve requests

Create java Web Application

Create java Web Project in Eclipse :
NOTE: I am using MyEclipse Plugin which is enhanced version of WTP, so screen shots should look similar :
Fine–> new Project –> dynamic web project (or just Web project)

Create Web ProjectCreate Web Project

Add Java beans


  1. public class Event {
  2. private int id;
  3. private String name;
  4. private List<Team> teams;
  5. private Date eventDate;
  6. // default constructor
  7. //setters getters …
  8. }


  1. public class Team {
  2. private String name ;
  3. private String shortName;
  4. // default constructor
  5. //setters getters …
  6. }

Finally Lets Create Service class which will serve those beans to caller.
In this tutorial, we are not going to use DB so we need to hardcore some values to simulate random data:


  1. public Event getSportEvent (int eid) throws Exception{
  2. // in reality :
  3. //you query db etc get correct event and return it.
  4. Event e = new Event();
  5. e.setEventDate(new Date());
  6. e.setId(eid);
  7. List<Team> l = new ArrayList<Team>();
  8. // Simulating the random Events
  9. switch (eid) {
  10. case 1:
  11. e.setName(event1);
  12. l.add(new Team(“Atlanta Hawks”,“ATL”) );
  13. l.add(new Team(“Los Angeles Lakers”,“LAL”) );
  14. break;
  15. case 2:
  16. case 3:
  17. default:
  18. break;
  19. }
  20. e.setTeams(l);
  21. return e;
  22. }
  23. public List<Event> getAllEvents() throws Exception{
  24. List<Event> ae = new ArrayList<Event>();
  25. ae.add(getSportEvent(1));
  26. ae.add(getSportEvent(2));
  27. return ae;
  28. }

Add BlazeDS to project :

  • Download latest Stable Build from following url: BlazeDS latest Build
    download Binary distribution version not turnkey version, for example this:
  • unzipp .war file with winrar or your proffered compression program .
  • copy jar files from blazeds/WEB-INF/lib directory to your projects web/WEB-INF/lib directory
  • create directory “flex” under your projects web/WEB-INF/ directory
  • Add two flex configuration files under flex directory :
    • services-config.xml
    • remoting-config.xml
WEB-INF directoryWEB-INF directory

Configure web.xml

Add following to your web.xml file:


  1. <!– MessageBroker Servlet –>
  2. <servlet>
  3. <servlet-name>MessageBrokerServlet</servlet-name>
  4. <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
  5. <init-param>
  6. <param-name>services.configuration.file</param-name>
  7. <param-value>/WEB-INF/flex/services-config.xml</param-value>
  8. </init-param>
  9. <load-on-startup>1</load-on-startup>
  10. </servlet>
  11. <servlet-mapping>
  12. <servlet-name>MessageBrokerServlet</servlet-name>
  13. <url-pattern>/messagebroker/*</url-pattern>
  14. </servlet-mapping>

Configure services-config.xml add my-amf channel definition


  1. <services>
    <service-include file-path=”remoting-config.xml” />
  2. <channel-definition id=“my-amf”
  3. class=“mx.messaging.channels.AMFChannel”>
  4. <endpoint url=http://{}:{server.port}/{context.root}/messagebroker/amf”
  5. class=“flex.messaging.endpoints.AMFEndpoint”/>
  6. </channel-definition>

Configure remoting-config.xml add destination for our SportEventsManager class


  1. <destination id=“sportEventsManager”>
  2. <properties>
  3. <source>com.example.EventsManager</source>
  4. </properties>
  5. </destination>

lets test the settings, build and deploy java project to tomcat and access following url :


you should get empty page which means blazeDS is running and waiting for request.
that’s all for java part.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: