Correlation based off a value in Request Body
I need some assistance with this issue. A teammate is trying to set up a responder correlation based off a value incoming from the request service. The issue is that this value is within the element and I need to set up correlation based on that specific value / id within.
The section of the request body contains that value:
<SearchRequest><EdgeLookUp><ANINo>XXXXX123</ANINo></EdgeLookUp></SearchRequest>
With XXXXX123 being the value I need to the correlation based on.
I have the following Javascript custom assertion applied to the responder:
function ANINo(input)
{
if(input.toString().contains("XXXXX123")){
return true;
}
else{
return false;
}
}
However, this does not work properly and does not accept the incoming request.
Is there anything I need to change my code in order to detect this value in that element, or would this more so involve XPath manipulation and request correlation?
Comments
-
Hi,
Have you considered using the Request Body correlation? Here is a link to the documentation for it
The body correlation has UI to help select and extract values from an XML payload so I would recommend using the body correlation if possible.
Is there a reason this cause would not be able to use the body correlation?
0 -
Hey William I posted a comment but edited it a bit but it appears to have been taken down here
0 -
Hi,
Yes, I saw a notification for the missing comment but it was gone before I could read it.
0 -
So I think what is going on is either a format issue with the request or with the Parasoft Forums.
The code contains HTML code for greater than and less than symbols: "> ;" and "< ;"
EDIT: I Have put a space after the "t" before the semicolon, because the forums auto-converts it to the actual symbol
The actual code snippet is:
<searchCriteria><SearchRequest><EdgeLookUp><ANINo>XXX123</ANINo></EdgeLookUp></SearchRequest></searchCriteria>
So the string I need to do correlation on is
<SearchRequest><EdgeLookUp><ANINo>XXX123</ANINo></EdgeLookUp></SearchRequest>
and on the value XXX123 within.
Virtualize autocorrects the code in tree view and I can do correlation on this value in Request Body Correlation, however, when the request is sent the service reads it as a string
<SearchRequest><EdgeLookUp><ANINo>XXX123</ANINo></EdgeLookUp></SearchRequest>
and does not correct it to feature the "> and <" characters. The developer who created this request also says it is too late to change the code and that the code is to remain in this format when sent by the request.So how should I go about setting up correlation based on the value XXX123 within this string?
0 -
idk why it changed the original code snippet but here it is
<searchCriteria> < ;SearchRequest> ;< ;EdgeLookUp> ;<ANINo> ;XXX123< ;/ANINo> ;< ;/EdgeLookUp> ;< ;/SearchRequest> ; </searchCriteria>
0 -
"<searchCriteria><SearchRequest><EdgeLookUp><ANINo>XXX123</ANINo></EdgeLookUp></SearchRequest></searchCriteria>"
Ah I found that through, the Code Format option for the comments, I can keep it in its original format without the forums page converting it to the characters
0 -
Hi,
Yes, it sounds like a custom correlation will be needed in that case. There should be a default script that gives an example and the documentation below may help.
I believe the issue with the script you initially provided is that the object being provided is a context and not the message input. I attached a text file that has the default script that shows how to access all the message parts from the context.
Documentation
https://docs.parasoft.com/display/VIRT9105/Message+Responder+OverviewHope this helps!
1 -
Hey William,
That does help regarding what I am looking for.
So would the code in this instance more so look like this:
import com.parasoft.api.CorrelationScriptingHookConstants def correlateOperation(context) { requestBodyStr = context.get(CorrelationScriptingHookConstants.MESSAGE_STR) // String return requestBodyStr.contains("XXX123") }
This way it checks if XXX123 is in the string and returns true if detected, or do I have an incorrect understanding of how to write the syntax of this code / script?
0 -
Hi,
Yes, that roughly looks about what I believe would be expected.
1 -
Hey William,
The code I posted,
`import com.parasoft.api.CorrelationScriptingHookConstantsdef correlateOperation(context) {
requestBodyStr = context.get(CorrelationScriptingHookConstants.MESSAGE_STR) // String return requestBodyStr.contains("XXX123")
}`
Works successfully. It now hits the correct responder if XXX123 is detected in the message body string.
I also noticed that the Groovy script in your text document is the same placeholder script for Groovy that is in every responder with the Options tab and the Custom option on the left, so I can reference it much easier in the future as well.
Thank you very much for your help!
0 -
Hi,
Yes that is the default value for the correlation Groovy script, glad to hear you were able to get it working!
0 -
I would still recommend using an XPath expression. You can do something like this:
parse-xml(/searchCriteria/text())/SearchRequest/EdgeLookUp/ANINo/text()="XXX123"
0