Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

POST Operation is not working in UI5 Application Developed using SMP Gateway Service

$
0
0

Hello Experts,

 

 

We are using SAP mobile platform as a middle-ware and SAPUI5 as a development tool. I am able to POST in Firefox browser but not able to POST in Chrome as well as published application on Apache Tomcat.

 

First, I have created OData service using SMP OData plugin in eclipse which is publish on SMP Integration Gateway. This service has SQL database as backend.

SMP admin cockpit url : https://SMPSERVER/Admin/

My application URL in SMP is :  http://SMPSERVER /com.sap.elogbook/

Here com.sap.elogbook is application name.

I configured back-end URL http://SMPSERVER /gateway/odata/SAP/TEST;v=1

In SMP admin cockpit.

1.png

 

SAPUI5 development :

In development I used this URL :  http:// SMPSERVER:8081/com.sap.elogbook/ for consuming odata.

For consume web service I used below code:

var serviceurl = "https://cors-anywhere.herokuapp.com/SMPSERVER:8081/com.sap.elogbook/";

                                                                var odatamodel = new sap.ui.model.odata.ODataModel(serviceurl, {

                                                                                headers: {

"X-SMP-APPCID": " b5c4d3c6-1745-4d53-9465-91a8fc2c53f9",

                                                                                                "Content-Type": "application/xml"

                                                                                }

                                                                });

                                                                sap.ui.getCore().setModel(odatamodel);

                                                                odatamodel.read("/BYPASS", null, null, false,

                                                                                function fnSuccess(oData) {

                                                                                                sap.ui.getCore().APPROVESet = oData.results;

                                                                                },

                                                                                function fnError(response) {

                                                                                });

 

Using this code I can get data .

Now, I have to POST data on web-service particular entity.

For this I used below code

 

  1. OData.request 

                                        ({

                                             requestUri: 

                                 "https://cors-anywhere.herokuapp.com/SMPSERVER:8081/com.sap.elogbook/BYPASS",  

                                                   method: "GET",  

                                                   headers:  

                                                       {       

                                                           "X-SMP-APPCID": "b5c4d3c6-1745-4d53-9465-91a8fc2c53f9",

                                                            "X-Requested-With": "XMLHttpRequest", 

                                                             "Content-Type": "application/atom+xml", 

                                                            "DataServiceVersion": "2.0",          

                                                            "X-CSRF-Token":"Fetch"      

                                                         }                    

                                                },  

                                                 function (data, response) 

                                                 { 

                                                             var header_xcsrf_token = response.headers['X-CSRF-TOKEN'];

                                                             //var cookie = response.headers['Set-Cookie'];

                                                  OData.request 

                                                  ({  

                                                       requestUri: 

                                 "https://cors-anywhere.herokuapp.com/SMPSERVER:8081/com.sap.elogbook/BYPASS",  

                                                             method: "POST",  

                                                             headers: {  

                                                                 "X-SMP-APPCID": " b5c4d3c6-1745-4d53-9465-91a8fc2c53f9",

                                                                 "X-Requested-With": "XMLHttpRequest",                        

                                                                  "Content-Type": "application/atom+xml", 

                                                                  "DataServiceVersion": "2.0",  

                                                                   "Accept": "application/atom+xml,application/atomsvc+xml,application/xml", 

                                                                  "X-CSRF-Token": header_xcsrf_token  

},  

                                                             data:  

                                                                 {  

                                                                 LOGNO: "66",

                                                                 BYPASSNAME: "PANARA",

                                                                 DATE: "2016-02-02",

                                                                 UNIT: "3",

                                                                 STATUS: "inservice",

                                                                 TIME: "02:02:00",

                                                                 LOCATIONID: "1",

                                                                 CREATED_DATE: "3016-02-02 00:00:00.0",

                                                                 UPDATED_DATE: "2016-03-03 00:00:00.0",

                                                                 CREATED_BY: "AAA",

                                                                 UPDATED_BY: "BBB"

 

                                                                  }  

                                                          },  

                                                            function (data, response) 

                                                            {

$("<div>Returned data " + window.JSON.stringify(data) + "</div>").appendTo($("#MessageDiv")); 

                                                            },  

                                                                   function (err)  

                                                                   { 

$("<div>Returned error " + window.JSON.stringify(err.response) + "</div>").appendTo($("#MessageDiv")); 

                                                                   } 

                                                  ); 

                                        },

                                                       function (err)  

                                                       { 

                                                            var request = err.request; // the request that was sent.

                                                            var response = err.response; // the response that was received. 

                                                            alert("Error in Get -- Request "+request+" Response "+response); 

                                                       } 

                                        );

                                                

                                               

                                }

 

When execute this code , GET operation done successfully but on POST operation request gives error :

“POST https://cors-anywhere.herokuapp.com/SMPSERVER:8081/com.sap.elogbook/BYPASS 403 (Forbidden) “.

 

 

2.png

Below are snap shot of google Chrome console window.

 

For GET operation on odata:

                Working fine.

 

2.png

 

POST operation on ODATA :

                Not working

 

2.png


Viewing all articles
Browse latest Browse all 3316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>