Posts Tagged Flash

Adobe Flex, BlazeDS, and TIBCO EMS

I’ve searched high and low and can’t really find a good walk through on how to configure TIBCO EMS and BlazeDS. The documentation can also be a little gray on how to correctly use the JMS adapter so i’ve taken the liberty of putting together this little pictorial on how it’s done.

First things first, get yourself a fresh copy of Eclipse. For this setup, I used Eclipse Ganymede (3.4, J2EE Edition) on Windows. You’ll need the Java stuff in addition to Flex Builder because we’re going to launch our own tomcat inside of Eclipse instead of using BlazeDS Turnkey or any of those. Also, if you want to add in Java remoting later you’ll appreciate having the components already there.

Next, install the Flex plugin for Eclipse and update according. I downloaded and installed the Flex 3.3 SDK and changed my default SDK in the preferences. Once the eclipse platform is installed, updated, and configured the way you like it, let’s make a new project.

Note: Click any one of these images for the full size version.
Step 1 - Create a new Project of type "Other"

Step 1 - Create a new Project of type "Other"

Step 2 - Expand the Server category and then select Server

Step 2 - Expand the Server category and then select Server

Step 3 - Create an Apache Tomcat v6.0 Server on Localhost

Step 3 - Create an Apache Tomcat v6.0 Server on Localhost

Step 4 - Set Installation Directory and JRE, Install if Necessary

Step 4 - Set Installation Directory and JRE, Install if Necessary

Step 5 - No projects yet, just hit Finish

Step 5 - No projects yet, just hit Finish

Step 6 - Create another new project of type "Other"

Step 6 - Create another new project of type "Other"

Step 7 - Now expand the Flex Builder category and select "Flex Project"

Step 7 - Now expand the Flex Builder category and select "Flex Project"

Step 8 - Set it for a J2EE application server and enable the combined Java/Flex project using WTP

Step 8 - Set it for a J2EE application server and enable the combined Java/Flex project using WTP

Step 9 - Connect the project to your Tomcat server and select the blazeds.war that you downloaded from Adobe

Step 9 - Connect the project to your Tomcat server and select the blazeds.war that you downloaded from Adobe

Step 10 - Everything should be good here

Step 10 - Everything should be good here

Step 11 - If everything went well, you should see have the following files available

Step 11 - If everything went well, you should see have the following files available

Step 12 - Open the web.xml, messaging-config.xml, and services-config.xml

Step 12 - Open the web.xml, messaging-config.xml, and services-config.xml

First, let’s edit web.xml. This file should be okay out of the box. Here’s mine as a reference.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>blaze1</display-name>
 
	<context-param>
		<param-name>flex.class.path</param-name>
		<param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars</param-value>
	</context-param>
 
	<!-- Http Flex Session attribute and binding listener support -->
	<listener>
		<listener-class>flex.messaging.HttpFlexSession</listener-class>
	</listener>
 
	<!-- MessageBroker Servlet -->
	<servlet>
		<servlet-name>MessageBrokerServlet</servlet-name>
		<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
		<init-param>
			<param-name>services.configuration.file</param-name>
			<param-value>/WEB-INF/flex/services-config.xml</param-value>
		</init-param>
		<init-param>
			<param-name>flex.write.path</param-name>
			<param-value>/WEB-INF/flex</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
 
	<servlet-mapping>
		<servlet-name>MessageBrokerServlet</servlet-name>
		<url-pattern>/messagebroker/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
 
	<!-- for WebSphere deployment, please uncomment -->
	<!--
		<resource-ref>
		<description>Flex Messaging WorkManager</description>
		<res-ref-name>wm/MessagingWorkManager</res-ref-name>
		<res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
		<res-auth>Container</res-auth>
		<res-sharing-scope>Shareable</res-sharing-scope>
	</resource-ref>
	-->
</web-app>

