FUSE Ajax Tutorial. 07/06 Version 1.2

Similar documents
LogicBlaze FUSE for WebSphere Application Server Community Edition Integration Guide

Comet and WebSocket Web Applications How to Scale Server-Side Event-Driven Scenarios

Distributed Systems. Messaging and JMS Distributed Systems 1. Master of Information System Management

Chapter 10 Web-based Information Systems

AJAX Programming Overview. Introduction. Overview

Web Engineering (CC 552)

We aren t getting enough orders on our Web site, storms the CEO.

Web Application Security

Lesson 12: JavaScript and AJAX

SSC - Web applications and development Introduction and Java Servlet (I)

What the Bayeux? Filip Hanik. SpringSource Inc Keystone, Colorado, Slide 1

Group 1. SAJAX: The Road to Secure and Efficient Applications. - Final Project Report -

GI PageBus AMS Integration Demo

Zero Latency HTTP The comet Technique

Adobe ColdFusion (2016 release)

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

ESIR SR. Unit 10a: JGroups. François Taïani

AMon A Monitoring System for ActiveMQ

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

1 Introduction. 2 Web Architecture

AJAX Programming Chris Seddon

JBoss to Geronimo - EJB-MDB Migration

CSCI 201L Written Exam #1 Fall % of course grade

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

Composer Help. Web Request Common Block

Introduction Haim Michael. All Rights Reserved.

User s Manual for uknowva


X100 ARCHITECTURE REFERENCES:

Adobe ColdFusion 11 Enterprise Edition

Contents. 1. JSF overview. 2. JSF example

CS 268 Lab 6 Eclipse Test Server and JSPs

Module 6 Node.js and Socket.IO

Programming for Digital Media. Lecture 7 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Deltek Touch Expense for Ajera. Touch 1.0 Technical Installation Guide

Tapestry. Code less, deliver more. Rayland Jeans


JavaScript Specialist v2.0 Exam 1D0-735

An Introduction to AJAX. By : I. Moamin Abughazaleh

Using Adobe Flex in JSR-286 Portlets

The University of Bradford Institutional Repository

Oracle Service Bus. 10g Release 3 (10.3) October 2008

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

Configuring User Defined Patterns

,

Ajax HTML5 Cookies. Sessions 1A and 1B

describe the functions of Windows Communication Foundation describe the features of the Windows Workflow Foundation solution

Streaming Presentation Manager User Guide

CSE 115. Introduction to Computer Science I

Rich Web UI made simple Building Data Dashboards without Code

edocs Home > BEA AquaLogic Service Bus 3.0 Documentation > Accessing ALDSP Data Services Through ALSB

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

Credits: Some of the slides are based on material adapted from

A Closer Look at XPages in IBM Lotus Domino Designer 8.5 Ray Chan Advisory I/T Specialist Lotus, IBM Software Group

web.xml Deployment Descriptor Elements

Notes. Submit homework on Blackboard The first homework deadline is the end of Sunday, Feb 11 th. Final slides have 'Spring 2018' in chapter title

Fall Semester (081) Module7: AJAX

20486-Developing ASP.NET MVC 4 Web Applications

PRODUCT DOCUMENTATION. Installing and Implementing Enterprise Contact Center Chat RELEASE 5.1

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

Flex and Java. James Ward. twitter://jlward4th Adobe Systems Incorporated. All Rights Reserved.

Web application Architecture

Software Paradigms (Lesson 10) Selected Topics in Software Architecture

WebSphere MQ Update. Paul Dennis WMQ Development 2007 IBM Corporation

Create-A-Page Design Documentation

Using items from a colleague s course

WS/HTTP-DDS Accessing Real-Time DDS Data From Web-Based Clients

Notes General. IS 651: Distributed Systems 1

Working with Javascript Building Responsive Library apps

FUEGO 5.5 WORK PORTAL. (Using Tomcat 5) Fernando Dobladez

When created, it is given a name.

CENG 256 Internet Programming Draft

Tivoli Common Reporting V Cognos report in a Tivoli Integrated Portal dashboard

REV. NO. CHANGES DATE. 000 New Document 5 May 2014

Project Title REPRESENTATION OF ELECTRICAL NETWORK USING GOOGLE MAP API. Submitted by: Submitted to: SEMANTA RAJ NEUPANE, Research Assistant,

RQs + PEs: More Servlets

