cancel
Showing results for 
Search instead for 
Did you mean: 

How to get HTTP headers from Data Provider Class?

Former Member
0 Kudos

Hi,

I'm the beginner in SAP NetWeaver Gateway. Using Service Builder I created CRUD OData web service and implemented CRUD operations in Data Provider Class. Data Provider Class has methods like MYENTITY_GET_ENTITYSET, MYENTITY_GET_ENTITY, MYENTITY_CREATE_ENTITY, MYENTITY_UPDATE_ENTITY. How can I get HTTP headers from the methods of this Data Provider Class?

Accepted Solutions (1)

Accepted Solutions (1)

former_member184867
Active Contributor
0 Kudos

You can do so by using the following code in DPC

Data :  Lo_facade type ref to /IWBEP/IF_MGW_DP_INT_FACADE.

lo_facade     ?= /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( ).

lt_client_headers = lo_facade->get_request_header( ).



Regards,

Atanu

AshwinDutt
Active Contributor
0 Kudos

Hello Atanu,

Thanks for the info. I was also not aware of that. Thanks again.

Regards,

Ashwin

Former Member
0 Kudos

Hello Atanu,

Your answer is correct, but unfortunately this code doesn't retrieve value for Authorization header.

Best regards,

Yauhen

Former Member
0 Kudos

Till NetWeaver Gateway 2.0 SP05 it is possible to retrieve the request headers in DPC with the mentioned code in SP06 its not.

Do you know a different way?

Regards

Silvio


Answers (1)

Answers (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Yauhen,

Could you please explain your question more in detail ? Do you want information regarding what headers you need to pass for Create , Update , Delete & Get operations ? is this what you are expecting ?

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

I try to make basic authorization for my web service. I send Authorization header from client to service. And now I want to read this header value in methods of Data Provider Class.

AshwinDutt
Active Contributor
0 Kudos

Hello Yauhen,

I do not see any way you can access Header Values in your DPC methods.

I am very much doubt full if you can access Yauhen.

You can set authorizations headers with user and password while firing service for authentication purpose to check if user has access to the system which we are trying to hit.

Otherwise why would anybody need that check apart from the above i mentioned ?

Its good if you can tell what is your scenario and why you would do that check.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

I want to get access to the service for registered users and to retrieve different data from service for each registered user. So I have to check user's credentials and return information depending on username. I will send Authorization header with encoded username and password values to the service from my web app.

Maybe, this way is wrong. I'm a newbie and I would be happy to know best practices for such problem.

Best regards,

Yauhen

AshwinDutt
Active Contributor
0 Kudos

Hello Yauhen,

As far as i know you cannot read the UserName and Password that you pass in Authentication Header for a particular user inside DPC and return information based on it . Because this Authentication Header is used to check if user has access to the system from which he/she would like to get data.

But your scenario is different from the above is what i could understand.

You have few registered users and would like to return info based on User and Password.

Is it really necessary to pass Password along with User in your scenario ? only passing user will not do ? Since Users are already registered , you just have to get users and pass info for that particular user.

In my opinion Passing Password along with User in URL is not correct.

Suggestion would be pass User and retrieve info.

If at all you are sending one user at a time to validate and return single entry, then you can implement Get_Entity ( Read ) . Pass User Name as Key and get info.

If you have many users to validate at a time and return single entry for each of them, then u can operate on BATCH mode for Read Operation.

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

Probably, the description of my problem was not clear. I have a table of users and a table of products. Users have username and password. Each user has a list of his products.

A user can get the list of own products and edit it. But user cannot get and edit the list of products of another user. So I have to pass username and password with each request, otherwise user can get another's products only with foreign username.

Best regards,

Yauhen

AshwinDutt
Active Contributor
0 Kudos

Hello Yauhen,

Please follow the code to get Headers like how Atanu has suggested and

implement Get_EntitySet and get all the products for that particular User.

Now the next question is how will you send table of users and get corresponding result ?

Since your approach is to send user name and password in the headers and use it to get list of products for that particular user,

even if you operate on BATCH for Query operation how will you send credentials of all those table of users in a single header ? You cannot set headers for all those users with their respective User Name and password correct ? Because Gateway does not support that.

Now its up to you how you would like to model your service and fire it

Regards,

Ashwin

Former Member
0 Kudos

Hi Yauhen,

do you have your users stored in SAP, or in some external system?

If they are in SAP, after login to netweaver gateway, you can access sy-uname in the backend and make your filter logic of products there.

Regards,

Peter