Monday, 22 October 2012

Oracle BPEL Fault Policy Framework handling custom business faults

rom the Oracle forum and from the comments on my article about Oracle BPEL Fault Policy Management i get a lot of questions about how to let the framework handle my own custom defined ‘business faults’.
In certain situations the default set of faults defined by Oracle aren’t suited enough and you need to define your own faults.
If we look into the examples which got supplied by Oracle we can see an example over here. In this example they defined their own NegativeCredit-fault.
The Oracle BPEL Fault Policy Framework by default only handles the faults which are getting returned on an invoke-activity.
So we have our own custom fault and the knowledge we can only let this fault getting catched by the framework by use of an invoke.
So we need atleast for this testscenario 2 bpel processes. One mainprocess which calls a subprocess, and this subprocess will throw the custom business fault.
This fault will get propogated back to the mainprocess and in here we will be able to let the framework handle the fault.
bpel-invoke
BPEL Processes
Mainprocess
mainprocess
Subprocess
subprocess
Just a simple invoke of the subprocess from the mainprocess. The subprocess with throw a fault, and this fault will be catched in the mainprocess.
throwThe fault to be thrown
From the console start the mainprocess and wait till it comes back with a fault messageinvoke-faultedClick the activity to see the thrown fault
01.[2009/02/13 16:24:41]
02."{http://nl.iteye/integration/faults/business}BusinessFault" has been thrown.
03. 
05.<part name="payload">
07.<faultCode>999</faultCode>
08.<faultMessage>Something went wrong!</faultMessage>
09.</businessFault>
10.</part>
11.</businessFault>
Ok nice!
So the custom fault we defined in the subprocess reaches the mainprocess.
Now we need to config the fault policy framework so it will get active on our custom business fault.
From the fault we pasted above we need the faultname (BusinessFault) and the namespace (http://nl.iteye/integration/faults/business).
Edit /bpel/domains/default/config/fault-policies/DefaultPolicy.xml and add the next fault :
1.<faultName xmlns:flt="http://nl.iteye/integration/faults/business" name="flt:BusinessFault">
2.<condition>
3.<action ref="ora-human-intervention"/>
4.</condition>
5.</faultName>
For testing we will just let this fault getting handled by human-intervention.
Now restart the components
opmnctl stopall
opmnctl startall
Now start the mainprocess again and wait till it fails.
invoke-faulted-frameworkIt looks like the framework got active (activity yellow marked) on our custom business fault.
invoke-faulted-audit
Go to the activities-tab
list-activities
And click the activity which faulted.
edit-activity
Now we can edit some of the values and let the subprocess get re-invoked.
So, at this moment we’re able to throw our custom business faults and let them getting catched by the framework. Since the fault is only getting catched on the invoke of a partnerlink, we aren’t able to let our custom business fault getting throwned to the process in which we maybe want do something with the data for which we actually throwed the custom business fault. So maybe we want to stay in the subprocess and somehow get the custome business fault thrown inhere, let the framework catch it and update the values of this subprocess with new values an re-execute the subprocess.
The next solution will get this done.
The mainprocess won’t get changed but in the subprocess we will invoke a new process called AllBusinessFaults.
New subprocess 2
subprocess2
AllBusinessFaults
all-business-faults
The AllBusinessFaults will throw the custom business fault we ‘request’ back on the invoke in this subprocess. Now it wil get catched by the framework and we will be able to change the values of the subprocess instead of the mainprocess.
list-activities2
By using the AllBusinessFaults bpel service like a sort of composite service, we can add the custom business faults in it and throw the one we would like to get thrown. This will work if the collection of custom business faults isn’t that big. I’m sure there will be better solutions for this, but for the scenario i wanted to describe inhere it was good enough for me.
Question
In the examples i provided i don’t use the fault-part of a synchronous invoke to propegate the soap-fault back to the caller, i just throw the fault. The bpel engine itself throws the fault back to the first-level. Whats best practice on this one ?
Sources
BPEL Sources (First part of article with mainprocess/subprocess)
BPEL Sources (Second part of article with mainprocess/subprocess/allbusinessfaults)
Resources
Oracle BPEL 10.1.3.3 Fault Policy Management

Saturday, 14 January 2012

Email Notification

Sending email notification in Oracle SOA Suite 11g using gmail

Hi,
 In this post, we are going to see how to send emails in Oracle SOA Suite 11g. Instead of using a local email server, we are going to use Gmail for this purpose. If you do not have a Gmail account, now is the time to create one as you are going to need it very soon.


  I am using Oracle SOA suite 11.1.1.5.If you are using a slightly older version, don't worry because the steps are going to be same.So let us get started straight away.Start the weblogic server and the SOA server.Next login to the Enterprise Manger Console.For me, it is available at:


                                                            http://localhost:7001/em








Next, expand the "User Messaging Service" node in the left pane.Next right click on the "usermessagindriver-emai(soa_server1)" node and select the "Email Driver Properties" option from the context menu.






The email driver properties page should open up.We will be setting the following values in this page:-



  • OutgoingMailServer
  • OutGoingMailServerPort
  • OutGoingMailServerSecurity
  • OutGoingUsername
  • OutGoingPassword
We are going to use Gmail for sending mails.So, enter "smtp.gmail.com" as the value for "OutgoingMailServer".

Enter the value "465" for the "OutGoingMailServerPort" property.

Select the "SSL" option from the drop down for the property "OutGoingMailServerSecurity".

Enter the account username for the property "OutGoingUserName".

For the property "OutGoingPassword", select the "Use Cleartext Password" option from the "Type of Password" drop down and enter the password for the account.



Hit the "Apply" button on the top right corner of the page to apply the changes.A message will be displayed at the top of the page saying that the values has been updated successfully.



If you want to use any other popular mail provider, you can get the details from the following link:-


In this case, enter the values according to the vendor you choose.Next, restart the SOA server.

Our next step is to obtain and install the security certificates for Gmail into our JRE.For this, we are going to use "OpenSSL" to obtain the certificate.You can download "OpenSSL" from the following link:-

                        http://gnuwin32.sourceforge.net/packages/openssl.htm

Download and install "OpenSSL".The path I installed it in is "C:\openssl".From now on, this is referred to as OPENSSL_HOME. To launch "OpenSSL", go to OPENSSL_HOME\bin.Then double click on the file "openssl.exe" to launch it.A new command prompt will open with "OpenSSL" prompt.


 Make sure you are connected to the internet.Next, type in the following command hit enter in the "OpenSSL" console:-

              s_client -connect smtp.gmail.com:465

 The certificate will be output on the console itself. Copy the portion from the "BEGIN CERTIFICATE" to the "END CERTIFICATE' as indicated in the image below:-



 Open your favourite text editor, paste the copied string and save the file with the name "gmail.cert". You can use whatever name you want.Just make sure the extension of the file is ".cert".

  Next, back in the "OpenSSL" console, hit "CTRL+C". Then type in the following command and hit return:-

                 s_client -connect imap.gmail.com:993


Like before, copy the portion from the "BEGIN CERTIFICATE" to the "END CERTIFICATE".This time save it in a file named "gmail_imap.cert".

In the previous step, we got hold of the certificates.Next, we are going to install these certificate into our JRE.Open a new command prompt.Next, issue the following command and hit return.

keytool -import -alias smtpgmail -keystore my-trusted-certificates.jks -file C:\gmail.cert


Adjust the command according to the file location of the "gmail.cert". You will be prompted for setting up a password for the first time.Enter "changeit".The certificate will be added.

Similarly, issue the following command to add the "gmail_imap.cert" file to the key store.

keytool -import -alias imapgmail -keystore my-trusted-certificates.jks -file C:\gmail_imap.cert


After executing the commands, a new ".jks" file named "my-trusted-certificates.jks" will be create in the directory where you executed the commands from.


Now, go to SOA_HOME/user_projects/domains/domain1/bin(e.g. D:\Oracle\Middleware\user_projects\domains\domain1\bin).

Next ,edit the setDomainEnv.cmd file and replace the existing javax.net.ssl.trustStore property setting with :-

Djavax.net.ssl.trustStore=D:\Oracle\Middleware\jdk160_18\jre\bin\my-trusted-certificates.jks 

 and


 -Djavax.net.ssl.trustStorePassword=changeit

Adjust the location of the ".jks" file and the password according to your system.Restart the server once again.We are all set to go now.


Open JDeveloper if it is not already open.Next go to File->New.


In the "New Gallery", select the "Applications" node under the "General" node.In the right pane, select the "SOA Application" option and hit OK.


In the "Create SOA Application" window, enter a name for the application.To follow along, enter "GmailNotificationApp".Hit next once you are done.




In the next screen, enter a project name.To follow along, enter "GmailNotificationProject".Hit next once you are done.



In the next screen, select the "Composite With BPEL Process" option and hit finish.


Your project will be created.Next, the "Create BPEL Process" window will pop up.Enter a name for the BPEL process.To follow along, name "GmailNotifierProcess".Select the "One Way BPEL Process" template.Make sure you check the "Expose as a SOAP service" option.Hit OK once you are done.You can use the following image as a guide.

Your composite will look like the following image.



Double click on the BPEL process to open it.Next, drag and drop an email activity from the component palette and put it just below the receive activity.



Next, double click on the "email" activity.Under the "General" tab, enter the values.First, click on the expression builder button just beside "To" to bring up the expression builder.



In the expression builder, select the "input" variable under the "inputVariable" node and click on the "Insert Into Expression" button as indicated in the image below.Hit OK once you are done.



Back in the "Email" activity configuration screen, enter a value for the "Subject" and "Body".You can use expressions for these values also.Hit OK once you are done.Click on "Save All" to save the changes.



Our application is complete.You can deploy and test the application.Make sure you are connected to the internet.In the Enterprise Manager console, enter the email address where you want to send the email as the input and test the service.