12-12 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server
chain. The order in which the filters are configured in the wlps:channel element is the order in which they execute.
The following example shows how to configure message filters in the weblogic-pubsub.xml deployment descriptor; only relevant information is shown.
See the text after the example for an explanation:
?xml version=1.0 encoding=UTF-8? wlps:weblogic-pubsub
xmlns:wlps=http:xmlns.oracle.comweblogicweblogic-pubsub wlps:server-config
... wlps:server-config
wlps:message-filter wlps:message-filter-namefilter1wlps:message-filter-name
wlps:message-filter-classmsgfilters.Fiter1wlps:message-filter-class wlps:message-filter
wlps:message-filter wlps:message-filter-namefilter2wlps:message-filter-name
wlps:message-filter-classmsgfilters.Filter2wlps:message-filter-class wlps:message-filter
wlps:channel wlps:channel-patternfirstchannelwlps:channel-pattern
wlps:message-filterfilter1wlps:message-filter wlps:channel
wlps:channel wlps:channel-patternsecondchannelwlps:channel-pattern
wlps:message-filterfilter2wlps:message-filter wlps:message-filterfilter1wlps:message-filter
wlps:channel wlps:weblogic-pubsub
In the example, two filters are declared using the wlps:message-filter element: filter1 implemented by the msgfilters.Filter1 class and filter2
implemented by the msgfilters.Filter2 class.
The channel with pattern firstchannel is then configured with filter1. At run time, this means that all messages published to the direct subchannels of
firstchannel are first pre-processed by the msgfilters.Filter1 class.
The channel with pattern secondchannel is configured with two filters: filter2 and filter1. The order in which these two filters are configured is
important. At run time, all messages published to the direct subchannels of secondchannel are first intercepted and processed by the msgfilters.Filter2
class, then the result of this processing is sent to msgfilters.Filter1 which then does its own processing, and then the result is sent to the subscribers of the channel.
12.3.4 Updating a Browser Client to Communicate with the Pub-Sub Server
To update a browser, or any other Web-based client, to communicate with the pub-sub server, you use a JavaScript library that supports the Bayeux protocol. You can use any
client-side programming framework of your choosing, provided that it supports the Bayeux protocol. Typically you add the JavaScript to your JSP or HTML file, or
whatever implements the Web client.
This section shows an example of using Dojo as the client-side programming framework and updating a JSP. Dojo is a JavaScript-based toolkit that supports the
Bayeux protocol as well as AJAX. Although WebLogic Server does not provide the toolkit as an integral feature, it does include a subset of the libraries as part of the
Using the HTTP Publish-Subscribe Server 12-13
installed pub-sub example; see Section 12.2, Examples of Using the HTTP
Publish-Subscribe Server for details.
There are three main tasks you must perform when programming the Web client to communicate with the pub-sub server:
■
Initialize the Dojo cometd environment. The following example shows a typical way to perform this step:
dojo.io.cometd.init{}, contextcometd; where context refers to the context path of the Web application that hosts the
pub-sub application. This initialization step creates a handshake with the pub-sub server so as to determine the transport type for the connection. If the handshake is
successful, the client connects to the pub-sub server.
The cometd part of the initialization string is required, unless you specifically override the default servlet mappings of the pubsub Java EE library that are
defined in the web.xml file of the library itself. For details of how to do this, see Section 12.3.5, Overriding the Default Servlet Mapping of the pubsub Java EE
Library .
■
Publish a message to a channel. The message can be a simple string message or a JSON message. The following
example shows how to publish a simple message: dojo.io.cometd.publishachannel, message content;
where achannel refers to the name of the channel to which you want to publish the message and the second parameter is the text of the message. The
following example shows how to publish a JSON message:
dojo.io.cometd.publishachannel, {data: content};
■
In this example, the second parameter can be any JSON object.
■
Subscribe to a channel. Before you can actually subscribe to a channel, you must first implement a
callback JavaScript function. This function can have any name; you will later reference the function when you subscribe to a channel. The following example
shows how to implement a JavaScript function called onUpdate:
function onUpdatemessage { if message.data {
alertbad message format +message; return;
} fetch the data published by other clients
var data = message.data; }
To actually subscribe to a channel, use the following JavaScript: dojo.io.cometd.subscribeachannel, null, onUpdate;
where achannel refers to the channel to which you want to subscribe and onUpdate is the name of the callback JavaScript function you previously defined.
12-14 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server
This section covers only the minimal information on using the Dojo toolkit to update a Web based client to communicate with the WebLogic pub-sub server; for additional
details, see http:www.dojotoolkit.orgdocumentation
.
12.3.5 Overriding the Default Servlet Mapping of the pubsub Java EE Library