We talked a lot about OData, but how did the Fiori app invoke the OData service via SAP Gateway?
Today we analyze it through an example of a Fiori app.
First we launch the Fiori app "Manage Journal Entries", this app I have quoted several times, and no longer introduced.
Enter simple filter parameters, company code, and fiscal year information.
Click Execute, and the app returns a list of header information for the corresponding financial voucher.
How does the SAP Fiori application use the front-end SAP UI5 to invoke the backend system to get the header information of the credential? We use Chrome's own tools: Developer tools, (similar to IE's F12) to view network transmission information, the main concern: XHR data transmission, about XHR (XML HTTP Request) you can Baidu.
Information such as:
We can get HTTP information for the OData call:
https://host:port/sap/opu/odata/sap/FAC_FINANCIAL_DOCUMENT_SRV_01/$batch? sap-client=210
Protocol: HTTPS
Hostname, port number,
Path of ICM Node:/sap/opu/odata/sap
OData Service Name:
Payload:fac_financial_document_srv_01
Parameters: $batch? sap-client=210, where $batch represents a batch with multiple OData service calls.
Then in the payload message, you can see that there are two OData service calls:
GET headers/$count?sap-client=210& $filter = ((companycode%20eq%20%270001%27)%20and%20 (fiscalyear%20eq%20% 272017%27))
GET headers?sap-client=210& $skip =0& $top =116& $orderby =postingdate%20desc& $filter = ((companycode% 20eq%20%270001%27)%20and%20 (fiscalyear%20eq%20%272017%27)) & $select =accountingdocument% 2caccountingdocumentheadertext%2ccompanycodename%2caccountingdocumenttype%2ccreatedbyuser%2cpostingdate% 2camountincocodecrcy%2ccompanycode%2caccountingdocumenttypename%2ccreatedbyusername% 2caccountingdocumentcategoryname%2cledgergroupname%2cparkedbyusername%2creversalreasonname% 2ctransactioncurrency%2ccocodecurrency%2cfiscalyear%2creferencedocumenttype%2cintercompanytransaction% 2creversalfunction%2ccopilotkey
People may feel a bit messy, many special characters such as:%20,%27, and so on, this is the escape character.
In web development, you pass a question mark (? ) method is passed in the browser address bar. The browser is "&" to distinguish the number of arguments after the question mark. If there are special characters in the pass-through parameter, an error occurs when the page is accepted.
URLs appear with +, spaces,/,?,%,#,&,= and other special symbols, may not be able to get the correct parameter value on the server side, how is good?
Solutions
Convert these characters into characters that the server can recognize, and the corresponding relationships are as follows:
URL character escapes
Replace it with other characters, or use the full-width.
+ the + sign in the URL indicates a space%2b
Spaces in a space URL can be encoded with the + number or%20
/delimited directories and subdirectories%2f
? Separating the actual URLs and parameters%3f
% Specifies special characters%25
# indicates bookmark%23
& the delimiter between the parameters specified in the URL%26
= The value of the specified parameter in the URL%3d
OK, we analyze the URI information that the browser uploads to the front-end server, and we need to impersonate the OData service call on the front-end server (Gateway server).
Here we will focus on the SAP Gateway Client, which is a very important debugging test tool that we'll cover in detail in the future.
T-code:
/n/iwfnd/gw_client
Omitted because it is a local call: https://hostname:port/
/sap/opu/odata/sap/fac_financial_document_srv_01/$batch? sap-client=210
OData service:fac_financial_document_srv_01
Path:/sap/opu/odata/sap/
$batch batch, there will be more than one call.
sap-client-210, Parameters: Client 210
View the specifics of the OData service request in payload and convert the transferred characters to normal characters for ease of understanding.
%2C,%20-> space%27-> '
GET headers/$count?sap-client=210& $filter = ((companycode eq ' 0001 ') and (fiscalyear eq ' 2017 '))
Decomposition Uri, get is the HTTP Method, headers is EntitySet, $count represents the number of rows to take the structure set, $filter equivalent to the selection criteria, is the same as the Where condition in SQL.
Let's take a look at:
URI:/sap/opu/odata/sap/fac_financial_document_srv_01/headers/$count?sap-client=210& $filter = ((CompanyCode eq ' 0001 ') and (fiscalyear eq ' 2017 '))
HTTP Method:get
GET headers?sap-client=210& $skip =0& $top =116& $orderby =postingdate desc& $filter = ((Companycode eq ' 0001 ') and (FiscalYear eq ')) & $select =accountingdocument,accountingdocumentheadertext,companycodename, Accountingdocumenttype,createdbyuser,postingdate,amountincocodecrcy,companycode,accountingdocumenttypename, Createdbyusername,accountingdocumentcategoryname,ledgergroupname,parkedbyusername,reversalreasonname, Transactioncurrency,cocodecurrency,fiscalyear,referencedocumenttype,intercompanytransaction,reversalfunction, Copilotkey
Analyze the second uri,http Method GET, Entity set:headers,& $orderby =postingdate desc, query condition:& $filter = ((companycode eq ' 0001 ') ) and (fiscalyear eq ' 2017 ')).
Fields returned by $select
For the sake of simplicity, I removed some fields.
/sap/opu/odata/sap/fac_financial_document_srv_01/headers?sap-client=210& $skip =0& $top =116& $orderby = Postingdate desc& $filter = ((companycode eq ' 0001 ') and (FiscalYear eq ')) & $select =accountingdocument, Accountingdocumentheadertext,companycodename,accountingdocumenttype
If you need JSON format, add parameter: $format =json
/sap/opu/odata/sap/fac_financial_document_srv_01/headers?sap-client=210& $format =json& $skip =0& $top = 116& $orderby =postingdate desc& $filter = ((companycode eq ' 0001 ') and (FiscalYear eq ')) & $select = Accountingdocument,accountingdocumentheadertext,companycodename,accountingdocumenttype
We see that the Fiori app, through the UI5 (JavaScript class library), calls the rest type of OData service,xhr, which is actually an early Ajax technique that sends a gateway server URI request, and the gateway server returns an XML or JSON-formatted data.
How we analyze the Fiori app call OData service is to intercept XHR communication information, and then parse the URI in the SAP Gate client to impersonate the URI call. You can parse the error Message or debug the implementation code of the OData service.
OK, let's take a dip today and in a future article we'll delve into how to debug the OData service and other features of the SAP Gateway client.
The content of this article belongs to the personal opinion, does not represent any official.
10 minutes to play the OData Service in the Fiori app