Below is the Java embedding code in BPEL which will compress the XML using GZIP and convert it into Bas64 format. Compression ratio will be around 85%.
try {
//Retrieve XML and Convert it to String
oracle.xml.parser.v2.XMLElement inputPayload = (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/inputXML");
oracle.xml.parser.v2.XMLDocument xmlPayload = inputPayload.getDocument();
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
xmlPayload.print(outputStream);
String inputstr = outputStream.toString();
//Compress the string using Gzip and Convert it to byte[]
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(inputstr.length());
java.util.zip.GZIPOutputStream gzip = new java.util.zip.GZIPOutputStream(bos);
gzip.write(inputstr.getBytes());
gzip.close();
byte[] compressed = bos.toByteArray();
bos.toByteArray();
bos.close();
//Convert the Gzip to Base64 Format
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
java.lang.String encodedString = null;
encodedString = encoder.encode(compressed);
//Assign it to Invoke variable
setVariableData("Invoke_TargetSystem_InputVariable", "Parameters", "/request/paylaod", encodedString);
} catch (Exception e) {
addAuditTrailEntry(e);
}
To learn how to decompress, please use below link.
How to decompress xml from base64|GZIP
try {
//Retrieve XML and Convert it to String
oracle.xml.parser.v2.XMLElement inputPayload = (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/inputXML");
oracle.xml.parser.v2.XMLDocument xmlPayload = inputPayload.getDocument();
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
xmlPayload.print(outputStream);
String inputstr = outputStream.toString();
//Compress the string using Gzip and Convert it to byte[]
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(inputstr.length());
java.util.zip.GZIPOutputStream gzip = new java.util.zip.GZIPOutputStream(bos);
gzip.write(inputstr.getBytes());
gzip.close();
byte[] compressed = bos.toByteArray();
bos.toByteArray();
bos.close();
//Convert the Gzip to Base64 Format
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
java.lang.String encodedString = null;
encodedString = encoder.encode(compressed);
//Assign it to Invoke variable
setVariableData("Invoke_TargetSystem_InputVariable", "Parameters", "/request/paylaod", encodedString);
} catch (Exception e) {
addAuditTrailEntry(e);
}
To learn how to decompress, please use below link.
How to decompress xml from base64|GZIP
No comments:
Post a Comment