E9.2 REST API Output connector XML

alfredorz

alfredorz

Reputable Poster
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.
 
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;
}
 
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.
 
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!
 
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:
View attachment 19551

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.
Hi Alfredo,
do your request XML Body has any variables in it, that are filled by input parameters of the connector?

I'm unable to do with the $esc{} place holders, because at runtime they are treated like JSON string. This forbids chars like '<' -.-

Greetz, Chrsitian
 
Hi Alfredo,
do your request XML Body has any variables in it, that are filled by input parameters of the connector?

I'm unable to do with the $esc{} place holders, because at runtime they are treated like JSON string. This forbids chars like '<' -.-

Greetz, Chrsitian
Hi Christian,

Yes, mi xml body request has input variables
1701181473227.png

But it's in a CDATA request (it's strange because it's a rest with xml body by the external system). Try it.

Regards.
 
Back
Top