Now let’s edit services-config.xml. Key things to note here is that i’ve disabled the inclusion of the remoting-config.xml and the proxy-config.xml since i’m not using them. I’ve also changed the default AMF channel from “my-amf” to “AmfChannel1″ and updated the endpoint URL. Everything else is pretty much the same.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version="1.0" encoding="UTF-8"?>
<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"/>
        <!-- Uncomment the correct app server
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
		<login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>        
        <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
        -->
 
        <!-- 
        <security-constraint id="basic-read-access">
            <auth-method>Basic</auth-method>
            <roles>
                <role>guests</role>
                <role>accountants</role>
                <role>employees</role>
                <role>managers</role>
            </roles>
        </security-constraint>
         -->
    </security>
 
    <channels>
        <channel-definition id="AmfChannel1" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/AmfChannel1" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>
 
    <logging>
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>false</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>
 
    <system>
        <redeploy>
            <enabled>false</enabled>
            <!-- 
            <watch-interval>20</watch-interval>
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
             -->
        </redeploy>
    </system>
 
</services-config>

And last but not least, messaging-config.xml. This file is where the JMS connection is made to the TIBCO EMS server. And no, you do not have to put anything in context.xml when you’re doing it this way. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service" 
    class="flex.messaging.services.MessageService">
 
    <adapters>
        <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
        <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/>
    </adapters>
 
    <default-channels>
        <channel ref="AmfChannel1"/>
    </default-channels>
 
	<destination id="jmsDest1">
		<properties>
			<jms>
				<!-- topic/queue -->
				<destination-type>topic</destination-type>
				<!-- What type of message we expect -->
				<message-type>javax.jms.TextMessage</message-type>
				<!-- This is the JNDI name of the topic/queue connection factory on the server -->
				<connection-factory>TopicConnectionFactory</connection-factory>
				<!-- This is the JNDI name of the topic/queue on the server -->
				<destination-jndi-name>testTopic</destination-jndi-name>
				<!-- Keep JMS headers when the message is delivered to Flex -->
				<preserve-jms-headers>true</preserve-jms-headers>
				<!-- If we're producing on this destination, what parameters should be used -->				
				<delivery-mode>NON_PERSISTENT</delivery-mode>
				<message-priority>DEFAULT_PRIORITY</message-priority>
				<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
				<!-- The following lines are for the JNDI connection -->
				<initial-context-environment>
					<property>
						<name>Context.INITIAL_CONTEXT_FACTORY</name>
						<value>com.tibco.tibjms.naming.TibjmsInitialContextFactory</value>             
					</property>
					<property>
						<name>Context.PROVIDER_URL</name>
						<value>tcp://localhost:7222</value>             
					</property>
					<property>
						<name>Context.SECURITY_PRINCIPAL</name>
						<value>admin</value>
					</property>
					<!-- Uncomment if you have a password
					<property>
						<name>Context.SECURITY_CREDENTIALS</name>
						<value>password</value>
					</property>
					-->
				</initial-context-environment>
			</jms>
		</properties>
		<channels>
			<channel ref="AmfChannel1"/>
		</channels>
		<adapter ref="jms"/>
	</destination>
 
</service>

Now we have our Tomcat instance set up, time to import some class libraries.

Step 13 - Right Click the lib directory under WebContent/WEB-INF/lib select Import

Step 13 - Right Click the lib directory under WebContent/WEB-INF/lib select Import

Step 14 - Select General and then File System

Step 14 - Select General and then File System

Step 15 - Select the TIBCO EMS 5.x library directory and select all of the .jar files (There are more than what is pictured here)

Step 15 - Select the TIBCO EMS 5.x library directory and select all of the .jar files (There are more than what is pictured here)

Step 16 - Open up the server view by selecting Window -> Show View -> Other

Step 16 - Open up the server view by selecting Window -> Show View -> Other

Step 17 - Select the Server category and select Servers

Step 17 - Select the Server category and select Servers

