HTTP and JMS connectivity sample details

After you set up the sample, you can run it. You can also import and study the source files to learn how the web application, solution, and connectivity interact to send and receive events.

Running the sample

  1. Open a web browser and enter the following URL:
    http://localhost:<PORT>/eventSender/
    where <PORT> is the port that is used by the sample server. The default port is 9080.

    The following web application is displayed:

    HTTP and JMS connectivity sample web application

  2. Specify some field values, select a connection type, and click Send event.
A response page opens, in which you see the response that is sent as output. The response page contains information similar to the following message:
accountId12015-02-10T09:53:23.912-05:00R02The transaction amount of 10000.0 is too large.R02: Transaction amount is too largeaccountId110000.0FR2015-02-10T09:53:23.912-05:00Super KStoreValbonne

Source files

The sample source files are in <InstallDir>/samples/connectivity.

You can view the files in Decision Server Insights by importing them. To import the sample into your workspace, click Import projects in the Samples and Tutorials view. The following items are imported:
  • The project connectivityServlet, which defines the web application that uses the connectivity.
  • ConnectivitySolution, the solution project for which the connectivity is defined in ConnectivitySolution/Connectivity Definitions/httpConnectivity.cdef and jmsConnectivity.cdef. A transformation is defined in ConnectivitySolution/Transformations.
  • ConnectivityAgent, a Java™ agent that is used by the solution.
  • ConnectivityRules, a rule agent that is used by the solution.
  • ConnectivitySolution - Java Model, which contains the Java interfaces of the solution.
  • ConnectivitySolutionBOM, the BOM of the solution.

In this simplified solution, the Java agent processes the events by using Java code and reads information from a simplified data store. The rule agent processes the events by using rules that compare and analyze the transaction events.

The Ant tasks that are used to deploy the sample are defined in build.xml.

The connectivityServlet project contains the following items:
  • The data folder, which contains the files that were exported from the solution project: the solution archive file and the exported connectivity definitions.
  • The webapp folder, which contains the web application folders and files. The items include sample.jsp for the JSP page description, css and images for the style description, and WEB-INF/web.xml, which is the web application descriptor that defines the servlet.
  • The src folder, which contains the Java source code:
    • The sample.connectivity package contains SendEventServlet.java, which describes the servlet and delegates to the appropriate protocol helper; JMSHelper.java, which describes the JMS protocol; and HTTPHelper.java, which describes the HTTP protocol.
    • The sample.utility package contains Parameters.java, which decodes the parameters from the request, and StringHelper.java, which manipulates strings and streams.

How this sample works

The connectivity definitions are in the httpConnectivity.cdef and jmsConnectivity.cdef files of the ConnectivitySolution project. These files define the bindings and endpoints of the solution for HTTP and JMS protocols. For both protocols, transaction events are accepted and authorization response events are delivered.

The accepted messages match a given classifier and apply a transformation to the event. The event is received as a flat event and is transformed into the appropriate hierarchical event. For example:
<event:Transaction>
   <amount>10000</amount>
   <countryCode>FR</countryCode>
   <account>accountId1</account>
   <merchantId>Super K</merchantId>
   <merchantType>Store</merchantType>
   <location>Valbonne</location>
</event:Transaction>
is transformed to
<event:Transaction>
   <event:amount>10000</event:amount>
   <event:countryCode>FR</event:countryCode>
   <event:account>accountId1</event:account>
   <merchant>
      <event:id>Super K</event:id>
      <event:type>Store</event:type>
      <event:location>Valbonne</event:location>
   </merchant>
</event:Transaction>

The .cdef files also define the URL, the JMS connection factory, and the destination.

The connectivity resources that are required to run the sample are stored in the connectivityServlet/data/connectivity-server-configuration.xml file. This file was exported from the solution by using the Export Solution Connectivity Server Configuration wizard. This file is deployed to the cisDev server by the connectionManager command, which is called by the Ant task deploy.connectivity, which is defined in the build.xml file.

Instructions to define the message engine were added to the generated file connectivity-server-configuration.xml. For simplicity in this sample, the cisDev server is used as the message server. In a production environment, a separate message server would be defined.

The solution archive is deployed to the cisDev server by the solutionManager command, which is called by the Ant task deploy.solution.

The web application uses a servlet SendEventServlet, which you can examine in the connectivityServlet/src/sample/connectivity/SendEventServlet.java file.

In the SendEventServlet.java file, the doGet method decodes the request parameters and posts a response according to the selected protocol.

For the JMS protocol, the doGet method does the following actions:
  • Initializes the connection, the queues, and the messages producer and consumer, then starts the connection
  • Builds a transaction event in XML format that uses the request parameters and sends it by using the producer
  • Receives an authorization response event from the message consumer
  • Closes the JMS connection and session
  • Displays the response in the response page
For the HTTP protocol, the doGet method does the following actions:
  • Initializes the connection
  • Builds a transaction event in XML format by using the request parameters and writes the event to the URL
  • Waits for the response event to be posted and display it in the response page

For the HTTP protocol, the doPost method copies the string output from the request.

For the purposes of this sample, some of the code for the web application is simplified. In a production application, for example, a more robust approach to receive HTTP responses is required.

Rebuilding the sample

After you use or modify the sample, you can rebuild it to its original state.

  1. In the Samples Commands view, open Samples Commands > Samples > HTTP and JMS Connectivity.
  2. Double-click redeploy to undeploy and redeploy the solution, and to clean, rebuild, and deploy the web application.