Solved! Go to Solution.
Alas, createNew will blank out previous request data. You would then have to manually copy the elements you want into the new request. The alternative is to for createNew=false with a previous step copying the essential elements you need later. Something along the lines of:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="true" enabled="true" name="assignSaveMessage"> <DisplayName>assignSaveMessage</DisplayName> <AssignVariable> <Name>save.request.content</Name> <Ref>request.content</Ref> </AssignVariable> <AssignVariable> <Name>save.request.verb</Name> <Ref>request.verb</Ref> </AssignVariable> <AssignVariable> <Name>save.request.queryparam.foo</Name> <Ref>request.queryparam.foo</Ref> </AssignVariable> [snip] <AssignVariable> <Name>storeIdAccessToken</Name> <Ref>access_token</Ref> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
You could then "restore" those values after you handle the callout. Like follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="true" enabled="true" name="assignRestoreMessage"> <DisplayName>assignRestoreMessage</DisplayName> <AssignVariable> <Name>request.verb</Name> <Ref>save.request.verb</Ref> </AssignVariable> <AssignVariable> <Name>request.queryparam.content</Name> <Ref>save.request.queryparam.content</Ref> </AssignVariable> <AssignVariable> <Name>request.queryparam.foo</Name> <Ref>save.request.queryparam.foo</Ref> </AssignVariable> [snip] <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
Can you clarify the question a bit with some examples? Is there something that isn't working as you expect?
Hi Carlos,
Yes I am facing an issue where I am not able to access custom variables created in proxy request flow.
Scenario: I am receiving a REST URL encoded request which I need to convert in XML to call first backend and if the response is not available from it, I need to call another backend which expects REST JSON message..
I have set first backend as target endpoint and it is response flow checking the status and accordingly want to call the 2nd backend in case of failure.
The problem is that I am passing custom variable as XML request to target endpoint unless and until I overwrite the original request message in request flow.
And when I did that, I lost my original request in response flow which I need to convert in REST JSON format.
I need pointers on how to retain the value of original request while retaining another XML request to be sent to 1st backend.
I think Prithpal's answer below may solve what you're trying to do. I would just use assignmessage to copy the request payload to a new variable, and use that new variable in the service callout for the exception case. If you can share your proxy or just paste in parts of the policies I'm certain we can get it sorted out.
Hi @Carlos Eberhardtarlos and @Prithpal Bhogill,
As per the attached image below of API proxy I have one assign message where I am assigning a transformed XML request to a variable,
...
<AssignTo type="request" createNew="true" transport="http">XML.request</AssignTo>
and then using this variable as input to XSL transform whose output is CacheRequest.
...
<Source>XML.request</Source> <ResourceURL>xsl://XSL-Transform-1.xsl</ResourceURL> <Parameters ignoreUnresolvedVariables="false"/> <OutputVariable>CacheRequest</OutputVariable>
and then assigning this CacheRequest as another request variable to go to backend server but it is going as blank . All variables created as createNew=true in AssignTo type are coming as blank value in trace session.
...
<Payload contentType="text/xml">{CacheRequest}</Payload> <Verb>POST</Verb> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo type="request" createNew="false" transport="http">Cache.Request</AssignTo> </AssignMessage>
If we overerite existing request variable with createnew=false, then it is working but I am loosing original request.
Please suggest how can we resolve this issue.
@Dharambir Singh just curious why you are using the "AssignTo" element for copying one variable to another. Have you considered doing the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1"> <DisplayName>Assign Message-1</DisplayName> <Properties/> <AssignVariable> <Name>newVariable</Name> <Ref>oldVariable</Ref> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage
Let me know if this solves what you are trying to do.
@Dharambir Singh I am a little confused. Are you assigning a new value to your original "request" variable? Typically the value of that variable should still be available unless you overwrite its value in the message flow somewhere. Are you able to upload your proxy here for us to look at it?
You can use an Assign Message policy to create new custom variables from existing ones. Please check out this example on various ways to use this policy.
Hi Prithpal,
Thanks for your inputs. I am able to resolve the access issue using assign variables of assign message policy.
Alas, createNew will blank out previous request data. You would then have to manually copy the elements you want into the new request. The alternative is to for createNew=false with a previous step copying the essential elements you need later. Something along the lines of:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="true" enabled="true" name="assignSaveMessage"> <DisplayName>assignSaveMessage</DisplayName> <AssignVariable> <Name>save.request.content</Name> <Ref>request.content</Ref> </AssignVariable> <AssignVariable> <Name>save.request.verb</Name> <Ref>request.verb</Ref> </AssignVariable> <AssignVariable> <Name>save.request.queryparam.foo</Name> <Ref>request.queryparam.foo</Ref> </AssignVariable> [snip] <AssignVariable> <Name>storeIdAccessToken</Name> <Ref>access_token</Ref> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
You could then "restore" those values after you handle the callout. Like follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="true" enabled="true" name="assignRestoreMessage"> <DisplayName>assignRestoreMessage</DisplayName> <AssignVariable> <Name>request.verb</Name> <Ref>save.request.verb</Ref> </AssignVariable> <AssignVariable> <Name>request.queryparam.content</Name> <Ref>save.request.queryparam.content</Ref> </AssignVariable> <AssignVariable> <Name>request.queryparam.foo</Name> <Ref>save.request.queryparam.foo</Ref> </AssignVariable> [snip] <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
Hi Dallen,
Thanks for the example above. I am able to resolve the issue with above and able to access request variables in response flow.
Are you validating solely based on trace? I ask because I notice you are using var.name in assignto sections. There used to, and may still be, a defect where variables of that style showed as blank in trace, yet the values were actually set correctly. Try just yanking the "." out of those var names and see if trace shows differently.
Hi Carlos,
Yes I was testing based on trace and it didn change much even after removing the .
As of now I am able to resolve it using assign variables of assign message.