Introduction
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:
1. preliminary work
2. implementation of a model provider
3. implementation of a data provider
4. register and publish OData Service
5. test
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
Preliminary work
Before we start with the OData Implementation, we will create a data base table.
Data Base Table – ZDEMO
◉ 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
Structure – ZSDEMO_ODATAV4
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.
PDF File in ZDEMO
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.
Model Provider Class
The Method /IWBEP/IF_V4_MP_BASIC~DEFINE will be redefined.
Model Provider Class – Define Method
I recommend calling for each entity an own private method.
Model Provider Class – Define File Download 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.
Data Provider Class
In this class we redefine the method /IWBEP/IF_V4_DP_BASIC~READ_ENTITY
Data Provider Class – Read Entity Method
Delegate to a private Method
Data Provider Class – File Download 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.
Register Service Group
And register the service
Register Service – Part I
Register Service – Part II
Here we enter our created classes. Finally, we assigned it to our Service Group
Register Service – Part III
Here the result:
Register Service
Call Transaction Code /IWFND/V4_ADMIN to publish the Service Group that we created in Step 4
Publish Service
Mark the entry and publish it. Result:
Published Service
Test
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
SAP Gateway Client – Test
PDF File opened
No comments:
Post a Comment