Try WSO2 Cloud for Free
Sign in

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log in to the API Publisher and click the edit icon of the PhoneVerification API.

  2. Add the following resource to the API. 

    Tip

    Tip: The resource you create here invokes the SOAP 1.2 Web service of the backend. Therefore, the recommended method is HTTP POST. As you do not include the payload in a query string, avoid giving any specific name in the URL pattern, which will be amended to the actual backend URL.

    FieldSample value
    ResourcesURL pattern: /*

    Request types: POST



  3. After the resource is added, expand it and note a parameter by the name payload already available. You can use this parameter to pass the payload to the backend. Edit its values as follows:

    Parameter nameDescriptionParameter TypeData TypeRequired
    payloadPass the phone number and license keybodyEmptyTrue

    Image Modified

    Next, let's write a sequence to convert the JSON payload to a SOAP request. We do this because the backend accepts SOAP requests. 

  4. Navigate to the Implement page and change the endpoint of the API to http://ws.cdyne.com/phoneverify/phoneverify.asmx?WSDL. Once the edits are done, click Save.

  5. Download and install the WSO2 API Manager Tooling Plug-in if you have not done so already. Open Eclipse by double clicking the Eclipse.app file inside the downloaded folder. 

  6. Click Window > Open Perspective > Other to open the Eclipse perspective selection window. Alternatively, click the Open Perspective icon in the top, right-hand corner.

  7. On the dialog box that appears, click WSO2 APIManager and click OK.
  8. On the APIM perspective, click the Login icon as shown below.

  9. On the dialog box that appears, enter your cloud username (in the format <email@company_name>) and password, and click OK.

  10. On the tree view that appears, expand the folder structure of the existing API.
  11. Right-click on the in sequence folder and click Create to create a new in sequence.
  12. Name the sequence JSONtoSOAP.
  13. Your sequence now appears on the APIM perspective. From under the Mediators section, drag and drop a PayloadFactory mediator to your sequence and give the following values to the mediator.

    Tip

    Tip: The PayloadFactory mediator transforms the content of your message. The <args> elements define arguments that retrieve values at runtime by evaluating the provided expression against the SOAP body. You can configure the format of the request/response and map it to the arguments. 

    For example, in the following configuration, the values for the format parameters PhoneNumber and LicenseKey will be assigned with values that are taken from the <args> elements (arguments,) in that particular order.

    For details on how you got this configuration, see PayloadFactory Mediator in the WSO2 ESB documentation.


    Payload
    Code Block
    languagexml
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
        <soap12:Body>
            <CheckPhoneNumber xmlns="http://ws.cdyne.com/PhoneVerify/query">
                 <PhoneNumber>$1</PhoneNumber>
                 <LicenseKey>$2</LicenseKey>
            </CheckPhoneNumber>
         </soap12:Body>
    </soap12:Envelope>
     Args

    Give the following arguments:

    TypeValueEvaluator
    expression
    //request/PhoneNumber
    xml
    expression//request/LicenseKeyxml
  14. Similarly, add a Property mediator to the same sequence and give the following values to the property mediator. 

    Property NamemessageType
    Value TypeLiteral
    Valueapplication/soap+xml
    Property Scopeaxis2
  15. Save the sequence, which is in XML format (e.g., JSONtoSOAP.xml). This will be the In sequence for your API. Next, create an out sequence.

  16. Right-click on the out sequence folder and click Create to create a new out sequence.

  17. Name the sequence SOAPtoJSON. Add a Property mediator to the sequence and give the following values to the property mediator. 

    Property NamemessageType
    Value TypeLiteral
    Valueapplication/json
    Property Scopeaxis2

  18. Save the sequence, which is in XML format (e.g., SOAPtoJSON.xml). This will be the Out sequence for your API.

  19. Click the Push all changes to the server icon shown below to commit your changes to the Publisher server.

  20. Log back to the API Publisher, click the Edit link associated with the API, navigate to the Implement tab, click the Enable Message Mediation checkbox and engage the In and out sequences that you created earlier.
  21. Save the API.
    You have created an API, a resource to access the SOAP backend and engaged sequences to the request and response paths to convert the message format from JSON to SOAP and back to JSON. Let's subscribe to the API and invoke it.
  22. Log in to the API Store and subscribe to the API and create an access token if you have not done so already.

  23. Go to the API Console tab and expand the POST method.

  24. Give the payload in the body parameter in JSON format and click Try it out. Here's a sample JSON payload: {"request":{"PhoneNumber":"18006785432","LicenseKey":"0"}}

  25. Note that you get a JSON response to the JSON request whereas the backend accepts SOAP messages. The request and response are converted by the sequences that you engaged at the API Gateway.

...