SOAP to REST Mediation Use Case

Learn how to perform SOAP to REST mediation with a specific use case.

Getting Started with Processes Process Reference

Table of Contents

  1. Introduction
  2. SOAP to REST mediation: use case:
    1. Prerequisites
    2. Create the API
    3. Design the mediation
    4. Run the test case

Introduction

In the developer portal, you can set up SOAP to REST mediation by using the Process Editor.

When you're mediating SOAP to REST, the bindings do most of the work. The main thing you have to do is use the Process Editor to get the content of the message body put together correctly.

The example below uses a simple SOAP service. It walks you through the steps for setting up the API, designing the mediation, and running the test case.

Back to top

SOAP to REST mediation: Number Conversion Service use case

This section provides detailed instructions for setting up and running a SOAP to REST mediation use case using a simple number conversion SOAP service. This example includes the steps to expose a SOAP physical service as a REST service in the developer portal.

It includes:

  1. Prerequisites
  2. Create the API
  3. Design the mediation
  4. Run the test case

Prerequisites

Before starting the main steps, set up the physical service in Policy Manager:

  1. Log in to Policy Manager and register the SOAP physical service (Organization > Services > Create Physical Service > put in the Service Description Document URL. For Service Management Options, choose Do not manage at this time).

    This example uses the Number Conversion SOAP Service: http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL.

Create the API

The next step is to set up the API in the developer portal. Follow the steps below.

To set up the API in the developer portal
  1. Log in to the API Management Portal.
  2. Click the Plus icon to add a new API.
  3. If you see the Add API page shown below, choose Add a new API and click Add.

    Adding a new API

  4. Choose I want to design my API from scratch (REST only). Provide an appropriate name to the API option, enable Advanced Options and choose Orchestration, and then click Save.

    Choose Orchestration

  5. Add all the resources: for each, click Add Resource, provide appropriate context path, and click Save. The resources you'll need to add for this example are indicated below.

    Number Conversion WSDL

  6. Review to make sure you have it correct. The resources for the Conversion SOAP WSDL should look like the below example:
    • Schema element names:

      API Designer; Add Resource view

    • Detail for the Number to Dollar resource:

      API Designer; resource detail view

    • Resulting API summary:

      API Details view

Design the mediation

The next step is to use the process editor to design the SOAP to REST mediation. Follow the steps below.

To set up the SOAP to REST mediation
  1. Click the Implementation tab and select the Live or Sandbox implementation.

    Implementations page

  2. Scroll down to the Resources section and select the Edit Process drop-down, as shown below.

    Accessing the Process Editor

  3. In the Process Editor, click on the Variables and Faults Editor Activity. Add a numberRequest variable with Type of message and a number variable with Type of String, and then click Finish.

    Variables and Faults Editor

  4. Add a Script Activity to get the number. Use the information below to guide you:
    • The GetNumber script for the Number Conversion SOAP Service:
      msg = processContext.getVariable("message");
      msg.normalize();
      // Request Line
      var requestLine = msg.getProperty("http.request.line");
      auditLog.debug("requestLine: " + requestLine);
      var number = msg.getProperty("http.binding.path.params").get("dNum");
      auditLog.debug("Number: " + number);
      processContext.setVariable("number",number);
    • The GetNumber script in the Script Details Editor:

      GetNumber script in Script Details Editor

  5. Add another Script Activity to create the request. Use the information below to guide you:
    • The CreateRequest script for the Number Conversion SOAP Service:
      var numbr = processContext.getVariable("number");
      // Number Conversion
      var numberRequest = msgFactory.create("text/xml");
      var numBody = "<web:NumberToDollars><web:dNum>" + numbr + "</web:dNum></web:NumberToDollars>";
      var numSoap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.dataaccess.com/webservicesserver/"><soapenv:Header/><soapenv:Body>' + numBody + "</soapenv:Body></soapenv:Envelope>";
      numberRequest.setStringContent(numSoap);
      processContext.setVariable("numberRequest", numberRequest);
      auditLog.debug(numberRequest.getContentAsString());
    • The CreateRequest script in the Script Details Editor:

      CreateRequest script in Script Details Editor

  6. Add an Invoke Activity:
    • In the Service QName field, search for the NumberConversion service that you created.
    • In the Service field, select the NumberConversion SOAP Physical Service that is registered from Policy Manager.
    • Select the Interface.
    • In the Operation field, select NumbertoWords and click Next.

      Invocation Details Editor

  7. In the Single Input Message Variable field, select numberRequest, and then click Finish.

    Input/Output Parameters page

  8. In the Process Editor, click the Save icon on the left and then click Finish.

    Saving in the Process Editor

    This sets up the SOAP to REST mediation for the first operation in the service, the Number to Dollar operation.

Run the test case

Now, you can test the number to dollar operation in Test Client to see the SOAP to REST mediation.

  1. Go to Test Client.
  2. Choose the correct operation and endpoint, provide a value for the dNum parameter, and click Invoke. You should get a successful response, with an HTTP 200 OK and a response message in application/json format, as shown below.

    Running the test case in Test Client

Back to top