Showing posts with label osb11g. Show all posts
Showing posts with label osb11g. Show all posts

Monday, September 16, 2019

Send MIME emails (HTML Email body + Attachments) from OSB using UMS Adapter

Hi Guys,

Here I am trying to explain how to send MIME (Multipurpose Internet Mail Extensions) emails from Oracle Service Bus 12c using UMS adapter having HTML email body Content and one or more Attachments.


I am assuming you are able to send simple emails from OSB, this requires some configurations. There are many blogs available on this topic. You can refer below blogs if Needed for basic setup:

1.  https://blog.sysco.no/osb/messaging/UMS_Adapter_send_email_OSB_12C/

2.  http://blog.sysco.no/osb/messaging/UMS_Adapter_send_html_content_email_OSB_12C/



The main purpose of this blog is to highlight usage of MIME or multipart/mixed emails which can have email body with attachments.
A Sample emails like below:



STEPS to Achieve this in OSB:

This assumes, you have a working OSB project which is able to send emails. (You can Refer above blogs for this purpose)

Assuming you have transformed the message required for your scenario, which is available in below format before request reaches the Routing node in OSB Pipeline.

<tns:EmailPayload xmlns:tns="http://www.dheerajOSB.com">
<tns:To/>
<tns:Subject>POC| POC| NOTIFICATION | 2019-09-14T06:14:35.266-04:00</tns:Subject>
<MailBody>
<html>
<body>
<table border="1" bordercolor="grey">
<tr>
<td colspan="2" style="background-color:#33339F;color:white">
<Center>
<b>NOTIFICATION DETAILS</b>
</Center>
</td>
</tr>
<tr>
<td style="background-color:#33339F;color:white">INTERFACE NAME</td>
<td/>
</tr>
<tr>
<td style="background-color:#33339F;color:white">ERROR DESCRIPTION</td>
<td>This is custom fault</td>
</tr>
</table>
</body>
</html>
</MailBody>
</tns:EmailPayload>



1. Below actions are required in OSB pipeline to achieve this. There may be other actions in your pipeline as well for purpose of audit/logging/invocations etc.





Transport Header Action:



Java Callout Action:





fn:concat('--MIME_Boundary 
Content-type: text/html; charset="utf-8" 

',fn-bea:serialize($varUMSPayload//*:MailBody/*),'
--MIME_Boundary 
Content-type: text/html; charset="utf-8" 
Content-Disposition: attachment; filename=payload.txt;

',fn-bea:serialize($body//*:XMLPayload),'
--MIME_Boundary-- 


' )



Replace Action:





<ref:message xmlns:opaq="http://xmlns.oracle.com/pcbpel/adapter/opaque/" 
xmlns:ref="http://platform.integration.oracle/blocks/adapter/fw/metadata/ref_UMS_Notification">
    <opaq:opaqueElement>{$varBase64}</opaq:opaqueElement>

   </ref:message>





Business Service tracing Logs for debugging:

[2019-09-16T06:44:18.466-04:00] [osb_server1] [NOTIFICATION] [OSB-398202] [oracle.osb.resources.service.service] [tid: [ACTIVE].ExecuteThread: '9' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: <anonymous>] [ecid: 76bae70b-d533-4893-adda-a0d78240273b-0005e2b6,1:40787] [APP: Service Bus Routing] [FlowId: 0000Motf5J0Fw025zrH7iW1TU^G70004HD] [[
 [OSB Tracing] Outbound request was sent.

 Service Ref = DheerajOSB/BusinessServices/ref_UMS_Notification
 URI = jca://eis/ums/UMSAdapterOutbound
 Request metadata =
    <xml-fragment>
      <tran:headers xsi:type="jca:JCARequestHeadersXML" xmlns:jca="http://www.bea.com/wli/sb/transports/jca" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <jca:SOAPAction>"SendNotification"</jca:SOAPAction>
        <jca:Content-Type>text/xml; charset=utf-8</jca:Content-Type>
        <jca:jca.ums.to>dheexxxxxxhra@gmail.com</jca:jca.ums.to>
        <jca:jca.ums.subject>POC | OSBSample2 | NOTIFICATION | 2019-09-16T06:44:18.236-04:00</jca:jca.ums.subject>
        <jca:jca.ums.msg.content-type>multipart/mixed;boundary="MIME_Boundary"</jca:jca.ums.msg.content-type>
        <jca:jca.ums.msg.content-transfer-encoding>7bit</jca:jca.ums.msg.content-transfer-encoding>
        <jca:jca.ums.part.content-transfer-encoding>7bit</jca:jca.ums.part.content-transfer-encoding>
      </tran:headers>
      <tran:encoding xmlns:tran="http://www.bea.com/wli/sb/transports">utf-8</tran:encoding>
    </xml-fragment>
 Payload =
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ref:message xmlns:opaq="http://xmlns.oracle.com/pcbpel/adapter/opaque/" xmlns:ref="http://platform.integration.oracle/blocks/adapter/fw/metadata/ref_UMS_Notification"><opaq:opaqueElement>LS1NSU1FX0JvdW5kYXJ5IApDb250ZW50LXR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0idXRmLTgi+Ci0tTUlNRV9Cb3VuZGFyeS0tIAoKCg==</opaq:opaqueElement></ref:message></soapenv:Body></soapenv:Envelope>

]]
[2019-09-16T06:44:18.506-04:00] [osb_server1] [NOTIFICATION] [OSB-398203] [oracle.osb.resources.service.service] [tid: [ACTIVE].ExecuteThread: '21' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: <anonymous>] [ecid: 76bae70b-d533-4893-adda-a0d78240273b-0005e2b6,1:40787:14] [APP: Service Bus JCA Transport Provider] [FlowId: 0000Motf5J0Fw025zrH7iW1TU^G70004HD] [[
 [OSB Tracing] Outbound response was received.

 Service Ref = DheerajOSB/BusinessServices/ref_UMS_Notification
 URI = jca://eis/ums/UMSAdapterOutbound
 Message ID = a008016.2736342f.5.16d25a4109a.N7a1b
 Response metadata =
 <xml-fragment>
   <tran:headers xsi:type="jca:JCAResponseHeadersXML" xmlns:jca="http://www.bea.com/wli/sb/transports/jca" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
   <tran:response-code xmlns:tran="http://www.bea.com/wli/sb/transports">0</tran:response-code>
 </xml-fragment>
 Payload =



]]