Active Endpoints. ActiveVOS Platform Architecture Active Endpoints

This Readme describes the NetIQ Access Manager 3.1 SP5 release.

Using the Prime Performance Manager Web Interface

WA2018 Programming REST Web Services with JAX-RS WebLogic 12c / Eclipse. Student Labs. Web Age Solutions Inc.

User Interaction: jquery

Restful Application Development

Overview. Principal Product Manager Oracle JDeveloper & Oracle ADF

Real-Time SignalR. Overview

Building Large Scale Distributed Systems with AMQP. Ted Ross

Red Hat JBoss Fuse 6.1

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

COSC 2206 Internet Tools. The HTTP Protocol

JADE TCP/IP Connection and Worker Framework

CSE 115. Introduction to Computer Science I

TIME SCHEDULE MODULE TOPICS PERIODS. HTML Document Object Model (DOM) and javascript Object Notation (JSON)

CS 498RK FALL RESTFUL APIs

Lotus Exam IBM Websphere Portal 6.1 Application Development Version: 5.0 [ Total Questions: 150 ]

Asynchronous Ajax for Revolutionary Web Applications. Jeanfrancois Arcand Ted Goddard, Ph.D.

WWW. HTTP, Ajax, APIs, REST

Developing ASP.Net MVC 4 Web Application

5.1 Registration and Configuration

CSCI 201L Written Exam #1 Fall % of course grade

EPHP a tool for learning the basics of PHP development. Nick Whitelegg School of Media Arts and Technology Southampton Solent University

Transcription:

07/06 Version 1.2

This is a tutorial for a real world example of a stock portfolio publisher using Ajax and Apache ActiveMQ (AMQ). This demonstration uses features of Ajax to show multiple interactive components on the same Web page. The components in this case are a live portfolio and chat room. Copyright 2006 LogicBlaze, Inc.. All rights reserved. The contents of this publication are protected by U.S. copyright law and international treaties. Unauthorized reproduction of this publication or any portion of it is strictly prohibited.

1. Introduction This demo uses the example of a Stock Portfolio to demonstrate the use of Ajax and Apache ActiveMQ and to show how to integrate them. Ajax (short for Asynchronous JavaScript and XML) is an approach to web application programming involving many technologies. Web applications require many time-consuming page reloads after calling the server. The purpose of Ajax is to minimize page reloads by sending only the necessary data to the server instead of sending the entire page. Inside Ajax one can use XHTML and CSS for standards-based presentation, dynamic display and interaction. The Document Object Model, XML and XSLT conduct the data exchange and manipulation. Then we use XMLHttpRequest for asynchronous data retrieval. Lastly we use JavaScript to bind everything together. The result is a Web application that provides almost instant feedback from the back-end with no downtime from page reloads without having to use proprietary technologies. Apache ActiveMQ supports Ajax using the same basis as the REST connector for Apache ActiveMQ. The REST connector allows any Web capable device to send or receive messages over JMS. Please refer to the Introduction to the Apache ActiveMQ document for more information on Apache ActiveMQ. Ajax and LogicBlaze FUSE's SOA go hand in hand. In the LogicBlaze SOA model business services can be exposed through XML web services. Ajax clients are excellent consumers for these services. 2. Running the Demo The Ajax demo is preinstalled and ready to run as part of the LogicBlaze FUSE distribution. To run the demo follow the instructions in Running the Demo below. To run the demo: 1. Start LogicBlaze FUSE per the LogicBlaze FUSE Getting Started Guide 2. In a browser, go to http://localhost:8080/ajax-demo. 3. When the page opens you will notice you have two links. Click on both of them. The links will automatically open in a new window. 4. In the LogicBlaze FUSE Portfolio Publisher window you will see a list of stocks. Feel free to select or deselect as many stocks as you wish. We suggest leaving a few checked for the sake of the example. 3

5. In the Ajax Demo window you will see your Portfolio. 4

