The Web messaging service consists of a run time JavaTM archive (JAR) file that gets placed in the WebSphere® Application Server installation directory and a library designed to be inserted into a new or existing Web module as a utility JAR file. This section provides brief instructions on enabling the Web messaging service and developing a Web messaging enabled application. Including in this section are links to more detailed sections. In addition, the QuoteStreamer Sample application can be examined and used as a starting point for developing Web messaging enabled applications.
Linux® and
UNIX®: <ECLIPSE_HOME>/plugins/com.ibm.websphere.webmsg_1.0.1.0/lib/webmsg_applib.jar |
Windows(TM):
<ECLIPSE_HOME>\plugins\com.ibm.websphere.webmsg_1.0.1.0\lib\webmsg_applib.jar
|
Linux and UNIX: /opt/WebSphere/AppServer |
Windows:
c:\WebSphere\AppServer |
Linux and UNIX:
/opt/WebSphere/AppServer/web2fep/optionalLibraries/MessagingService/webmsg_applib.jar.
|
Windows:
c:\WebSphere\AppServer\web2fep\optionalLibraries\MessagingService\webmsg_applib.jar.
|
You must enable the Web messaging service for a Web messaging enabled application to run. Refer to the Web messaging service enablement instructions for more information.
A Web messaging application must have a configured service integration bus with a defined topic space to run. At a minimum, the bus name must be provided in a Web messaging configuration file for a Web messaging application to function.
The Dojo Toolkit provides client support for the Web messaging service. The easiest way is to include the Dojo Tookit in a Web module. If the Dojo toolkit is not included in a Web module (statically served through web server for example), the Uniform Resource Identifier (URI) location of the dojo.js file must be known to load the Dojo Toolkit in any Web module presentation files.
The best place to insert the Web messaging utility library is in a Web module's WEB-INF/lib directory as a utility library. Copy the webmsg_applib.jar file file located in step 1 into the Web module's WEB-INF/lib directory. You can use the Web messaging utility library in the same Web module as the Dojo Toolkit, or in a different Web module. The key interaction point is the Bayeux protocol communication URI. See the installation steps for further information.
<servlet> <description/> <display-name> WebMsgServlet </display-name> <servlet-name>WebMsgServlet</servlet-name> <servlet-class> com.ibm.websphere.webmsg.servlet.WebMsgServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>WebMsgServlet</servlet-name> <url-pattern>/webmsgServlet</url-pattern> </servlet-mapping> |
In step 9, the URI defined above is used by the Dojo Toolkit cometd client for initialization purposes. A simple initialization statement in a presentation file is used in the step 9 and an example and is shown here for comparison:
The
Web messaging service reads configuration parameters from a configuration
file to handle incoming Web messaging requests. Create a Web messaging
configuration file, webmsg.json, in the WEB-INF directory (same directory
as the web.xml file) similar to the following example. The webmsg.json
file is specified as a JSON Object(map) with each key matching an
existing servlet name mapped to the Web messaging servlet. The Configuration overview section provides
info on all possible configuration options.
{ "WebMsgServlet": { "busName": "thebus", "destination": "Default.Topic.Space", "clientCanPublish": true, "longPollTimeout": 30 } } |
All server
side setup is now complete except for installing the application.
The remaining task is to create the client side logic using the Dojo
Toolkit functions. A simple test example is provided here. Note how
the initialization URI parameter matches the Web messaging servlet
mapping.
<html> <head> <title>cometd client/server test page</title> <script type="text/javascript" src="dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true, debugAtAllCosts: false"></script> <script type="text/javascript"> dojo.require("dojox.cometd"); dojo.addOnLoad(function(){ dojox.cometd.init("webmsgServlet") dojox.cometd.subscribe("/testtopic", window, "display"); } ); function display(msg) { alert("Message " + msg.data.test); } </script> <div align="left"> <button Id="publishButton" onclick="dojox.cometd.publish('/testtopic', {test: 'Data'});"> <span style="font-size:small">PUBLISH</span> </button> </div> </head> <body></body> </html> |
Assemble,
install, and test the application using standard Web application assemble,
installation, and test procedures.