In this blog post I would like to show you how you can download a file through NetWeaver Gateway with OData Version 4. The next sections contain following topics:
- preliminary work
- implementation of a model provider
- implementation of a data provider
- register and publish OData Service
In my case the system conditions were during the implementations as follows:
|Component||Release||SP-Level||Support Package||Short Description|
|SAP_GWFND||754||0000||–||SAP Gateway Foundation|
|SAP_UI||754||0002||SAPK-75402INSAPUI||User Interface Technology|
Embedded Gateway Scenario
Before we start with the OData Implementation, we will create a data base table.
- NAME is the name of the file
- CONTENT is from type RAWSTRING and contains the content of the file
- CONTENT_TYPE is our MIME_Type
Afterwards I created a structure
In a separate blog post I will explain you how you can fill this table via POST URL Request which generates an Adobe Form. We assume that we have already an entry. In our example it is a PDF File.
OData V4 Model Provider Class
OData Version 4 Model will be implemented by creating a class that inherits from /IWBEP/CL_V4_ABS_MODEL_PROV.
The Method /IWBEP/IF_V4_MP_BASIC~DEFINE will be redefined.
I recommend calling for each entity an own private method.
We use here the type Stream for property CONTENT.
That’s all. The Model for File Download is finished.
OData V4 Data Provider Class
OData Version 4 Data Provider will be implemented by creating a class that inherits from /IWBEP/CL_V4_ABS_DATA_PROVIDER.
In this class we redefine the method /IWBEP/IF_V4_DP_BASIC~READ_ENTITY
Delegate to a private Method
This method reads the entry of our data base table ZDEMO according to key which comes from the URL Request.
The OData Version 4 Implementation for File Download is finished. Now we have to register the Service and publish it.
Register and Publish OData Service
Two activities are needed before you can call the URL and test the request. Register the service and publish it.
Register Service Group and assign service
Call Transaction Code /IWBEP/V4_ADMIN for creating a Service Group. First Add a Register Group.
And register the service
Here we enter our created classes. Finally, we assigned it to our Service Group
Here the result:
Call Transaction Code /IWFND/V4_ADMIN to publish the Service Group that we created in Step 4
Mark the entry and publish it. Result:
Now let test our File Download Demo. For that Mark Line 2 and execute “Service Test”. SAP Gateway Client will be opened. Type request FileDownloadSet(0050560C-0A03-1EEB-98CC-EA223BCD9E8D)/Content
PDF File opened
This example shows you how you can implememt a file download through SAP Gateway with OData Service 4.0. The crunching point is the use of EDM Data Type stream in the model provider class.
I hope you liked it.
Please, let me know what you are thinking about it.