Skip to Content
0

Rest receiver adapter: How to do 'post' using x-www-form-urlencoded and key value in PI

Oct 18, 2017 at 09:00 AM

513

avatar image
Former Member

Dear All

I have Proxy - PI - Rest scenario where I am suppose to send the data in x-www-form-urlencoded format. When using postman i am able to receive response properly but if i use PI i am not able to understand how to accommodate key value in PI ESR and and setting required in receiver rest adapter for encoded as well.

Below is the postman result i got and the key value that i need to use in PI as well.

Kindly help !!

Regards

Neha

rest-query-sap.jpg (65.8 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

avatar image
Former Member Oct 18, 2017 at 01:52 PM
0

hi all

Any idea

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 12, 2017 at 12:22 PM
0

Hi,

You can use XSLT power for this. Like some OAuth 2.0 token services not accepting query string or payload JSON for values. Try this XSLT code with operational mapping (use dummy message type for result its not important)

x-www-form-urlencoded is usually means raw text. We can generate with XSLT or JAVA mapping.

MT_Token_Req -> Your input message type root
grant_type, username, password -> Your input message xml nodes. 

Change all for your message type.
Result should be like this: grant_type=xxxxxx&username=yyyyyy&password=zzzzzz
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" omit-xml-declaration="yes"/>
	
	<xsl:template match="*[local-name()='MT_Token_Req']">
		<xsl:for-each select="./*">


			<xsl:choose>
				<xsl:when test="name(.) = 'grant_type'">
					<xsl:text>grant_type=</xsl:text><xsl:value-of select="." />
				</xsl:when>
				<xsl:when test="name(.) = 'username'">
					<xsl:text disable-output-escaping="yes"><![CDATA[&]]></xsl:text><xsl:text>username=</xsl:text><xsl:value-of select="." />
				</xsl:when>
				<xsl:when test="name(.) = 'password'">
					<xsl:text disable-output-escaping="yes"><![CDATA[&]]></xsl:text><xsl:text>password=</xsl:text><xsl:value-of select="." />
				</xsl:when>
			</xsl:choose>


		</xsl:for-each>
	</xsl:template>


</xsl:stylesheet>
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you , this worked. I added a MessageTransformBean to change the content type to x-www-form-urlencoded in the rest channel too.

0
avatar image
Former Member Jan 29 at 09:16 AM
0

Hi Litza /Atakan,

Thanks Atakan, XSLT code is working fine when i used in HTTP_AAE adapter at receiver side in a synchronous scenario. But when i am using that code in rest receiver adapter then getting error XML /Json structure is not valid.

Could you suggest configuration of rest adapter at receiver side.

System - SAP PI 7.4 SP10.

Regards,

Pradeep Kumar

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 17 at 11:44 AM
0

Hi Pradeep,

Are you trying to parse querystring? Something like this? grant_type=xxxxxx&username=yyyyyy&password=zzzzzz

If i understood correctly; you can use XSLT or JAVA Mapping again. But this time JAVA Mapping will be more usefull. Try to parse with "error handling" on REST adapter; you can get an XML structure from there. After that you can parse querystring from XML Node with using UDF or JAVA Mapping.

Error handling mapping can be like that;

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_XXX_Res xmlns:ns0="http://xxx.com">
   <message>{http_status}</message>
   <type>{http_status_text}</type>
   <querystring>{http_result}</querystring>
</ns0:MT_XXX_Res>

Hope it will help.

Share
10 |10000 characters needed characters left characters exceeded