Step 18 - Click the Servers tab that appeared at the bottom, highlight the Tomcat Server and click the Debug icon

Step 18 - Click the Servers tab that appeared at the bottom, highlight the Tomcat Server and click the Debug icon

Step 19 - Start the EMS Server instance

Step 19 - Start the EMS Server instance

Step 20 - Create the topic that was referenced in the messaging-config.xml file

Step 20 - Create the topic that was referenced in the messaging-config.xml file

Now jump back into Eclipse and set up the application. I started with a base form, added a text area and called it a day. Here’s the code to add in the message consumer, channel configuration, and event handlers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	applicationComplete="messageConsumer.subscribe()">
	<mx:Script>
		<![CDATA[
			// Import the required namespaces
			import mx.messaging.events.MessageEvent;
			import mx.messaging.events.ChannelEvent;
			import mx.messaging.messages.AsyncMessage;
 
			private function incomingMessageHandler(event:MessageEvent):void
			{
				logArea.text += (event.message.body + "\r");
			}
 
			private function connectEventHandler(event:ChannelEvent):void
			{
				logArea.text += (event.channel.endpoint + " is now connected.\r");
			}
 
			private function disconnectEventHandler(event:ChannelEvent):void
			{
				logArea.text += (event.channel.endpoint + " is now disconnected.\r");
			}
		]]>
	</mx:Script>
	<mx:TextArea id="logArea" editable="false" width="95%" height="95%"/>
	<mx:Consumer id="messageConsumer"
		destination="jmsDest1"
		message="incomingMessageHandler(event)"
		channelConnect="connectEventHandler(event)"
		channelDisconnect="disconnectEventHandler(event)">
		<mx:channelSet>
			<mx:ChannelSet>
				<mx:channels>
					<mx:AMFChannel
						url="http://localhost:8080/blaze1/messagebroker/AmfChannel1"/>
				</mx:channels>
			</mx:ChannelSet>
		</mx:channelSet>		
	</mx:Consumer>
</mx:Application>

That should do it for the code work … now for the fun stuff. :)

Step 21 - Fire up the debugger (use the dropdown next to the button)

Step 21 - Fire up the debugger (use the dropdown next to the button)

Step 22 - Select Debug As, then Debug on Server

Step 22 - Select Debug As, then Debug on Server

Step 23 - Select the installed Tomcat image

Step 23 - Select the installed Tomcat image

Step 24 - The project should appear on the right, press Finish

Step 24 - The project should appear on the right, press Finish

Note : The first debug attempt will fail because Eclipse doesn’t correctly deploy the application. What I haven’t figured out is how to correctly associate the project without using the Debug or Run options. If you know a better way, leave a comment. :)
Step 25 - Hit Debug As again and hit the "Flex Application" choice

Step 25 - Hit Debug As again and hit the "Flex Application" choice

Step 26 - If everything worked, you should now be staring at the application and should have a message that the channel has connected.

Step 26 - If everything worked, you should now be staring at the application and should have a message that the channel has connected.

Step 27 - Now send a text message to the JMS topic using your favorite JMS client and enjoy the result!

Step 27 - Now send a text message to the JMS topic using your favorite JMS client and enjoy the result!

That should do it! Enjoy your new found JMS happiness. As a reference, a Channel is what the Flex application uses to communicate with BlazeDS and can be HTTP or AMF. A Destination is where you send the messages to and from. A lot of the examples i’ve found don’t show you how to declare what channel you’re talking to as it’s supposed to be handled automatically, i’ve found this to be unreliable and once I started specifying the channel everything started working flawlessly so i’m staying with it. Also, you can do multiple channels for redundancy and such, but that’s a lesson for another day. ;)

, , , , , , , , , , , ,

2 Comments

Reasons why Adobe should give away Flash

