I'm looking to build a proxy for one of our legacy products. I can largely drive most of our site with postman, but in one particular instance, I need to request a page that has a struts token, then submit that token with a subsequent page.
I've been able get configure apigee to hit the target page (html) to see the token in postman:
<snip>
<body id="page"> <div id="wrapper"> <div id="wrapperInner"> <div id="container"> <div id="content"> <input type="hidden" name="struts.token.name" value="6TDBCYPWXOXPC4TL06UQAO4YM7CYPMO7" /> <input type="hidden" name="6TDBCYPWXOXPC4TL06UQAO4YM7CYPMO7" value="EFTUN7KPDQA0846BTGZQ85GZZGX5Z8WC" /> <script> var struts2TokenName = "6TDBCYPWXOXPC4TL06UQAO4YM7CYPMO7"; var struts2Token = "EFTUN7KPDQA0846BTGZQ85GZZGX5Z8WC";
<snip>
Now my strategy is to extract the token with a javascript policy. This is my js code:
var strutsTokenNameRegex = /struts2TokenName\s=\s"(.*)"/; var strutsTokenName = strutsTokenNameRegex.exec(context.targetResponse.content); context.setVariable("strutsToken",strutsTokenName)
I know my code is running because if I set strutsTokenName to "blah" then the value is set on apigee.
I'm pretty sure that the variable "context.targetResponse.content" holds the response payload. Any suggestions would be appreciated.
Solved! Go to Solution.
After a bit of trial and error, and lots of googling, it looks like I use the wrong variable name for the response. Here is the updated code:
var strutsTokenNameRegex = /struts2TokenName\s=\s"(.*)"/; var strutsTokenName = strutsTokenNameRegex.exec(response.content); context.setVariable("strutsToken",strutsTokenName[1])
Two things:
After a bit of trial and error, and lots of googling, it looks like I use the wrong variable name for the response. Here is the updated code:
var strutsTokenNameRegex = /struts2TokenName\s=\s"(.*)"/; var strutsTokenName = strutsTokenNameRegex.exec(response.content); context.setVariable("strutsToken",strutsTokenName[1])
Two things: