Technical Articles
PI REST Adapter – How to handle 415 Unsupported format, Special Chars, & HTTP Error messages from 3rd party
I am posting this blog post to share some of the challenges I have faced while integrating our SAP system with a REST-based 3rd party system via SAP PI 7.31 SPS 19 REST adapter.
Scenario:
SAP sends Sync HTTP (GET and POST) requests to the 3rd Party system (via SAP PI) and expects a response from 3rd party system.
Issue 1: HTTP 415 Unsupported Media Type exception
All HTTP-GET requests are working fine. HTTP-POST messages triggered from SAP are failing with HTTP 415 Unsupported Media Type exception.
Root Cause:
Logs from 3rd party application suggest POST request from SAP PI REST receiver adapter is failing at 3rd party as charset is getting appended to the Content-Type HTTP header parameter
i.e. Content-Type = application/json;charset=UTF-8
From the SAP PI point of view, Content-Type is defined as application/json in the REST receiver adapter configuration. Also, PI adapter logs show RESTOUT_HTTP_HEADER Content-Type as application/json.
Solution:
The issue got resolved after implementing SAP Note “2456232 – Cannot send HTTP Content-Type header without charset value”.
Issue 2: Special characters in the REST Request
REST requests with special chars like &,’, /, are failing.
e.g. M&S
MARSK & SPENCERS.
Solution:
Implemented 2215187 – Options for URL encoding of query strings with PI REST adapter
Set Module parameter EncodeURL to false.
Note: After implementing this fix all the messages with spaces are failing.
i.e. M&S is working fine, but MARKS & SPENCERS is failing.
This issue got resolved after replacing & with %26 and spaces with +.
i.e. MARKS+%26+Spencers.
Pls find below list with more special chars and code used
Special Character | Description | Code Used | Status |
£ | (pound sign) | %C2%A3 | Accepted |
} | Right brace | %7D | Accepted |
| | Vertical bar | %7C | Accepted |
{ | Left brace | %7B | Accepted |
\ | Backward Slash | %5C | Accepted |
‘ | (Apostrophe) | 27% | Accepted |
& | (ampersand) | 26% | Accepted |
“ | (Inverted Comma) | 22% | Accepted |
A-Z | (any standard letter) | Accepted | |
0-9 | (any standard numeric) | Accepted | |
@ | (at sign) | Accepted | |
$ | (dollar sign) | Accepted | |
# | (hash tag) | Accepted | |
. | (full stop) | Accepted | |
, | (comma) | Accepted | |
: | (colon) | Accepted | |
; | (semi-colon) | Accepted | |
– | (hyphen) | Accepted | |
( | Left parenthesis | Accepted | |
) | Right parenthesis | Accepted | |
/ | Forward Slash | Accepted | |
+ | Plus | Accepted | |
_ | Underscore | Accepted | |
= | Equals | Accepted | |
[ | Square Bracket Open | Not Accepted | |
] | Square Bracket Close | Not Accepted | |
! | Exclamation | Not Accepted | |
~ | Tilde | Not Accepted | |
` | Grave accent (backtick) | Not Accepted | |
< | Less Than | Not Accepted | |
> | Greater Than | Not Accepted | |
€ | (euro sign) | Not Accepted | |
¥ | (yen sign) | Not Accepted |
Issue 3: HTTP Error Responses from 3rd are not getting delivered to Source (i.e. SAP)
Non-200 HTTP (error) response messages from 3rd party like HTTP 415, 503, 500, 404, 403 are failing in SAP PI and not getting delivered to Source (i.e. SAP)
Solution:
Test the service via the postman. Get the 3rd party Error response structure and embed that in the PI response structure (DT).
In the Receiver Adapter configuration -> Error Handling
Source = HTTP Status Code
Select check box “Selection does NOT match”
Message Content = {http_result}
Conclusion: SAP has released many patches for REST adapter. Its recommended to check the patch levels before starting the development to avoid these issues.
Hi Phani,
I am having a similar issue with the "/" escape character. I am working on PO 7.5 version. will the above mentioned module works for it?
thanks
Smith
Hi PhaniKumar Akella,
Thank you for have shared this solution with us.
It has just helped me out with a similar issue!
Cheers,
Ulisses Filho