cancel
Showing results for 
Search instead for 
Did you mean: 

Consume SAP Odata feed in SENCHA

Former Member
0 Kudos

Hello folks,

                I was trying to create an ODATA feed from sap netweaver gateway and consume that data from my SENCHA application.....

So at first i created the entity set from Netweaver Gateway Service Builder and started that from (/iwfnd/maint_service)....then i was able to read entity sets and entity using sencha odata proxy...but the problem came at the time of posting data(Create,Update).....Chrome is saying "Failed to load resource: the server responded with a status of 403(Forbidden)"....but when i tried to create and update from Firefox Rest Extention,it's working fine....

so this is my code


Ext.define('App.model.TravelAgency', { 
    extend: 'Ext.data.Model', 
    config: { 
        fields: [ 
          { name: "ID" }, 
          { name: "Name" }, 
        ], 
        proxy: { 
            type: 'odata', 
  
url: 'http://192.168.253.114:8000/sap/opu/odata/sap/Z_DEB_TEST_SRV/Tests', 
            withCredentials: true,
       
   

}); 

Ext.application({ 
    launch: function () { 
  
var model = Ext.create('App.model.TravelAgency', {
                ID:   'ABC',
                Name: 'ABCDEFGH'
            });
  
model.save();
   

}); 

any plz help me guys

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Debarshi,

It could be an issue with XCSRF Token validation. For any modify request(Put/Post/Delete) we need to pass xcsrf token in the header along with the authorization headers.

So what you need to do is, before the actual modify request, make a GET request with

"X-CSRF-TOKEN: Fetch" as one of the header. In the response you will get the X-CSRF-TOKEN.

Pass this "X-CSRF-TOKEN: <value>" in the header for the subsequent modify requests to the gateway.

I'm not sure how you do it in Sencha, but you need to pass the token for successful create operation.

Hope this helps.

Regards,

Suhas

Former Member
0 Kudos

Hi suhas,

              Actually when i tried to update my sap db using firefox rest client,it worked perfectly,there i provided the x-csrf token value....but in sencha the odata proxy itself manages all the tokens(i have seen the code in odata.js proxy file)......so i need the solution for sencha

...thanks anyway

Former Member
0 Kudos

Hi,

In the Sencha OData connector, the XCSRF token is fetched on the first GET request. This means you should at least do one GET (read) before you can do any of the create/update/delete actions.

So you can try to do a read collection first, wait for the results and then do a create.

In any case, check the request/response headers with e.g. Developer Tools in Chrome.

I hope this works.

Former Member
0 Kudos

Hi Luc,

           Thanks a lot......reading the store before trying to save did the trick.....

Former Member
0 Kudos

HI Luc,

           I have another query, i am trying to create a login screen in sencha from where users can login into their SAP account and explore the app. So i created two global variables in app.js then i applied those two variables in models for username/password. But the problem is that i am calling the loginView from launch function of app.js but before that only as i have specified all the Models,Stores, so before calling the loginview the models are searching for username/password and as at that time the variables are empty the browsers popup is opening...But i dont want to use the browsers popup...

var username="";

var password="";

Ext.application({

    name: 'V4Retail',

    views: ["LoginView","MainView""],

    models: ["AgreementsModel"],

    stores: ["AgreementsStore"],

    controllers: ["MainController"],

    launch: function() {

        Ext.Viewport.add(Ext.create('V4Retail.view.LoginView'));

    }

});

Former Member
0 Kudos

Hi,

In Sencha you get/set config properties after the class definition using accessor methods. After the user has filled in the username and password, use something along the lines of

YourModel.getProxy().setUsername(...)

YourModel.getProxy().setPassword(...)

Former Member
0 Kudos

Thanks!! That was spot on...its working now....i have another question ....how to understand using code that whether user has entered wrong authentication details...in my case if the authentication is wrong browser's default popup is opening....

Former Member
0 Kudos

I understand. Annoying, yet correct behaviour for Basic Authentication.

See this article for a suggestion: http://loudvchar.blogspot.ca/2010/11/avoiding-browser-popup-for-401.html

Perhaps you can tweak Gateway server settings to either change the 401 error code or Basic authentication header.

Former Member
0 Kudos

Hi Debarshi,

I'm going through the same problem as of yours...

As suggested by Luc and Suhas, I did a GET request and got a x-csrf-token along with the response. I used this x-csrf-token with the PUT request... But to no success.

I'm getting the same error - "CSRF token validation failed".

What did you actually mean when you said... "reading the store before trying to save did the trick" ??

Did you mean reading the full collection using the service url... OR.... reading the Store(Ext.data.Store)?

We are working with the model here, reading the Store(Ext.data.Store) doesn't make much sense I suppose. Please correct me if I'm wrong.

It would very helpful if you could provide me with some sample code as of what you've done.

Thanks In Advance.

Former Member
0 Kudos

@Luc Stakenborg: Your answer helped me a lot. thanks!

Answers (4)

Answers (4)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Did you actually include username/password details in the proxy config in the Sencha code?

Former Member
0 Kudos

Hi Luc,

          No i did not...i was specifying the username/password from the browsers popup. Is that the reason? let me try with hardcoded username/password.

midhun_vp
Active Contributor
0 Kudos

Since you are able to perform the operation using Firefox Restclient means there is no problem in the odata services.

What is the issue you are getting when you are trying ti execute it from the app?

Are you passing token and cookie when you are performing the operation.

-Midhun VP

Former Member
0 Kudos

Hi midhun.....i am trying to post the using sencha odata proxy...u can see my code in the above post....i am getting the 403 forbidden error and i kept a external breakpoint in my sap create code,so that breakpoint is not being called...

Former Member
0 Kudos

Hi,

To me it looks like an authorization issue, do one thing, go to netweaver gateway and run the t-code /iwfnd/gw_client and try to post the data.

Regadrs,

Srinivas Divakarla