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: 
CarlosRoggan
Product and Topic Expert
Product and Topic Expert

This blog is about Integration Gateway in SAP Mobile Platform 3.0 (SMP)

In this blog, we’ll have a closer look at 2 new capabilities that have been introduced in SP10

Please note that we’re talking about JDBC data source only.

Up to now, it was possible to use $batch for read operations. Write operations were supported as well, but only one operation per change set.

Now, since SP10,  it is possible to have multiple operations within one change set.

This leads to 2 interesting capabilities:

1. Rollback

2. Content ID referencing

Let’s have a closer look.

I’ll be showing a sample $batch request body for each feature.

Note:

While trying the same, please make sure to use the REST client tool “Postman” for the $batch requests.

Attached you can find a Postman-collection file, which you can download, remove the zip fileextension and import in Postman.

It will help to construct the $batch requests, however, to run the requests, you need a corresponding service and database

1. Rollback

In the following sample request body, I’m showing that an erroneous (inner) request in the $batch leads to a rollback.

The below $batch request contains the following inner requests:

POST

---

DELETE

PUT

---

PUT

PUT

---

GET

The first POST request is contained in one change set and creates a product

Then, in a second change set the new product is deleted and in the same change set the product is modified with a PUT.

This PUT request will fail, because the product has been deleted in the SAME change set.

As such, THIS change set will be rolled back and as such, the deletion is reverted.

Afterwards, since the product is not deleted, we can go ahead and in a third change set, we fire two PUT requests, both will succeed.

Finally, the last thing is to perform a READ operation.

The GET request is not contained in any change set, because change sets are used for modifying operations only.

The GET request calls the product and shows that the 2 last PUT requests were executed successfully.

This is my sample request body:


--batch_mybatch
Content-Type: multipart/mixed; boundary=changeset_mychangeset1
--changeset_mychangeset1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST PRODUCTS HTTP/1.1
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:PRODUCTID>108</d:PRODUCTID>
            <d:NAME>Product108</d:NAME>
            <d:DESCRIPTION>Product108 description</d:DESCRIPTION>
            <d:RATING>108</d:RATING>
            <d:PRICE>108</d:PRICE>
            <d:CATEGORYID>555</d:CATEGORYID>
            <d:SUPPLIERID>20</d:SUPPLIERID>
            <d:ISDELETED>0</d:ISDELETED>
        </m:properties>
</content>
</entry>
--changeset_mychangeset1--
--batch_mybatch
Content-Type: multipart/mixed; boundary=changeset_mychangeset2
--changeset_mychangeset2
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE PRODUCTS(108M) HTTP/1.1
Content-Type: application/atom+xml
--changeset_mychangeset2
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT PRODUCTS(108M) HTTP/1.1
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:NAME>Product108BetterName</d:NAME>
        </m:properties>
    </content>
</entry>
--changeset_mychangeset2--
--batch_mybatch
Content-Type: multipart/mixed; boundary=changeset_mychangeset3
--changeset_mychangeset3
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT PRODUCTS(108M) HTTP/1.1
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:NAME>Praline</d:NAME>
        </m:properties>
    </content>
</entry>
--changeset_mychangeset3
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT PRODUCTS(108M) HTTP/1.1
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:DESCRIPTION>Really tasty</d:DESCRIPTION>
        </m:properties>
    </content>
</entry>
--changeset_mychangeset3--
--batch_mybatch
Content-Type: application/http
Content-Transfer-Encoding: binary
GET PRODUCTS(108M) HTTP/1.1
Accept-Language: en-US
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_mybatch--








The above request is fired against an OData service, running on SMP 3.0 SP10

https://localhost:8083/gateway/odata/SAP/<MYSERVICE>/$batch

The Product entity is bound against a JDBC data source, which connects against a corresponding database.

2. Content ID referencing

A typical use case that is supported with this feature is the following:

Create an entry

Take this newly created entry, follow a navigation link and create an entry for that resource as well

Example:

A typical use case is that a user of a webshop chooses an article and puts it into a cart.