Portfolio To add a stock to your portfolio, type in any stock name (names are case sensitive) listed in your Portfolio Publisher window into the "Add to Watch List" field. Type in a number to the"holding" field. Click "Add Symbols to List" to add the information from the field to your Portfolio. To subtract a stock from your portfolio simply uncheck the check box from next to the stock's symbol. Stock Chat Type in a user name in the Username field. "Elvis" has been pre-entered for your convenience. To join a chat room for a stock click on the face icon in the chat column that is associated to the stock that you wish to chat about. Your name will appear in the Members column. You will receive an error message if you fail to add a username. Type in a message in the Chat field and click "Send" to send message. You will receive an error message if you fail to type a message. Click "Leave" to leave room. 6. Now that you have your Portfolio set up click the "Submit" button in your "Portfolio Publisher" window. 7. Watch your portfolio change based the rate established by your "Update Period" field. 8. Navigate into the LogicBlaze FUSE Console and scroll down to the "Topics" Portal to see details. For instructions on the console please see the LogicBlaze FUSE Console Guide. The other links located on your Portfolio page are there to show you what you can do. They are not functioning links. 5

2.1. How the Ajax Demo Works This section traces the Ajax demonstration emphasizing the value of the architecture used. The portfolio - time emphasis This demo will trace the path of a message in accordance to the figure. After reading this section you will better understand the principals of Ajax and messaging in Apache ActiveMQ. 1. When a user joins a room inside the portfolio, a message is sent from the user's interface to the Ajax engine. Please visit the Sending Messages section for more information. 2. The Ajax engine takes the JavaScript call and makes the appropriate HTTP requests. The HTTP transport takes the request to the Jetty web server. Please refer to the MessageListenerServlet portion of this document for more information. 3. The Jetty Web server sends the information requested back to the Ajax engine in the form of XML. Please visit the Receiving Messages and Polls section for more information. 4. The XML is sent back to the user interface in the form of HTML data for the user's browser to display the results of the call made in step one. 6

2.2. The Portfolio Messaging Emphasis This section is a detailed look at the stock portfolio and how it messages. 1. Open http://localhost:8080/ajax-demo and open the two links main.html (the portfolio) and publisher.html (the publisher). In the main.html file notice there is a chat section and a stock table. For data to appear in the stock table or messages to appear in the chat window messages must be sent and received. 2. Inside publisher.html select the stocks that match the ones listed in our portfolio's stock table by checking the appropriate check boxes. By clicking "Submit" the PortfolioPublisherServlet is called. This file is a Java class that creates numbers for the checked stocks the data using random number generation functionality. The location of the PortfolioPublisherServlet is mapped by the web.xml located in the WEB-INF directory. The web.xml file contains the mapping of servlets. 3. The Ajax features are provided on the client side by the amq.js script. This script depends on the behaviour.js and prototype.js script. All of these scripts are loaded to the main.html by the default.js as follows. <script type="text/javascript" src="/context/js/default.js"></script> Including these scripts results in the creation of a JavaScript object called AMQ, which provides the API the ability to send messages and to subscribe to channels and topics. 7

4. As the user interacts with the main.html requests are created and take the form of JavaScript that calls on the Ajax layer. An example of this is sending messages when joining or leaving a room. The following from the chat.js file shows this: amq.sendmessage(room._chatmembership, "<message type='join' from='" + room._username + "'/>"); and amq.sendmessage(room._chatmembership, "<message type='leave' from='" + room._username + "'/>"); The destination for these messages is room: _chatmembership and the message is to join or leave the room. These two functions are available to us through the functionality of the Ajax layer. The calls go out to the messagelistenerservlet. From the messagelistenerservlet they go to the AMQ Message Broker. See Sending a Message and Message Listener Servlet sections for more information. 5. Messages come back from the AMQ Message Broker and the JavaScript in chat.js and portfolio.js are used to display back to the user the contents of the messages. For example, to add a row to the stock table or join a chat room you have to register a listener to be able to receive the information that is being sent out by others. This following line of code in portfolio.js adds a listener for each new stock row a user creates: amq.addlistener('stocks','topic://stocks.' + stock, portfolio._quote); This following line of code in chat.js checks for new messages in the chat: amq.addlistener('chat',room._chatmembership,room._chat); When you register listeners you must send a message subscription request to the server as a POST like any other message but as type listen. To learn more about receiving messages please refer to the Receiving Messages and Polls section of this document. 8

