Thank you very much. Will try this. However you included external.xml directly. Per my previous comment, there can be multiple external.xml in the name of tttContractNumber value from request. Dont we need to get xpath of that and check for its value .xml?","body@stringLength":"268","rawBody":"Hi Rao
Thank you very much. Will try this. However you included external.xml directly. Per my previous comment, there can be multiple external.xml in the name of tttContractNumber value from request. Dont we need to get xpath of that and check for its value .xml?","author":{"__ref":"User:user:68898"},"isEscalated":null,"postTime":"2017-03-27T10:10:00.645-07:00","solution":false,"customFields":[],"attachments":{"__typename":"AttachmentConnection","edges":[],"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"repliesCount":4},"Revision:revision:138778_1":{"__typename":"Revision","id":"revision:138778_1","lastEditTime":"2017-03-27T10:52:39.311-07:00"},"ForumReplyMessage:message:138772":{"__typename":"ForumReplyMessage","uid":138772,"id":"message:138772","entityType":"FORUM_REPLY","eventPath":"category:soapui-os-community/community:nwkab66374board:SoapUI_OS/message:137915/message:138772","revisionNum":1,"author":{"__ref":"User:user:68898"},"readOnly":false},"ModerationData:moderation_data:138774":{"__typename":"ModerationData","id":"moderation_data:138774","status":"APPROVED","rejectReason":null},"AcceptedSolutionMessage:message:138774":{"__typename":"AcceptedSolutionMessage","author":{"__ref":"User:user:21201"},"id":"message:138774","entityType":"FORUM_REPLY","eventPath":"category:soapui-os-community/community:nwkab66374board:SoapUI_OS/message:137915/message:138774","revisionNum":4,"uid":138774,"depth":10,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:SoapUI_OS"},"parent":{"__ref":"ForumReplyMessage:message:138772"},"conversation":{"__ref":"Conversation:conversation:137915"},"subject":"Re: Need help in writing content of request (selected attributes) to external XML file.","moderationData":{"__ref":"ModerationData:moderation_data:138774"},"body":"
\n
Below is the Script for Mock Script Dispatcher.
\n\n
Hope you aware that you need to set response to ${content}
\n\n
NOTE: the script is not tried before providing, so please try and post if there are any errors.
\n\n
Response content is dynamically generated and set the response to content variable.
\n\n
//Provided the directory name where external file exists\ndef extFileDirectory = '/path/to/ext/file/directory'\n\n\n//Provide the absolute file path of soapfault file\ndef soapFaultPath = '/path/to/soapFault.xml'\n\n//NOTE: Donot edit beyond this point\n\ndef parsedXml = { fileName -> \n\tif (new File(fileName).exists()) {\n\t\treturn new XmlSlurper().parse(fileName) \n\t} else {\n \tlog.error \"${fileName} does not exists\"\n \t\tcontext.content = new File(soapFaultPath).text\n\t\treturn null\n\t}\n}\n\ndef requestXml = new XmlSlurper().parseText(mockRequest.requestContent)\n\n//Get the file name of external file\ndef extFileName = requestXml.'**'.find { it.name() == 'tttContractNumber'} as String\n\ndef extFileAbsPath = \"${extFileDirectory}/${extFileName}.xml\"\n\n//Provide the file path of external file\ndef externalXml = parsedXml(extFileAbsPath)\n\nif(externalXml) {\n\n\t//Closure to get the BillAccounts\n\tdef billAccounts = { data -> data.'**'.findAll { it.name() == 'BillAccount' } }\n\n\t//Closure to get the map of matching keys\n\tdef billDetailsMap = { data, key, value ->\n\t\tbillAccounts(data).inject([:]){map, account -> map[account.\"$key\".text()] = account.\"$value\".text(); map}\n\t}\n\n\t//Get the bill details map from request\n\tdef requestBillDetailsMap = billDetailsMap(requestXml, 'BillAccountNodeId', 'BillingAccountNumber')\n\n\t//check if the map has some details i.e., there are BillAccountNodeId's in the request\n\tif (0 < requestBillDetailsMap.size()) {\n\t \n\t\tdef requestBillDetailsMapForResponse = billDetailsMap(requestXml, 'BillAccountNodeId', 'BillAccountNodeType')\n\n\t\tdef exterBillAccounts = billAccounts(externalXml)\n\n\t\tdef isMatchingNodeIdFound = false\n\n\t\trequestBillDetailsMap.each { key, value ->\n\t\t\texterBillAccounts.each { account ->\n\t\t\t\tif (account?.BillAccountNodeId.text() == key) {\n\t\t\t\t\tisMatchingNodeIdFound = true\n\t\t\t\t\taccount.BillingAccountNumber = value\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(isMatchingNodeIdFound) {\n\t\t\tlog.info 'There are matching BillAccountNodeId between the request and external file, updating external file'\n\t\t\tlog.info \"Content of the external file is going to be : ${groovy.xml.XmlUtil.serialize(externalXml)}\"\n\t\t\tnew File(extFileAbsPath).write(groovy.xml.XmlUtil.serialize(externalXml))\n\t\t\tlog.info 'Building the response'\n\t\t\tdef builder = new groovy.xml.StreamingMarkupBuilder()\n\t\t\tbuilder.encoding = 'UTF-8'\n\t\t\tdef xml = builder.bind {\n\t\t\t mkp.xmlDeclaration()\n\t\t\t mkp.declareNamespace(env:'http://schemas.xmlsoap.org/soap/envelope/',\n\t\t\t \tch : 'http://cio.ttt.com/commonheader/v3',\n\t\t\t \tns : 'http://edb.ttt.com/dppco/billaccountinsertupdatemigr/v2')\n\t\t\t\t'env:Envelope' {\n\t\t\t\t\t'env:Header' { }\n\t\t\t\t\t'env:Body' {\n\t\t\t\t\t\t'ns:setBillAccountMigrResponse' {\n\t\t\t\t\t\t\t'ch:WSResponseHeader' { }\n\t\t\t\t\t\t\trequestBillDetailsMapForResponse.each { key, value ->\n\t\t\t\t\t\t\t\t'ns:BillAccount' {\n\t\t\t\t\t\t\t\t\t'ns:BillAccountNodeId' (key) \n\t\t\t\t\t\t\t\t\t'ns:BillAccountNodeType' (value)\n\t\t\t\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlog.info \"Response that is going to send: ${groovy.xml.XmlUtil.serialize(xml)}\"\n\t\t\tcontext.content = groovy.xml.XmlUtil.serialize(xml)\n\t\t} else {\n\t\t\tlog.info 'There are no matching BillAccountNodeId between the request and external file'\n\t\t\tcontext.content = new File(soapFaultPath).text\n\t\t}\n\t} else {\n\t log.error 'No BillAccountNodeId found in the request'\n\t context.content = new File(soapFaultPath).text\n\t}\n}\n
\n
","body@stripHtml({\"removeProcessingText\":true,\"removeSpoilerMarkup\":true,\"removeTocMarkup\":true,\"truncateLength\":200})@stringLength":"218","postTime":"2017-03-27T09:33:09.953-07:00","lastPublishTime":"2017-03-27T10:51:52.110-07:00","images":{"__typename":"AssociatedImageConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"attachments":{"__typename":"AttachmentConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[]},"solution":true,"metrics":{"__typename":"MessageMetrics","views":3747},"placeholder":false,"showMoveIndicator":false,"originalMessageForPlaceholder":null,"videos":{"__typename":"VideoConnection","edges":[],"totalCount":0,"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}},"isEscalated":null,"customFields":[]},"QueryVariables:ReplyList:message:138778:1":{"__typename":"QueryVariables","id":"ReplyList:message:138778:1","value":{"id":"message:138778","first":10,"sorts":{"kudosSumWeight":{"direction":"DESC","order":0},"postTime":{"direction":"ASC","order":1}},"repliesFirst":3,"repliesFirstDepthThree":1,"repliesSorts":{"kudosSumWeight":{"direction":"DESC","order":0},"postTime":{"direction":"ASC","order":1}},"useAvatar":true,"useAuthorLogin":true,"useAuthorRank":true,"useBody":true,"useKudosCount":true,"useTimeToRead":false,"useMedia":false,"useReadOnlyIcon":false,"useRepliesCount":true,"useSearchSnippet":false,"useAcceptedSolutionButton":true,"useSolvedBadge":false,"useAttachments":false,"attachmentsFirst":5,"useTags":false,"useNodeAncestors":false,"useUserHoverCard":false,"useNodeHoverCard":false,"useModerationStatus":true,"usePreviewSubjectModal":false,"useMessageStatus":true}},"CachedAsset:text:en_US-shared/client/components/users/UserAvatar-1749759144459":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/users/UserAvatar-1749759144459","value":{"altText":"{login}'s avatar","altTextGeneric":"User's avatar"},"localOverride":false},"CachedAsset:text:en_US-shared/client/components/ranks/UserRankLabel-1749759144459":{"__typename":"CachedAsset","id":"text:en_US-shared/client/components/ranks/UserRankLabel-1749759144459","value":{"altTitle":"Icon for {rankName} rank"},"localOverride":false},"CachedAsset:text:en_US-components/common/ExternalLinkWarningModal-1749759144459":{"__typename":"CachedAsset","id":"text:en_US-components/common/ExternalLinkWarningModal-1749759144459","value":{"title":"Leaving the Community","description":"You're about to leave this site and navigate to an external domain. Are you sure you want to continue?","action.submit":"Continue","action.cancel":"Go Back"},"localOverride":false},"CachedAsset:text:en_US-components/messages/AcceptedSolutionButton-1749759144459":{"__typename":"CachedAsset","id":"text:en_US-components/messages/AcceptedSolutionButton-1749759144459","value":{"accept":"Mark as Solution","accepted":"Marked as Solution","errorHeader":"Error!","errorAdd":"There was an error marking as solution.","errorRemove":"There was an error unmarking as solution.","solved":"Solved","topicAlreadySolvedErrorTitle":"Solution Already Exists","topicAlreadySolvedErrorDesc":"Refresh the browser to view the existing solution"},"localOverride":false},"CachedAsset:text:en_US-components/messages/ThreadedReplyList-1749759144459":{"__typename":"CachedAsset","id":"text:en_US-components/messages/ThreadedReplyList-1749759144459","value":{"title":"{count, plural, one{# Reply} other{# Replies}}","title@board:BLOG":"{count, plural, one{# Comment} other{# Comments}}","title@board:TKB":"{count, plural, one{# Comment} other{# Comments}}","title@board:IDEA":"{count, plural, one{# Comment} other{# Comments}}","title@board:OCCASION":"{count, plural, one{# Comment} other{# Comments}}","noRepliesTitle":"No Replies","noRepliesTitle@board:BLOG":"No Comments","noRepliesTitle@board:TKB":"No Comments","noRepliesTitle@board:IDEA":"No Comments","noRepliesTitle@board:OCCASION":"No Comments","noRepliesDescription":"Be the first to reply","noRepliesDescription@board:BLOG":"Be the first to comment","noRepliesDescription@board:TKB":"Be the first to comment","noRepliesDescription@board:IDEA":"Be the first to comment","noRepliesDescription@board:OCCASION":"Be the first to comment","messageReadOnlyAlert:BLOG":"Comments have been turned off for this post","messageReadOnlyAlert:TKB":"Comments have been turned off for this article","messageReadOnlyAlert:IDEA":"Comments have been turned off for this idea","messageReadOnlyAlert:FORUM":"Replies have been turned off for this discussion","messageReadOnlyAlert:OCCASION":"Comments have been turned off for this event"},"localOverride":false},"ModerationData:moderation_data:138781":{"__typename":"ModerationData","id":"moderation_data:138781","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"ForumReplyMessage:message:138781":{"__typename":"ForumReplyMessage","uid":138781,"id":"message:138781","entityType":"FORUM_REPLY","eventPath":"category:soapui-os-community/community:nwkab66374board:SoapUI_OS/message:137915/message:138781","revisionNum":1,"author":{"__ref":"User:user:68898"},"readOnly":false,"repliesCount":1,"depth":3,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:SoapUI_OS"},"parent":{"__ref":"ForumReplyMessage:message:138778"},"conversation":{"__ref":"Conversation:conversation:137915"},"subject":"Re: Need help in writing content of request (selected attributes) to external XML file.","moderationData":{"__ref":"ModerationData:moderation_data:138781"},"body":"
Hi Rao,
Its working absolutely great and as expected. Thank you very much.
","body@stripHtml({\"removeProcessingText\":false,\"removeSpoilerMarkup\":false,\"removeTocMarkup\":false,\"truncateLength\":200})@stringLength":"85","kudosSumWeight":0,"postTime":"2017-03-27T11:33:19.431-07:00","lastPublishTime":"2017-03-27T11:33:19.431-07:00","metrics":{"__typename":"MessageMetrics","views":2247},"visibilityScope":"PUBLIC","placeholder":false,"showMoveIndicator":false,"originalMessageForPlaceholder":null,"isEscalated":null,"solution":false,"replies":{"__typename":"MessageConnection","pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null},"edges":[{"__typename":"MessageEdge","cursor":"MjUuNHwyLjF8b3wzfDE0OjAsMzk6MXwx","node":{"__ref":"ForumReplyMessage:message:138790"}}]},"customFields":[],"attachments":{"__typename":"AttachmentConnection","edges":[],"pageInfo":{"__typename":"PageInfo","hasNextPage":false,"endCursor":null,"hasPreviousPage":false,"startCursor":null}}},"ModerationData:moderation_data:138790":{"__typename":"ModerationData","id":"moderation_data:138790","status":"APPROVED","rejectReason":null,"isReportedAbuse":false,"rejectUser":null,"rejectTime":null,"rejectActorType":null},"ForumReplyMessage:message:138790":{"__typename":"ForumReplyMessage","author":{"__ref":"User:user:21201"},"id":"message:138790","entityType":"FORUM_REPLY","eventPath":"category:soapui-os-community/community:nwkab66374board:SoapUI_OS/message:137915/message:138790","revisionNum":1,"uid":138790,"depth":4,"hasGivenKudo":false,"subscribed":false,"board":{"__ref":"Forum:board:SoapUI_OS"},"parent":{"__ref":"ForumReplyMessage:message:138781"},"conversation":{"__ref":"Conversation:conversation:137915"},"subject":"Re: Need help in writing content of request (selected attributes) to external XML file.","moderationData":{"__ref":"ModerationData:moderation_data:138790"},"body":"Apoorva6,