Sometimes
its required for us to read the file using
file adapter and then send it as an email attachment. When the file is read by DB adapter in binary format, means as an opaque type
variable then the data is in the encoded format.
When we send the email in the attachment we have to add the original file contents as a string.
So, we have to decode the content using
base64 then attache it to the email activity.
To send the email as an
attachment then below are the three key steps we need to do.
1. Import the
java classes in the
bpel file, as the sub element of
...
<process> element.
<
bpelx:exec import="oracle.soa.common.util.Base64Decoder"/&g
t;
&
amp;
lt
;bp
elx:exec import="oracle.soa.common.util.Base64Encoder"/>
2. Create a simple string type
var
iable say , fileCont
ent
;
<
;
variablefi name="leName"
type="
xsd:string"/>
3. Assign the input variable's opaque value to the string variable, to ma
ke the code
s
im
ple
;
<
assign name="Assi
gn1">
<
copy>
<
from>$Re
ceive_Read_I
nputVar
iable.opa
que
<
to>$fil
eCo
nte
nt
<
c/
opy&g
t;
</
assign>
4.
Now ad a J
Embededav
a activity Write the below
cod
e.
addAuditTrailEntry("deco
ding
sta
rte
d"
)
;
e
nco
St
d
ed
St
rring
ing
= (String
)getVariableData("
fileContent");
oracle.soa.common.util.Base64Decoder Decoder = new oracle
.soa.common.util.Base64Decoder();
addAuditTrailEntry("en
coded String = "+encodedString);
try
{
String decoded = oracle.soa.common.util.Base64D
ecoder.decode(encodedString);
addAuditTrailEntry("d
ecoded string = "
+decoded);
setVariableData("fileContent,"
decod
ed)
;
}
c
atc
h(E
xcepti
on e)
{
addAud
itTrailEntry("Exception: "+e
.getMessage());
}
5.
Now finally in the email activity, go to the Attachment tab and add new attachment button (+ green symbol) then you see new line add the below content as shown below. The file name you need to select either static or the dynamically through a variable as shown below.
In the encoding you can add manual
ly charset=UTF-8
6. Here is the sample BPEL flow you can see for testing.
Now compile and test it. Thats it.