Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member197386
Active Contributor
0 Kudos

Introduction

In this post, we will see how you can test quickly RESTful API by using Azot. Azot is a small open source tool which help to execute easily a set of HTTP calls in a workflow without coding.

Azot can be downloaded from here:

download link

It required to have at least JRE 6 installed in your computer to work.To process an Azot workflow, defined into an XML file, you just have to a command like:

java -jar azot.jar myworkflow.xml

Anatomy of an Azot workflow

An Azot workflow is defined in a XML file which allows to specify a series of HTTP calls. What is interesting is that you can indicate to Azot to store a value coming from a HTTP response into a Azot variable. So, you can reuse this value into subsequent calls.

More information about Azot dialect on this wiki page.

To write a workflow, you simply start with:


<workflow>
     <!-- description here -->
</workflow>

Then, to perform a HTTP request, you just have to describe these characteristics. For instance, if you wish to perform a simple call to know which is the version of Webi RESTful APIs you're working with, the Azot script will look like:


<workflow name="Simple About Test">
  <call>
        <request url="http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/raylight/v1/about" method="GET">
            <header name="Accept" value="application/xml" />
        </request>
    </call>
</workflow>

Into a workflow, several calls can be described but here there is only one call. When you describe the HTTP call, you just have to indicate the URL to reach and the HTTP verbe to use. GET, PUT, POST and DELETE are very usual verbs in RESTful APIs. Finally, you can see <header> tag allows to describe HTTP header to specify when performing the call.

To execute a such workflow, you just have to execute it through a command tool:

java -jar azot.jar about.xml


The result will be so:



C:\dev\tools\azot>java -jar azot.jar about.xml
Starting workflow 'Simple About Test'
==========================================================================================
----------------------------------------
| Starting call 'GetDocumentParameters' |
-----------------------------------------
REQUEST:
[GET] http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/raylight/v1/about
header:Accept = application/xml
------------------------------------------------------------------------------------------
RESPONSE:
header:Server = Apache-Coyote/1.1
header:Content-Length = 410
header:Date = Fri, 17 Jun 2016 07:09:20 GMT
header:Content-Type = application/xml
meta:Status = HTTP/1.1 200 OK
meta:HttpCode = 200
meta:Content = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<about>
    <title>Web Intelligence - Raylight</title>
    <version>1.0</version>
    <vendor>SAP BusinessObjects</vendor>
    <build major="14" minor="0" sp="1" patch="0" number="3">14.0.1.3</build>
    <timestamp>20160617.081714</timestamp>
    <copyright>©2010 - 2016 SAP SE or an SAP affiliate company.  All rights reserved.</copyright>
</about>
==========================================================================================

Simple Azot workflow to logon/logoff to the BI4

In a REST workflow, you need to execute a sequence of HTTP calls. And most of the time, you need to pick a piece of information from a call response, and to use it to next call. This is what you will try in next example with a simple logon/logoff workflow.

In this sample, you will describe a first call to logon to the BI4. Then, the "X-SAP-LogonToken" will be picked. Finally, it will be reused to logoff. To be able to implement this, the Azot variable will be used.


<workflow name="Logon/Logoff Test">
    <!-- First call to login -->
    <call name="Login">
        <request url="http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/logon/long" method="POST">
            <header name="Accept" value="application/xml" />
            <header name="Content-Type" value="application/xml" />
            <content>
                <![CDATA[
                <attrs>
                  <attr name="userName" type="string">Administrator</attr>
                  <attr name="password" type="string">Password1</attr>
                  <attr name="auth" type="string">secEnterprise</attr>
                </attrs>
                ]]>
            </content>
        </request>
        <response>
            <variable id="token" value="${header:X-SAP-LogonToken}" />
        </response>
    </call>
   
    <!-- Final call to logoff -->
    <call name="Logoff">
        <request url="http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/logoff" method="POST">
            <header name="Accept" value="application/xml" />
            <header name="X-SAP-LogonToken" value="${token}" />
        </request>
    </call>
</workflow>

As you can see, the first HTTP call perform a POST request to logon to the BI4. So, thanks to the <response> tag in the Azot workflow, the "X-SAP-LogonToken" is picked from response headers and store into a Azot variable named "token". So, in the next HTTP call description, the variable "token" is reused using the notation ${token}.

Here, the result of this workflow execution:


C:\dev\tools\azot>java -jar azot.jar logon_logoff.xml
Starting workflow 'Logon/Logoff Test'
==========================================================================================
-------------------------
| Starting call 'Login' |
-------------------------
REQUEST:
[POST] http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/logon/long
Content :
<attrs>
  <attr name="userName" type="string">Administrator</attr>
  <attr name="password" type="string">*** the password ***</attr>
  <attr name="auth" type="string">secEnterprise</attr>
</attrs>
header:Accept = application/xml
header:Content-Type = application/xml
header: Content-Length = 201
------------------------------------------------------------------------------------------
RESPONSE:
header:Server = Apache-Coyote/1.1
header:Content-Length = 617
header:Date = Fri, 17 Jun 2016 07:28:25 GMT
header:Content-Type = application/xml
header:X-SAP-LogonToken = "*** the generated token ***"
meta:Status = HTTP/1.1 200 OK
meta:HttpCode = 200
meta:Content = <entry xmlns="http://www.w3.org/2005/Atom"><author><name>@dewdftv01222.dhcp.pgdev.sap.corp:6400</name></author><id>tag:sap.com,2010:bip-rs/logon/long</id><title type="text">Logon Result</title><updated>2016-06-17T07:28:25.103Z</updated><content type="application/xml"><attrs xmlns="http://www.sap.com/rws/bip"><attr name="logonToken" type="string">*** the generated token ***</attr></attrs></content></entry>
Setting variable: ${token} = "*** the generated token ***"
==========================================================================================
--------------------------
| Starting call 'Logoff' |
--------------------------
REQUEST:
[POST] http://dewdftv01222.dhcp.pgdev.sap.corp:6405/biprws/logoff
header:Accept = application/xml
header:X-SAP-LogonToken = "*** the generated token ***"
------------------------------------------------------------------------------------------
RESPONSE:
header:Server = Apache-Coyote/1.1
header:Content-Length = 0
header:Date = Fri, 17 Jun 2016 07:28:25 GMT
meta:Status = HTTP/1.1 200 OK
meta:HttpCode = 200
==========================================================================================