Hi Guys,
Sometimes there are requirements where we receives request from consumer in opaque/binary format or we may have to interact with applications using binary format.To facilitate this requirement Java embedding activity is used in BPEL.I will be demonstrating how to convert string to binary format and vice verse.
For this use case I have already created a BPEL process that will receive string in string format.In the BPEL code I have added 2 java embedding activities one for encoding and one for decoding the data.
Firstly, I will encode the payload received in binary format using below code:
addAuditTrailEntry("Encoding started");
try {
oracle.xml.parser.v2.XMLElement input = (oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input");
java.lang.String input_str = input.getTextContent();
addAuditTrailEntry("Input String = "+input_str);
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
java.lang.String encoded = null;
encoded = encoder.encode(input_str);
addAuditTrailEntry("encoded string = "+encoded);
setVariableData("InputVar",encoded);
} catch (Exception e) {
addAuditTrailEntry("Exception: "+e.getMessage());
}
addAuditTrailEntry("Encoded ended");
Pass the input variable name in the input string and create one more variable of 64binary format that will store the encoded string.
Now, we will decode the string that we encoded in previous step using below code:
addAuditTrailEntry("decoding started");
String encodedString = (String)getVariableData("InputVar");
Base64Decoder Decoder = new Base64Decoder();
addAuditTrailEntry("encoded String = "+encodedString);
try
{
String decoded = Base64Decoder.decode(encodedString);
addAuditTrailEntry("decoded string = "+decoded);
setVariableData("decodedString",decoded);
}
catch(Exception e)
{
addAuditTrailEntry("Exception: "+e.getMessage());
}
Create one more variable of string type that will contain the decoded string.In this case we will pass the variable we created in previous step as input.Decoded string will be stored in variable we created for storing decoded string.
Now, we will test our composite to verify the changes we have made.String passed is encoded using 1st java embedding activity and decoded using second java embedding java activity.
Make sure you imported below mentioned classes in your BPEL source:
<bpelx:exec import="oracle.soa.common.util.Base64Encoder"/>
<bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
Otherwise your compilation will fail.
In this way you can achieve encoding and decoding functionality in BPEL.Hope this post is useful to you.
Happy Learning,
Cheers !!!
Sometimes there are requirements where we receives request from consumer in opaque/binary format or we may have to interact with applications using binary format.To facilitate this requirement Java embedding activity is used in BPEL.I will be demonstrating how to convert string to binary format and vice verse.
For this use case I have already created a BPEL process that will receive string in string format.In the BPEL code I have added 2 java embedding activities one for encoding and one for decoding the data.
Firstly, I will encode the payload received in binary format using below code:
addAuditTrailEntry("Encoding started");
try {
oracle.xml.parser.v2.XMLElement input = (oracle.xml.parser.v2.XMLElement) getVariableData("inputVariable","payload","/client:process/client:input");
java.lang.String input_str = input.getTextContent();
addAuditTrailEntry("Input String = "+input_str);
oracle.soa.common.util.Base64Encoder encoder = new oracle.soa.common.util.Base64Encoder();
java.lang.String encoded = null;
encoded = encoder.encode(input_str);
addAuditTrailEntry("encoded string = "+encoded);
setVariableData("InputVar",encoded);
} catch (Exception e) {
addAuditTrailEntry("Exception: "+e.getMessage());
}
addAuditTrailEntry("Encoded ended");
Pass the input variable name in the input string and create one more variable of 64binary format that will store the encoded string.
Now, we will decode the string that we encoded in previous step using below code:
addAuditTrailEntry("decoding started");
String encodedString = (String)getVariableData("InputVar");
Base64Decoder Decoder = new Base64Decoder();
addAuditTrailEntry("encoded String = "+encodedString);
try
{
String decoded = Base64Decoder.decode(encodedString);
addAuditTrailEntry("decoded string = "+decoded);
setVariableData("decodedString",decoded);
}
catch(Exception e)
{
addAuditTrailEntry("Exception: "+e.getMessage());
}
Create one more variable of string type that will contain the decoded string.In this case we will pass the variable we created in previous step as input.Decoded string will be stored in variable we created for storing decoded string.
Now, we will test our composite to verify the changes we have made.String passed is encoded using 1st java embedding activity and decoded using second java embedding java activity.
Make sure you imported below mentioned classes in your BPEL source:
<bpelx:exec import="oracle.soa.common.util.Base64Encoder"/>
<bpelx:exec import="oracle.soa.common.util.Base64Decoder"/>
Otherwise your compilation will fail.
In this way you can achieve encoding and decoding functionality in BPEL.Hope this post is useful to you.
Happy Learning,
Cheers !!!
No comments:
Post a Comment