2.3. How to Message in LogicBlaze FUSE This section will cover the information you need to know to successfully message in LogicBlaze FUSE using the Apache AcitveMQ messaging capabilities. Message Listener Servlet The Ajax features of AMQ are handled on the server side by the MessageListenerServlet. This servlet is responsible for tracking the existing clients (using a HttpSession) and for creating the AMQ and javax.jms objects required by the client to send and receive messages (for example, Destination, MessageConsumer, MessageAvailableListener). This servlet should be mapped to /AMQ/* in the Web application context serving the Ajax client (this can be changed, but the client JavaScript amq.uri field needs to be updated to match.) <servlet> <servlet-name>messagelistenerservlet</servlet-name> <servlet-class>org.apache.activemq.web.messagelistenerservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> Sending Messages To send a JMS message from the JavaScript client is done by calling the method: amq.sendmessage(mydestination,mymessage); where mydestination is the URL string address of the destination (for example, topic://my.name or channel://my.name) and mymessage is any well formed XML or plain text encoded as XML content. When a message is sent from the client it is encoded as the content of a POST request, using the prototype API for XmlHttpRequest. The AMQ object may combine several sendmessage calls into a single POST if it can do so without adding additional delays (see polls below). When the MessageListenerServlet receives a POST, the messages are decoded as application/x-www-form-urlencoded parameters with their type (in this case send as opposed to listen or unlisten - see below) and destination. If a destination channel or topic do not exist, it is created. The message is sent to the destination as a TextMessage. 9

Receiving Messages To receive messages, the client must define a message handling function and register it with the AMQ object. For example: var myhandler = { rcvmessage: function(message) { alert("received "+message); } }; amq.addlistener(myid,mydestination,myhandler.rcvmessage); where myid is a string identifier that can be used for a later call to amq.removehandler(myid) and mydestination is a URL string address of the destination (e.g. topic://my.name or channel://my.name). When a message is received, a call back to the myhandler.rcvmessage function passes the message to your handling code. When a client registers a listener, a message subscription request is sent from the client to the server in a POST in the same way as a message, but with a type of listen. When the MessageListenerServlet receives a listen message, it creates a MessageAvailableConsumer and registers a Listener on it. Polls When a Listener created by the MessageListenerServlet is called to indicate that a message is available, due to the limitations of the HTTP client-server model, it is not possible to send that message directly to the Ajax client. Instead the client must perform a special type of Poll for messages. Polling normally means periodically making a request to see if there are messages available and there is a trade off: either the poll frequency is high and excessive load is generated when the system is idle; or the frequency is low and the latency for detecting new messages is high. To avoid the load vs. latency trade-off, AMQ uses a waiting poll mechanism. As soon as the amq.js script is loaded, the client begins polling the server for available messages. A poll request can be sent as a GET request or as a POST if there are other messages ready to be delivered from the client to the server. When the MessageListenerServlet receives a poll it: 1. If the poll request is a POST, all send, listen and unlisten messages are processed 2. If there are no messages available for the client on any of the subscribed channels or topic, the servlet suspends the request handling until: A MessageAvailableConsumer Listener is called to indicate that a message is now available; or A timeout expires (normally around 30 seconds, which is less than all common TCP/IP, proxy and browser timeouts). 3. A HTTP response is returned to the client containing all available messages encapsulated as text/xml. 10

When the amq.js JavaScript receives the response to the poll, it processes all the messages by passing them to the registered handler functions. Once it has processed all the messages, it immediately sends another poll to the server. Thus the idle state of the AMQ Ajax feature is a poll request "parked" in the server, waiting for messages to be sent to the client. Periodically this "parked" request is refreshed by a timeout that prevents any TCP/IP, proxy or browser timeout closing the connection. The server is thus able to asynchronously send a message to the client by waking up the "parked" request and allowing the response to be sent. The client is able to asynchronously send a message to the server by creating (or using an existing) second connection to the server. However, during the processing of the poll response, normal client message sending is suspended, so that all messages to be sent are queued and sent as a single POST with the poll that will be sent (with no delay) at the end of the processing. This ensures that only two connections are required between client and server (the normal for most browsers). Threadless Waiting The waiting poll described above is implemented using the Jetty 6 Continuation mechanism. This allows the thread associated with the request to be released during the wait, so that the container does not need to have a thread per client (which may be a large number). If another servlet container is used, the Continuation mechanism falls back to use a wait and the thread is not released. 3. Additional Resources ActiveMQ Web site: http://activemq.org Article explaining Ajax: http://www.adaptivepath.com/publications/essays/archives/000385.php Article about Ajax and SOA: http://www.xml.com/lpt/a/2005/10/05/ajax-web-20-soa.html Web sites on Ajax: http://www.ajaxinfo.com, http://www.ajaxian.com 11