When writing a file using the FTP adapter with the message schema defined, for some reason the output would come out without a prefix in the root element, like so:
This would happen even with the XSL transformation declaring the prefix in the root element:
I'm not sure if it's a bug or the fact that we have our schema/transformation wrong, but a coworker and I just couldn't get it to work, so we opted for a workaround using Java embedding.
Solution:
We used the following code to add the prefix to the root element by transforming the XML into a string:
try{
oracle.xml.parser.v2.XMLElement responseFile = (oracle.xml.parser.v2.XMLElement)getVariableData("varResponseFile");
//setting prefix to root
oracle.xml.parser.v2.XMLNode firstChild = (oracle.xml.parser.v2.XMLNode)responseFile.getFirstChild();
responseFile.setPrefix(firstChild.getPrefix());
//getting xml document
oracle.xml.parser.v2.XMLDocument responseFileXML = (oracle.xml.parser.v2.XMLDocument)responseFile.getDocument();
//setting prologue
responseFileXML.setVersion("1.0");
responseFileXML.setEncoding("UTF-8");
//writing xml document
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
responseFileXML.print(outputStream );
String responseFileString = outputStream.toString();
//encode xml document
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
String stringEnconded = null;
stringEnconded = encoder.encode(responseFileString);
//setting xml encoded
setVariableData("encodedBody",stringEnconded);
} catch (Exception e) {
addAuditTrailEntry("Error encoding Response File: " + e.getMessage());
throw new RuntimeException(e);
}
We would of course change the FTP message schema to opaque instead. Applying this code would then write the XML file correctly:
If anyone knows how to do this without Java (or perhaps what we are doing wrong in the first place), please let us know in the comments!