Connector Web Queue
axConnectorWebQueue
Description
axConnectorWebQueue adds the functionality to open a web queue between AXES and the server making it possible to send and receive messages between them. This extension also provides the functionality to implement scripts for messages received from the server.
Usability
|
Context |
Supported |
|---|---|
|
Input screen fields |
No |
|
Output screen fields |
No |
|
Input subfile fields |
No |
|
Output subfile fields |
No |
|
New screen elements |
Yes |
Properties
|
Name |
Description and Comments |
JavaScript |
Shipped default |
|---|---|---|---|
|
hostEndPoint |
Specifies the web service endpoint URL. |
Yes. Must return a string. |
ws:// |
|
hostUserId |
Specifies the user id to connect to a web service. |
Yes. Must return a string. |
None. |
|
hostPassword |
Specifies the password to connect to a web service. |
Yes. Must return a string. |
None. |
|
onConnectionClosed |
Javascript code to be executed when the connection has been closed by either the client or the server. Receives ENV.cwqMessage object with the following properties: code - Reason code clean – True indicates a planned shutdown reason – Reason for closing the connection |
Yes. |
// {Object} ENV.cwqMessage{code, clean, reason} |
|
onConnectionOpened |
Javascript code to be executed when the connection has been opened to the server. |
Yes. |
None. |
|
onConnectionReady |
Javascript code to be executed when the queue is ready. Receives ENV.cwqMessage string as the queue id. |
Yes. |
// {String} ENV.cwqMessage - messageQueue. |
|
onDataPushedByServer |
Javascript code to be executed when the server has pushed a message with a text based data. Receives ENV.cwqMessage object with the following properties: textFormat - Format of the text data – Text from server message – Unfiltered message received from the server as JSON string. |
Yes. |
// {Object} ENV.cwqMessage{textFormat, data, message} |
|
onErrorReceived |
Javascript code to be executed when error has been received. Receives ENV.cwqMessage string as the error message. |
Yes. |
// {String} ENV.cwqMessage - error message. |
|
onMessageAccepted |
Javascript code to be executed when the message sent to the host has been accepted. Receives ENV.cwqMessage string as the message id. |
Yes. |
// {String} ENV.cwqMessage - message id |
|
onMessagePushedByServer |
Javascript code to be executed when the server has pushed a message. Receives ENV.cwqMessage string as the message text. |
Yes. |
// {String} ENV.cwqMessage - message text |
|
onMessageRejected |
Javascript code to be executed when the message sent to the host has been rejected. Receives ENV.cwqMessage object with the following properties: messageId – Message identifier of the message that was rejected. code - Code for the reason the message was rejected. reason – Reason why the message was rejected. |
Yes. |
// {Object} ENV.cwqMessage{messageId, code, reason} |
|
parameters |
Specifies the parameters to pass with the connection request. |
No. |
None. |
|
queueId |
Specifies the name of the queue. |
Yes. Must return a string. |
None. |
Notes, Comments and Warnings
This extension provides the ability to open a web queue.
Refer to Examples how to open a queue.
To handle the message received from the server, implement the script to the events properties attached to this extension. Some of the events contain data that is stored in ENV.cwqMessage variable in the form of an object or String. (Refer to description of properties for details.)
In order to send a message, there must be a Command Language(CL) server program that sends the files to a Web application.
To send messages to the server, use AXES.IBMiService.ConnectorWebQueue API.
Example:
AXES.IBMiService.ConnectorWebQueue.send(messageId, message, file);
In addition, please take note of the following:
- in case axConnectorWebQueue extension is added to the screen, its render timing is after all the extensions have been loaded.
- a web queue can also be opened using AXES.IBMiService.ConnectorWebQueue API instead of this extension.
- only one web queue can be opened. In case there are other extensions calling the open web queue, the last one to process open web queue will be the one to receive the messages sent by the server.
- the web queue is closed when screen is locked in the developer mode.
Example
On the System i Main Menu, add the axConnectorWebQueue extension to the screen. Set a valid value to the following properties:
Example,
hostEndPoint: ws://<endpointURL:port>/service/webqueue.jsp
hostUserId: <valid user id>
hostPassword: <valid password>
queueId: <valid queue id>
onConnectionOpened: alert("ext-open");
onConnectionReady: alert("ext-Ready:" + ENV.cwqMessage);
Save and unlock the screen.
The alert message “ext-open” will be displayed.
Close the alert message, then the message “ext-Ready: ” including the queueId will be displayed.
To send a message to download data, add an axButton eXtension to the screen.
Set its caption property to “Send message”.
On its, onClick property,type the following:
AXES.IBMiService.ConnectorWebQueue.send"DMSG002", "DEF");
Note: Provided that “DEF” is the message for a text file in the server
Update the following axConnectorWebQueue extension’s properties:
onMessageAccepted: alert("ext-messageAccepted:" + ENV.cwqMessage);
onMessagePushedByServer: alert("Message pushed.\nMessage was: " + ENV.cwqMessage);
Save and unlock the screen.
After the message is displayed for ready,click the “Send message” button.
The alert message “ext-messageAccepted” including the message id will be displayed.
Close the alert message, then the message “Data pushed.\n textFormat: PLAIN” will be displayed.
To close the queue, add another axButton eXtension to the screen.
Set its caption property to “Close queue”.
On its, onClick property, type the following:
AXES.IBMiService.ConnectorWebQueue.close(4100, "Closed by button click.");
Update the following axConnectorWebQueueextension’s property:
onConnectionClosed:
alert("ext-closed");
Save and unlock the screen.
After the message is displayed for ready,click the “Close queue” button.
The alert message “ext-closed” will be displayed.
See Also
Extension Scripting Reference - aXes Connector Web Queue Object Functions and Features
ConnectorJS WebQueue developer guide