After my recent FreeBSD experience, I came to the realization that a large part of my web experience depends on Flash. Not having a decent Flash player in BSD was a big turn off to the OS as a viable desktop environment. Oh sure, you can use the Linux binary emulator to run a Linux version of Firefox and Flash under the BSD kernel. That’s definitely neat, but just not practical. And what about other platforms that can’t emulate Linux or Windows? Are they just out in the cold? Well, not exactly. There are FOSS alternatives, like Gnash and others. Anybody who has tried to use these things knows they aren’t exactly a joyride. No offense to these guys, they’re doing the best they can with what they have to work with from Adobe, which is basically nothing. Reverse engineering something as complex as Flash can’t be easy. Hats off to the Gnash team and others for trying to help.

With this being said, i’ve come up with what I believe to be compelling reasons for Adobe to open up the doors to Flash for the rest of the world to truly embrace it. Now, when I say “open up the doors to Flash”, I do not mean give up the source code. That’s really not practical. No, what i’d like to see is for Adobe to open up the format for everyone to use. I understand that they can’t very well open up the full source code to the Flash player without giving up on some trade secrets, but would opening up the file format kill them?

Technological Reasons

  • It’s old enough. The money has been made, adoption is at it’s peak. Give it away and allow it to spread it’s wings even further. Keep it proprietary and watch as people being to migrate away from it. (More on this later)
  • A large majority of the web sites out there depend on Flash content, yet the player isn’t supported on all platforms. Support for some of those platforms is pretty pitiful. I know there’s not a lot of demand for commercial UNIX versions, I get it, but still…
  • The FOSS developers would most likely provide support on all of the platforms. Leading in from my last point… hey Adobe, if you want Flash on all platforms, then give it to people who love their platforms enough to put it there.
  • Alternative technologies (like Silverlight) will not stand a chance against a format that is applicable to all users with all browsers. The market is speaking out and buying alternative platforms and hardware. People are experimenting with their machines again.
  • Applications will start to use Flash as a format for other things, not just web applications. Creativity will set in eventually and the Flash format will soar to new heights. Just imagine the amazing widget engine that could be built using Flash/ActionScript instead of HTML/CSS/JavaScript!
  • SVG didn’t do so hot in the web world. (Makes for a great icon though!) It was misunderstood and poorly implemented in most cases. We’re sorry that didn’t go so well, but Flash is already seated. Just open up the format and solidify it’s position as a first rate content format.

Business Reasons

  • The current Flash money making model is to sell environments to build high quality Flash content. Opening the format will open the door for competition in this arena, thus giving alternatives to those who don’t like the current Flash editor. This may be considering a negative by some, as Adobe will have to try harder to build the best Flash editor money can buy. In the end, competition will only drive these companies harder and the consumer will be the winner.
  • Be the company that gave Flash to the world, similar to what Sun is trying to do with Java. Build products that use Flash and sell those, don’t hog the Flash format. Don’t be the company that drove us away from Flash. Remember, today’s computer geek is tomorrow’s IT lead. :-)
  • It’s cheaper to release a format specification and a reference player than it is to release a player for all platforms. Make the Windows/Mac player if you’d like, and let the FOSS guys handle the rest if you choose not to. Hey, here’s an idea… how about an open source version of the Linux player that can be extended more than the normal player. Maybe some alternate graphics engine support, similar to the current generation’s alternative sound engine support. (Which was a great move from Adobe). I’m sure Apple would like to get their hands on the MacOSX player to build a highly optimized version. I’m sure the Linux guys would love to as well.

Ethical Reasons

  • People will sing the praises of the company that makes and supports open formats. Flash will become “a standard”. Not just a “we use it because they’re isn’t anything better out there right now”
  • It’s a really nice thing to do. We’d really appreciate it. (Do I have to beg here?)

In closing… Adobe, please open up Flash. Take the lead here, give the Flash format to the world and let us build some amazing applications with it! Don’t make us invent something better. It can happen. Don’t believe me? Just take a look at how much Flash market share has already been lost to CSS. :-)

, , , , , , ,

No Comments