cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Set header info(TenantId) in Request Context from Header in a REST Controller

aniket09
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,149

Hello Colleagues,

We have a SAP Cap Java application in DwC. We have defined a REST Controller and contact a POST Endpoint. The endpoint will be called by another service in DwC with the tenant information in header. In order to correctly process the payload, we would need to set the tenant id in the request context so that the persistence service can be called in the right context. Could you please give some guidance as to how the headers can be mapped to the request context.

Regards,

Aniket

View Entire Topic
0 Kudos

You can define the tenant when opening the RequestContext in your RestController.

context.getCdsRuntime().requestContext() .modifyUser(u -> u.setTenant(<tenant>)) .run(requestContext -> { // queries will be executed in context of <tenant> persistenceService.run(...); });

See an example here.

aniket09
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thanks I will try this now. So setting only the tenant should be enough to set the context.