E9.2 REST API Output connector XML

alfredorz

alfredorz

Well Known Member
Hi friend,

I need to call to REST service with XML body and response. The request it's fine, y add xml to body and content-type and accept to header. But I don't know how I get the value of xml tag:
1677773417630.png

I've tried output as json message with response.messageEngine but doesn't work. I've tried with messageEngine only, with response:<messageEngine> but all bad.

How can I get messageEngine value? I could get with manipulateOutput directly or I'll need manipulate with grovy and xml function?

Thanks very much.

Best Regards,
Alfredo.
 
DaveWagoner

DaveWagoner

Well Known Member
So you have a xml (or HTML) "document" wrapped in a json "document".

You mapped the output of response json var to an output var from your Connector step, so now you have a simple string output that should just include the messageEngine xml. Use a groovy script in the following step to use XMLSlurper to parse that string, and finally output the value of messageEngine as an output from the subsequent Groovy call.

You could manipulate the output using Groovy in the connection step if you like as well. I prefer to keep my connection "simple" and do more intense processing in a more visible step.

Here's what that groovy might look like:
JavaScript:
import com.oracle.e1.common.OrchestrationAttributes;
import groovy.xml.*;

HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
  HashMap<String, Object> returnMap = new HashMap<String, Object>();
 
  String connectorResponse = (String)inputMap.get("connectorResponse");
  def xml = new XmlSlurper().parseText(connectorResponse);
  String messageEngine = xml.messageEngine.text()
 
  returnMap.put("messageEngine",messageEngine);

  return returnMap;
}
 
alfredorz

alfredorz

Well Known Member
So you have a xml (or HTML) "document" wrapped in a json "document".

You mapped the output of response json var to an output var from your Connector step, so now you have a simple string output that should just include the messageEngine xml. Use a groovy script in the following step to use XMLSlurper to parse that string, and finally output the value of messageEngine as an output from the subsequent Groovy call.

You could manipulate the output using Groovy in the connection step if you like as well. I prefer to keep my connection "simple" and do more intense processing in a more visible step.

Here's what that groovy might look like:
JavaScript:
import com.oracle.e1.common.OrchestrationAttributes;
import groovy.xml.*;

HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
  HashMap<String, Object> returnMap = new HashMap<String, Object>();
 
  String connectorResponse = (String)inputMap.get("connectorResponse");
  def xml = new XmlSlurper().parseText(connectorResponse);
  String messageEngine = xml.messageEngine.text()
 
  returnMap.put("messageEngine",messageEngine);

  return returnMap;
}
Thanks a lot Dave, it works fine!

1677846113272.png

You are the best! I'm beginner in orchestrator (I've done a lot of bssv before), you has a new follower!

Best regards,
Alfredo.
 
DaveWagoner

DaveWagoner

Well Known Member
You're very welcome! I see you didn't need to specify the messageEngine "address" because it's the top level container anyway. I have never used/seen the writeDebug stuff, it looks really useful!
 
Top