Not able extract response header values from target endpoint

thamilbecse
Participant II

My variable policy configuration is as below: I could see from target response headers I am getting value for Tr-ui-Yui variable header.

It's value is {"test":"data","test1":"data1"}. But I could not see the variable at all in ExtractVariablePolicy used in TargetPreFlow (Response flow side).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariablesasync="false"continueOnError="false"enabled="true"name="Extract-Variables-1">
<Source>response</Source>
<DisplayName>Extract Variables-1</DisplayName>
<Headername="Tr-ui-Yui">
<PatternignoreCase="false">{myvalueNew}</Pattern>
</Header>
</ExtractVariables>
0 7 565
7 REPLIES 7

masood
Participant I

Try to extract the header in a javaScript instead:

var trUiYui = context.getVariable('response.header.Tr-ui-Yui');
print('trUiYui: ' + trUiYui);

// To further extract
var jsonBody = JSON.parse(trUiYui);
var test = jsonBody.test;
var test1 = jsonBody.test1;

No I am looking solution with the extract or assign message policy.

In that case you can use assign message policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Load-Header">
    <AssignVariable>
        <Name>trUiYui</Name>
        <Ref>response.header.Tr-ui-Yui</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
    <DisplayName>Load Header</DisplayName>
</AssignMessage>

try to print it in javaScript and check if you are able to get it. If not, I think I faced this issue once where it was not possible to assign JSON object to a variable.

Tried this as well. That too not working.Why cant we use extract variable policy. Is there any problem in that? Then why we need to print with javascript policy. when we enable trace it will show right?

Nothing wrong with extract variable policy. Yes you can see the response in trace, but I doubt if you can see what value has been assigned after using the policy. Try to print myvalueNew and check the output to be sure of extracted value

masood
Participant I

Did you try printing myvalueNew? What is your output?

You are "extracting" the entire value of the header to a different variable? Why?

What's the point?

The analogous action in a Javascript program is

var x = y;

OK, then what? Before the assignment, y had a value. After the assignment, x has that value. It doesn't get you anywhere. Anything you do with x afterwards, you could have done with y, without the assignment.

And the same is true if you use ExtractVariables to extract the entire variable. You're just assigning from one thing to another. Why not just reference "request.header.tru-ui-yui" ? Anything you can do with "mynewvalue" you could have done with "request.header.tru-ui-yui" before your ExtractVariables policy. So it's pointless.

What are you really trying to do?