Skip to Content

Prerequisites

 

This page tries to collect information required for following the series of blogs about creating OData services with SAP Cloud Platform SDK for service development

 

Java

The SAP Cloud SDK for service development is a framework for Java development, so obviously you need Java on your computer
At this point in time, it is JDK 8

 

Maven

The result of all our endeavor is a web application, to be deployed to a server. Actually, it doesn’t matter how you build it, but there’s some specific support for maven, as it makes our life easier – if we’re lucky and everything goes fine 😉

So it makes sense to install maven, if you don’t have it, to easily follow the tutorials

 

https://maven.apache.org/ The maven home page
https://maven.apache.org/download.cgi Download current maven,e.g. as simple (small) zip
https://maven.apache.org/install.html Installing means unpacking the zip
and  adapting the env variable to point to the mvn.cmd
https://maven.apache.org/run.html Shows some maven commands

 

Eclipse

All tutorials are based on eclipse, but of course any other IDE can be used as well

http://www.eclipse.org Homepage
https://www.eclipse.org/downloads make sure to navigate to “Packages”
https://www.eclipse.org/downloads/eclipse-packages choose e.g. “Eclipse IDE for Java EE Developers”

After download, just unpack the archive and execute the exe file to start up eclipse.
Start eclipse with double-click on the eclipse.exe file
When starting eclipse, you have to specify a directory for your workspace. This can be any folder.
Eclipse will store all your projects and the eclipse-internal metadata there
After startup, you can close the Welcome screen

 

Cloud

See here

 

 

OData V2 service

In some of the tutorials, we connect to an existing OData V2 service in order to fetch data.
For that purpose we can make use of the well-known OData V2 sample service
In order to access it, you need to quickly sign up to the SAP Gateway Demo System

Demo System
Announcement blog: Demo System Available
How to get an account in the demo system: Sign up to Demo System

Sample OData V2 service URL: https://sapes5.sapdevcenter.com/sap/opu/odata/iwbep/GWSAMPLE_BASIC

SAP documentation about the Sample Service

 

CSRF

The Gateway services (e.g. on Demo System) are protected against Cross Site Request Forgery attacks via csrf-token.
This means, the service doesn’t accept a modifying request without valid csrf-token.
Otherwise it responds with an error “csrf-token validation failed”
This affects the requests for CREATE, UPDATE (PUT and PATCH) and DELETE
As such, when executing manual tests against a service which is CSRF protected, we have to proceed as follows:

Execute a GET request to the service.
Any resource of the service should be usable, we tend to use a URL with fast response time, e.g. metadata or service document.
Also, the GET request can be a HEAD request, which is even faster

Along with the request, send the following header:

header name header value
x-csrf-token fetch

In the response, the server sends a newly issued valid csrf-token, which can be found in the response headers area.
We copy it to our clipboard
Afterwards, we can send the desired modifying operation, e.g. CREATE
In the request we can now specify the copied token:

header name header value
x-csrf-token <the csrf-token value copied from the previous response>

 

Reset data

The service GWSAMPLE_BASIC, which we’re using as backend v2 service, allows to do a reset of the sample data.
This is done via the function import called “RegenerateAllData”

Information about how to invoke it can be found in the metadata here

https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/$metadata

The relevant snippet:

<FunctionImport Name="RegenerateAllData" ReturnType="GWSAMPLE_BASIC.CT_String" m:HttpMethod="POST">
   <Parameter Name="NoOfSalesOrders" Type="Edm.Int32" Mode="In"/>
</FunctionImport>

Following this instruction, we need to use a REST client to send the POST request, empty request body, with csrf-token (see above), and we need to send it to the following URL:

https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/RegenerateAllData?&NoOfSalesOrders=20

 

REST client

Yes, in my blog posts I’m mentioning that you need a REST client for executing the HTTP requests like POST etc
And I’m linking to this Prerequisites page.
But come on … you can google yourself how to get a REST client…;-)

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