cancel
Showing results for 
Search instead for 
Did you mean: 

Creating and adding an entity to an OData collection using SUP 2.1

Former Member
0 Kudos

Greetings

I am in the process of writing an iOS native application that accesses the FlightData OData service running on NW Gateway through SUP 2.1 (ESD #1)

I am able to enumerate the top level collections and display them on the device. I am able to run queries (like GetAvailableFlights).

But I am unable to create a new booking object and add it to BookingCollection.  I have tried using various client scenarios.

- SUP client from IOS.

- Direct HTTP Post to the service URL (from command line using curl. From a .dot client).

I am always getting errors.

Do I have to enable something on the gateway to accept updates? (I get 401 permissions error from my .net client. Though it doesn't appear so in the $metadata, can this collection be read only?)

Any help with how to proceed?  Any sample code will be much appreciated.

thanks

pj

Accepted Solutions (1)

Accepted Solutions (1)

kenichi_unnai
Advisor
Advisor
0 Kudos

Hi there,

Some checklists 🙂

  • Does your NW GW oData service contain /sdata/ or /odata/ in the URL?

/sdata/ indicates the service is made with old Generic Channel API. /odata/ indicates a new & recommended OData Channel API based.

/sdata/ requires http header "X-Requested-With=XMLHttpRequest" for both HTTP POST(Create) and PUT(Update).

/odata/ requires http header "Content-Type=application/atom+xml;type=entry" AND "X-CSRF-Token=<token value>" for both HTTP POST and PUT. The X-CSRF-Token value needs to be fetched by "X-CSRF-Token=Fetch" in the previous http call. The value will not change in the same app session. It is a new security enhancement on NW GW SP3 for a well known Cross-site request forgery.

Hope this helps to move forward...

Former Member
0 Kudos

Hi Kenichi

Thanks for your reply.

This is the URL of the service I am connecting to.

http://nplhost:8042/sap/opu/sdata/IWFND/RMTSAMPLEFLIGHT/

It does say 'sdata'. Here is what I see in the 'show version info' in SAP Management console.

/usr/sap/NPL/DVEBMGS42/exe/sapstartsrv    720, patch 80, changelist 1226580, optu (Feb 13 2011, 20:06:57), linuxx86_64    2011 02 13 12:59:41

I take it I am using older version of NW Gateway demo server?

I will try the http headers you suggested and update.

thanks

pj

Answers (1)

Answers (1)

rohith_deraje
Advisor
Advisor
0 Kudos

Hi PJ,

As far as I remember there is single collection which supports all operations (GET/PUT/POST/DELETE) in RMTSAMPLEFLIGHT for "sdata"  URL.

GET--> All collections

PUT-->TravelAgencyCollection

POST--> BookingCollection and SubscriptionCollection

DELETE--> BookingCollection and SubscriptionCollection

When you do PUT/POST/DELETE operations you need to send the below headers

X-Requested-With = XMLHttpRequest

Content-Type = Application/atom+xml

Regards

Rohith

Former Member
0 Kudos

Thanks Guys for all your help.

I am able to Add to BookingCollection from my iOS application now.

cheers

pj

Former Member
0 Kudos

Hi

I am also trying to update the entity but I am facing problem while trying to fetch CSRF token can you provide your help, I am able to get the response , but I am not able to get the CSRF token.

Thanks

Santosh Varada

kenichi_unnai
Advisor
Advisor
0 Kudos

First off you should make sure if your service is /sdata/ or /odata/. if you're using /odata/ then you should be able to fetch the X-CSRF-Token=Fetch HTTP header.

You can try it via Firefox's RESTClient plugin to see how it works.

Former Member
0 Kudos

Hi

  The above two things I have confirmed  my URL contains oData and I tried to it from Chrome Rest client , I am getting CSRF token and with that token I was able to update the entity but I am not able to update fetch it via SUP oData .Actually there was recent upgrade in our landscape  where in our Unwired Server has been upgraded to 2.2 version but our sybase SDk is  of version 2.1.2, please share your views.I have opened a new  thread in , can you have a look at it and provide your views.

Thanks

Santosh Varada

kenichi_unnai
Advisor
Advisor
0 Kudos

Yes, the version of SUP runtime and your oData SDK really matters. As you referred the version 2.2, I assume you have some contact to the SAP development team? You need to use corresponding version of SDK.

Former Member
0 Kudos

Hi

     Thanks for sharing your views once again,will that be sufficient if I just get the oData - Android jar files of 2.1.3 version or the whole SDK should be upgraded to 2.1.3

Thanks

Santosh Varada

kenichi_unnai
Advisor
Advisor
0 Kudos

If you're working on eclipse plugin kit provided by the sybase unwired workspace, you would need to update a whole sdk set but if you're working with other 3rd party libs (such as the ones available at www.odata.org), you could replace a portion of libs.

rohith_deraje
Advisor
Advisor
0 Kudos

Hi Varada,

You can use android plugin with latest eclipse(details available at developper.android.com).  You can pick the ODP libs which comes as part of SDK installer and use them in the android workbench directly. No need to use workspace.

I belive, you are new to android-SUP. You can refer to the guide http://scn.sap.com/docs/DOC-23532

Regards

Rohith

Former Member
0 Kudos

Hi Rohit

Yes,it is a nice document very much helpful , I have referred the document initially to configure the applications in SCC.I was able to work before the up gradation, but all of a sudden my code stopped working , then I realized that upgrade could be issue.Still yet to confirm ,now I am trying to get the 2.1.3 oData- Android jar files ,I will replace them and test my application once I upgrade the SDk.I will keep you posted and will come back if any help needed.I hope  I will come with positive note here.

Thanks

Santosh varada

Former Member
0 Kudos

Hi Kenichi

   Thanks for that , I will replace my old lib files and try first ,will update you further.

Thanks

Santosh Varada