Skip to main content
Skip table of contents

Working with services


Learning objectives
At completion of this learning module, you will be familiar with:

  • The different types of steps that make up a service.
  • How to create a service in NexJ Studio.

  • How to bind a channel to a service.

  • How to add steps to a service, including script steps.

  • How to test a service.

Key concepts
Services are used to tie together integration structures. In NexJ Studio, services are part of the Integration layer. Each service defines a series of steps, similar in concept to a workflow in the Business Model layer. A service passes a token from one step to the next, performing actions on the token at each step.

The steps available to services include:

  • Email - Sends an e-mail message.
  • Format - Serializes a message fom an internal format to its external raw format.
  • Invoke Service -Invokes an integration service.
  • Log - Creates log entries.
  • Parse - Deserializes a message from its external raw format to an internal format.
  • Persist - Updates business model objects from an object message.
  • Script - Executes custom logic from a Scheme script. The returned value is a message that is passed to the next step.
  • Send - Asynchronously sends a message through a channel.
  • Send/Receive - Synchronously sends a message through a channel and waits for a response. The response is a message that is passed to the next step.
  • Set Channel - Sets which channel is used for output.
  • Sync - Synchronizes an object message with business model objects.
  • Transform - Transforms a message into another type of message, which is then passed to the next step.

Creating a service

In this learning activity, you will create a new service.

Learning activity

To create a new service called training:EchoService:

  1. In the Integration layer, select the Services tab.
  2. Right-click the list area inside the tab and select New Service. The New Service dialog opens.

  3. Name the service training:EchoService.

  4. Click Finish. The new service opens in an editor dialog.

Binding an HTTP channel to the service

Let's create a new HTTP channel called training:EchoChannel and bind it to training:EchoService. With binding, when the channel receives a message, it passes it on to the service. When the service has finished processing the message, it sends a response message back through the channel.

Learning activity

To bind a channel to the service:

  1. In the Integration layer, select the Channels tab.
  2. Right-click the list area inside the tab and select New Channel. The New Channel dialog opens.
  3. Specify the following values for the channel:
    • Name: training:EchoChannel
    • Channel Type: HTTP
  4. Click Finish. The new channel opens in an editor.

  5. Enter or drag and drop the following XML code on the Source tab.

    <HTTP contentType="text/html; charset=UTF-8" get="true">
          <ServiceBinding output="training:EchoChannel" service="training:EchoService"/>
  6. Click the Overview tab and set the Content Type to text/html; charset=UTF-8 if this is not already set.

  7. In the HTTP Methods area, ensure that GET and POST are selected.

  8. In the Service Bindings tab, click the Add button

    Add button
    to add a new service binding.

  9. In the General section, specify the following values for the service binding:

    • Service: training:EchoService

    • Output: training:EchoChannel

  10. Click the Save button 

    in the toolbar to save the channel.

    This channel can be accessed through your web browser at http://localhost:7080/training/channel/training:EchoChannel

    If you go to that URL now, you will see a blank response. You need a response message.

Adding a script to the service

Let's add a script step to the EchoService that creates a raw HTTP message.

Learning activity

To add a script step to the service:

  1. In the Integration layer, select the Services tab and open training:EchoService.

  2. To add a script step to the service:

    1. In the Palette, select Script.
    2. Click a location on the line between the start and end of the service.
  3. Select the script icon to open its Property Editor view.
    • Name: createResponse
    • Caption: Create the response. The caption appears in the service diagram.
    • Description: Create a raw HTTP response message and set its 'body' part to an HTML string with information embedded from the raw HTTP request.

  4. In the Script tab, enter the following code:

    (message (: body (format
    	<h2>method:</h2> {0} <h2>parameters:</h2> {1}
    	<h2>path:</h2> {2} <h2>body:</h2> {3}
    	<h2>class:</h2> {4} </body></html>" (this
    	'method) (this 'parameters) (this 'path) (this 'body) (this ':class) ) ) )
  5. Save the changes made to the service.

Testing the service

Test the service by interacting with it using a web browser and viewing the web page the service returns when accessed using the GET and POST methods.

Learning activity

Test the GET method

  1. In your browser, navigate to http://localhost:7080/training/channel/EchoChannel/my/path?param1=this&param2=that

Test the POST method
Test the POST method by creating an HTML form. The information entered into the form is processed and returned by the service.

To create the HTML form:

  1. Create a new file called EchoTest.html and enter the following code:

    <FORM ACTION="http://localhost:7080/training/channel/EchoChannel" METHOD="POST">
    <INPUT TYPE="text" name="test1">
    <INPUT TYPE="submit" name="submit">
  2. Save your work.
  3. Open the file, enter a value and see the result.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.