Behind the scene, a SalesOrder is created and for this newly created SalesOrder a LineItem is created

These 2 steps are normally performed by 2 HTTP POST requests:

One POST request for the first entry, then read the response and construct the URL to fire the second POST, based on that URL.

However, it is better to  perform both requests in one single $batch request.

But the problem is that the second POST request depends on the result of the first, because usually the ID of a SalesOrder is generated by the backend system and cannot be hardcoded in the $batch body.

Now there’s a solution available for this problem: the Content-ID

The handling is the following:

Inside the $batch request body, the first POST operation is tagged with a Content-ID header and a value that serves as ID

The second POST  request can use this ID as a variable that represents a resource segment in the URI

Such that, following the above example, the URI for the second request, the creation of a LineItem would be constructed as follows


POST $1/LineItems









where the $1 represents the SalesOrder that has been created before.


Please note that both requests, the one that defines a Content-ID and the one that uses it, have to be part of the same Changeset









Please find below a full sample request body for a $batch request.

The request body contains

- one changeset with 2 operations, where the first POST creates a Product and the second POST creates the customer belonging to this product.
   The header section of the first operation defines the Content-ID

   The URI of the second POST is constructed using the Content-ID reference, followed by the navigation property name.

- afterwards we perform a GET request to the newly created product. Here a Content-ID cannot be referenced, so we use the hardcoded productID

Please note that other kind of usage of the Content-ID reference is not supported in SP10


--batch_mybatch
Content-Type: multipart/mixed; boundary=changeset_mychangeset1
--changeset_mychangeset1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST Products HTTP/1.1
Content-Type: application/atom+xml
Content-ID: 1
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC_SP10;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:PRODUCTID>111</d:PRODUCTID>
            <d:NAME>Product111</d:NAME>
            <d:DESCRIPTION>ProductDesc111</d:DESCRIPTION>
            <d:RATING>111</d:RATING>
            <d:PRICE>111.11</d:PRICE>
            <d:CATEGORYID>1</d:CATEGORYID>
            <d:SUPPLIERID>20</d:SUPPLIERID>
            <d:ISDELETED>0</d:ISDELETED>
        </m:properties>
    </content>
</entry>
--changeset_mychangeset1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST $1/Customers HTTP/1.1
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://localhost:8083/gateway/odata/SAP/JDBC_SP10;v=1/">
    <content type="application/xml">
        <m:properties>
            <d:CUSTOMERID>111</d:CUSTOMERID>
            <d:PRODUCTID>111</d:PRODUCTID>
            <d:NAME>Customer111</d:NAME>
            <d:AGE>111</d:AGE>
        </m:properties>
    </content>
</entry>
--changeset_mychangeset1--
--batch_mybatch
Content-Type: application/http
Content-Transfer-Encoding: binary
GET Products(111M) HTTP/1.1
Accept-Language: en-US
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
--batch_mybatch--






The above request body is fired against an OData service, running on SMP 3.0 SP10 :

https://localhost:8083/gateway/odata/SAP/<MYSERVICE>/$batch

As a result, we can see the newly created Product and the newly created Customer entry

The Product entity is bound against a JDBC data source, which connects against a corresponding database.

The model looks as follows:

Please note that a referential constraint is necessary, where the PRODUCTID key property of the Product is mapped against the PRODUCTID property of the Customer:

By the way, please note that a POST request on a navigation property is not supported outside of a $batch request (in SP10).

I mean, it is not supported in SP 10 to fire a POST request to a URL like:

https://localhost:8083/gateway/odata/SAP/<MYSERVICE>/Products('11')/Customers

It is only possible as an inner request of a $batch request, as shown above

Summary

Since SMP 3.0 SP10, the Integration Gateway component supports multiple operations in one change set of a $batch request for the JDBC data source.

This feature includes the 2 following capabilities:

- if an operation in one change set fails, the complete change set is rolled back

- the result of a POST can be referenced via a Content-ID by a subsequent request in the same change set

2 Comments