cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Gateway AJAX call - Handle HTTP Options Request

Former Member
0 Kudos

Hello All,

I am needing some assistance in knowing how to handle an HTTP OPTIONS request. I have a front end JavaScript developer that is performing an AJAX request to my gateway URL expecting JSON in return. I can execute my gateway URL with the ?format=json parameter, and it renders correctly in the browser. In speaking with my JS developer, his call to my URL is failing because SAP is not handling the OPTIONS request. Specifically, I need set the header information on the OPTIONS request to allow for CORS processing.

Evidently, an AJAX request makes an OPTIONS request before the specified request (GET, POST, etc…). Therefore, I need to set the header data on the Options request. Any help would be appreciated.

I have created a service in SEGW and have added the following code to the method USR01SET_GET_ENTITYSET. I need to find the method that handles the OPTIONS request.

data: ls_header type ihttpnvp.

   ls_header-name = 'Access-Control-Allow-Origin'.

   ls_header-value = '*'.

   /iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

   ls_header-name = 'Access-Control-Allow-Credentials' .

   ls_header-value = 'true' .

   /iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

   ls_header-name = 'Access-Control-Allow-Headers' .

   ls_header-value = 'Content-Type, Authorization' .

   /iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

   ls_header-name = 'Access-Control-Allow-Methods' .

   ls_header-value = 'POST, GET, OPTIONS, PUT, DELETE, HEAD' .

   /iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

Thanks in advance!

Allen

Accepted Solutions (0)

Answers (1)

Answers (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Allen,

Are you talking about HTTP Method OPTIONS correct ?

If yes,

We have GW running SAP_GWFND 7.40 SP 05 where we are unable to see HTTP Method OPTIONS which you are looking for it.

In the old release i too have seen HTTP Method OPTIONS as part of HTTP Method. But in the latest releases it has disappeared.

I don not know if the latest SP 09 have got HTTP Method OPTIONS or not.

I really doubt if this is supported or not.

May be someone running on SP 09 can confirm if OPTIONS is supported in GW in the latest release

Regards,

Ashwin

Former Member
0 Kudos

Hello Ashwin,

I am not sure about a HTTP method, but what we are needing is a way to supply HTTP Header authentication in order for the originating domain to "Trust" an outside domain. This is a cross-origin request or CORS. A standard browser call wouldn't need this, as this is a same-origin request. On the other hand, when you create an app outside your originating domain or try to consume your OData service in Excel, there needs to be a negotiation to allow this permission. Eventually, I would like to use this HTTP header to supply private and public tokens for added security.

Hopefully this helps in the understanding. I do appreciate your response and I will have to look into SP09.

I may have figured out a way to do this, and will be looking at it more today.

Thank you,

Allen

AshwinDutt
Active Contributor
0 Kudos

Hello Allen,

May be you can just have a look here and see something can help you :

Regards,

Ashwin

kammaje_cis
Active Contributor
0 Kudos

Allen,

As per my knowledge OPTIONS cannot be handled/responded in SAP Gateway currently. Also I have seen many widely available APIs over net, which do not have OPTIONS implemented.

So the frontend code should not depend on implementation of OPTIONS. If the problem is with CORS, then Ashwin has pointed you to the right way.

thanks

Krishna

Former Member
0 Kudos

Ashwin/Krishna,

Unfortunately, attempting to set the HTTP header in the BEP/ERP system is too late in the process. We needed to handle this in the Gateway and with what we have found, it is not currently possible. We found an alternative way of handling this through a reverse proxy in both Apache and Node.JS.

Thank you both for your input.

Allen