This section describes how to run the REST example, which consists of a servlet engine integral to the message broker binary, and some demonstration servlets that run as a Web application. To connect to the Web applications, you can use your favorite Web browser.
You must ensure that the message broker is configured to instantiate an embedded servlet engine. In your broker configuration file, conf/activemq.xml, check that there is a jetty element configured as shown in Example 4.1
.
Example 4.1. Configuration of an Embedded Servlet Engine
<!-- Embedded servlet engine for serving up the Admin console
-->
<jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
<connectors>
<nioConnector port="8161" />
</connectors>
<handlers>
<webAppContext contextPath="/admin"
resourceBase="${activemq.base}/webapps/admin"
logUrlOnStart="true" />
<webAppContext contextPath="/demo"
resourceBase="${activemq.base}/webapps/demo"
logUrlOnStart="true" />
</handlers>
</jetty>
With the configuration shown in Example 4.1 , the servlet engine opens up a HTTP port on IP port, 8161. The following Web applications are loaded:
Demonstration application (from webapps/demo),
REST protocol servlets (from webapps/demo).
Web console servlet (from webapps/admin),
To run the REST Web example, perform the following steps:
To run the embedded servlet engine, open a new command window and enter the following command to start the default message broker:
activemq
This step assumes that your broker is configured as described in Example prerequisites .
Open your favorite Web browser (for example, Firefox or Internet Explorer) and navigate to the following URL:
http://localhost:8161/demo
Your browser should now show the welcome page for the Web examples, as shown in Figure 4.1 .
To view the form for publishing messages, click the link, Send a message. The Send a JMS Message form now appears in your browser, as shown in Figure 4.2 .
In the Destination name text field, enter FOO.BAR to send a message to the FOO.BAR queue. Leave the Destination Type as Queue. Then enter an arbitrary text message in the large message text box. Click the Send button at the bottom of the form to send the message.
Using the history feature of your browser, navigate back to the example welcome page (see Figure 4.1
). The queueBrowse servlet supports a variety of ways to browse the contents of a queue and these are listed at the bottom of the welcome page. The following browsing options are listed:
If you click on Browse a queue, you should see a page like Figure 4.3 .
If you click on Browse a queue as XML, you should see a page like Figure 4.4 .
If you click on Browse a queue as Atom, you should see a page like Figure 4.5 .
If you click on Browse a queue as RSS 1.0 or Browse a queue as RSS 2.0, you should see a page like Figure 4.6 .
To receive a message from the FOO.BAR queue, open the example welcome page in your browser, http://localhost:8161/demo, and click the link, Receive
a message.
You should now see the text of the message that you sent earlier. You will probably also receive an error from your browser, if the message is not formatted as HTML or XML (which the browser expects).