PART 1 PART 2 PART 3 PART 4

Here we will see how to create a destination in Gateway cockpit and map it manually to deployed OData service and then how to perform CRUD operation on service document.

Test the OData service

  1. Log on to SMP 3.0 Admin: https://smpserver:port/Admin
  2. Create a new security profile with name as ‘sap‘ (exact name as namespace) under Settings>Security profiles>New

     /wp-content/uploads/2014/07/27_491331.png

3. Log on to SMP3 gateway cockpit https://smpserver:port/gateway/cockpit

4. Go to destinations tab, Create a new destination


         

Properties Values
Destination Type DATABASE
Destination URL jdbc:mysql://MySQLSeverip/schema_name
Destination Driver com.mysql.jdbc.Driver
Authentication Type Basic Authentication
User Name DB User
Password DB password


28.PNG

5. Move to Services tab, click on deployed service employee_MYSQLDB.

    • Click on ‘Add Destination‘, select MYSQLDB from the drop-down.
    • Save and close.


     /wp-content/uploads/2014/07/1_491447.png


6. Once done, open the service document,


/wp-content/uploads/2014/07/1_491447.png


http://smpserver:8080/gateway/odata/sap/employee_MySQLDB;v=1


/wp-content/uploads/2014/07/1_491447.png

   

7. Open service metadata document

    • OData defines a metadata format based on the Entity Data Model in XML (edmx).
    • To access a service’s metadata document use the $metadata command.
    • The returned document is the service’s edmx metadata + backend metadata

http://smpserver:8080/gateway/odata/sap/employee_MySQLDB;v=1/$metadata

          /wp-content/uploads/2014/07/1_491447.png

8. To get the details for the Entity ’employee’

http://smpserver:8080/gateway/odata/sap/employee_MySQLDB;v=1/employee

     /wp-content/uploads/2014/07/1_491447.png

To fetch only first row of the table, http://smpserver:8080/gateway/odata/sap/employee_MySQLDB;v=1/employee(1001)

OData operations : RetrieveEntity (READ)

To retrieve details of a specific entity,use HTTP GET verb to execute the same.

    • Open Advanced REST client

REQUEST:


Header Values
X-CSRF-TOKEN FETCH
Content-Type application/xml


     /wp-content/uploads/2014/07/1_491447.png


RESPONSE:


    • 200 OK status message
    • X-CSRF-TOKEN value e.g. 1B4687085D8F59B1CA21382DF17D535A

          /wp-content/uploads/2014/07/1_491447.png

      

OData Operations – InsertEntity (CREATE)

    • The InsertEntity operation creates an entity.

REQUEST:

Header Values
X-CSRF-TOKEN 1B4687085D8F59B1CA21382DF17D535A
Content-Type application/xml
    • Pass this xml text into the BODY

<?xml version="1.0" encoding="UTF-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <atom:content type="application/xml">
      <m:properties>
         <d:EMPID>1006</d:EMPID>
  <d:FIRST_NAME>SACHIN</d:FIRST_NAME>
  <d:LAST_NAME>SHARMA</d:LAST_NAME>
  <d:CITY>CHANDIGARH</d:CITY>
         <d:COUNTRY>INDIA</d:COUNTRY>
      </m:properties>
   </atom:content>
</atom:entry>






/wp-content/uploads/2014/07/1_491447.png

RESPONSE:

    • This operation creates an entity.
    • Successful execution of the operation returns HTTP 201 status code along with the Location of the newly created entity will be returned.

     /wp-content/uploads/2014/07/1_491447.png

ℹ To verify, you can check with http://smpserver:8080/gateway/odata/sap/employee_MySQLDB;v=1/employee(1006) OR directly in the MySQL database.

         

          /wp-content/uploads/2014/07/1_491447.png

OData Operations – UpdatetEntity (UPDATE)

    • The UpdateEntity operation updates an entity.

REQUEST


Header Values
X-CSRF-TOKEN 1B4687085D8F59B1CA21382DF17D535A
Content-Type application/xml
    • Pass this xml text into the BODY

xml version=”1.0″ encoding=”UTF-8″?>


<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <atom:content type="application/xml">
      <m:properties>
         <d:EMPID>1003</d:EMPID>
  <d:FIRST_NAME>CHIP</d:FIRST_NAME>
  <d:LAST_NAME>ROG</d:LAST_NAME>
  <d:CITY>SAN FRANS</d:CITY>
         <d:COUNTRY>USA</d:COUNTRY>
      </m:properties>
   </atom:content>
</atom:entry>






          /wp-content/uploads/2014/07/1_491447.png

RESPONSE:

    • If the update is successful, the server responds with 204 status code.
    • As the response code text “No Content” signifies, no data is returned in the Response Body.

          /wp-content/uploads/2014/07/1_491447.png

     /wp-content/uploads/2014/07/1_491447.png

OData Operations – DeleteEntity (DELETE)

  • The DeleteEntity operation deletes an entity.


REQUEST

Header Values
X-CSRF-TOKEN 1B4687085D8F59B1CA21382DF17D535A
Content-Type application/xml

     /wp-content/uploads/2014/07/1_491447.png

RESPONSE:

    • If the delete is successful, the server responds with 204 status code.
    • As the response code text “No Content” signifies, no data is returned in the Response Body.

/wp-content/uploads/2014/07/1_491447.png

     /wp-content/uploads/2014/07/1_491447.png

Next Part 4

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply