Wednesday, 28 September 2011

Convert a BPEL Process from asynchronous to a synchronous and synchronous to asynchronous in 11g

This article shows how to convert BPEL process from an asynchronous to a synchronous and synchronous to asynchronous in 11g. Whether a process is asynchronous or synchronous by just some small settings in composite.xml, componentType, .bpel and wsdl files is very easy to convert from one to another. To get the Asynchronous have to add additional code base to synchronous process and to get the Synchronous have to delete the required code base to synchronous process. Bothe are in vies versa.
When creating BPEL processes, by default we have to modify below four files:
1.      composite.xml
2.      .bpel
3.      .wsdl
4.      .componentType
Composite.xml:
Have to the delete the red marked code base in the service tag in Asynchronous composite.xml file achieve the Synchronous.
Have to add the red marked code base in the service tag in Synchronous composite.xml file to achieve the Asynchronous.
Async composit.xml
 <service name="syncbpelprocess_client_ep"   ui:wsdlLocation="SyncBPELProcess.wsdl">
    <interface.wsdl  interface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcess)"
                    callbackInterface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcessCallback)" />
    <binding.ws port="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.endpoint(syncbpelprocess_client_ep/SyncBPELProcess_pt)"/>
    <callback>
      <binding.ws port="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.endpoint(syncbpelprocess_client_ep/SyncBPELProcessCallback_pt)"/>
    </callback>
  </service>


replace  oneWayDeliveryPolicy with transaction and async.persist with required in the below property.

<property name="bpel.config.oneWayDeliveryPolicy" type="xs:string"
              many="false">async.persist</property>
After remove the asynchronous related code base form the composite.xml file the modified file will be like below (Sync composite.xml)
Sync composite.xml
  <service name="syncbpelprocess_client_ep"   ui:wsdlLocation="SyncBPELProcess.wsdl">
 <interface.wsdl interface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcess)"/>
 <binding.ws port="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.endpoint(syncbpelprocess_client_ep/SyncBPELProcess_pt)"/>
  </service>

<property name="bpel.config.transaction" type="xs:string"
              many="false">required</property>
.wsdl file:
Add the ProcessResponseMessage tag in Process port Type and delete the process call back port type. The deleted code base would be the blow red mark and added tag is in the bold.
Delete the ProcessResponseMessage tag in Process port Type and add the process call back port type. The added code base would be the blow red mark and the code base in the bold should be removed.

   <wsdl:portType name="BPELProcess1">
                   <wsdl:operation name="process">
                                   <wsdl:input  message="client:BPELProcess1RequestMessage" />
                                   <wsdl:output message="client:BPELProcess1ResponseMessage"/>
                   </wsdl:operation>
   </wsdl:portType>
   <wsdl:portType name="SyncBPELProcessCallback">
                   <wsdl:operation name="processResponse">
                                   <wsdl:input message=" client:BPELProcess1ResponseMessage "/>
                   </wsdl:operation>
   </wsdl:portType>
Delete the below red marked requester role to achieve Synchronous from an Asynchronous.
Add the below red marked requester role to achieve Asynchronous from Synchronous.
   <plnk:partnerLinkType name="SyncBPELProcess">
                   <plnk:role name="SyncBPELProcessProvider">
                                   <plnk:portType name="client:SyncBPELProcess"/>
                   </plnk:role>
   <plnk:role name="SyncBPELProcessRequester">
                                   <plnk:portType name="client:SyncBPELProcessCallback"/>
                   </plnk:role>
   </plnk:partnerLinkType> 
.bpel file:     Have to delete partner role at partner link in the .bpel file to achieveSynchronous.
 <partnerLinks>
        <partnerLink name="syncbpelprocess_client" partnerLinkType="client:SyncBPELProcess" myRole="SyncBPELProcessProvider" partnerRole="SyncBPELProcessRequester"/>
After delete the partner role partner link will be like below
                   <partnerLink name="syncbpelprocess_client" partnerLinkType="client:SyncBPELProcess" myRole="SyncBPELProcessProvider"/>
    </partnerLinks>
In the sequence replace invoke with reply, callbackClient with replyOutput, SyncBPELProcessCallback with SyncBPELProcessa, processResponse with process and replace the inputVariable with variable.
    <sequence name="main">     
        <invoke name="callbackClient" partnerLink="syncbpelprocess_client" portType="client:SyncBPELProcessCallback" operation="processResponse" inputVariable="outputVariable"/>
                   <reply name="replyOutput" partnerLink="syncbpelprocess_client" portType="client:SyncBPELProcess" operation="process" variable="outputVariable"/>
</sequence>
. componentType
Have to the delete the red marked code base in the service tag in “.componentType” file to get Synchronous.
Have to the add the red marked code base in the service tag in “.componentType” file to get Asynchronous.

<service name="syncbpelprocess_client_ep"   ui:wsdlLocation="SyncBPELProcess.wsdl">
    <interface.wsdl  interface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcess)"
                    callbackInterface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcessCallback)" />
</service>
After delete it will become a synchronous “.componentType” file.
<service name="syncbpelprocess_client_ep"   ui:wsdlLocation="SyncBPELProcess.wsdl">
    <interface.wsdl  interface="http://xmlns.oracle.com/training/Helloworld/SyncBPELProcess#wsdl.interface(SyncBPELProcess)"/>
</service>


After that open the BPEL window and refresh the client partner link and then compiled the process

Tuesday, 6 September 2011

MDS Deployment Scripts

In order to deploy a file to the MDS of any environment, you need to do the following :
  •  Edit Deploy.cmd, setting correct Middleware_Home, SOA_Home, ANT_HOME etc.
  • Go to build.properties and give the environment details : managed.server.host, managed.server.port, username, password, and mds.applications, which will be the folder inside MDS/seed/apps that will be recursively deployed on MDS.
  • If you want to undeploy the existing folder on MDS and then deploy the same(to clean up MDS folders), set the mds.undeploy parameter to true.
  • Run Deploy.cmd

Create MDSDeploymentScript folder. Create MDS and DeployMDS sub folders and copy below DJO_ONBASE_DEPLOY.sh file (for Linux environment), Deploy.cmd file (for windows environment) and build.properties file under MDSDeploymentScript folder.

DJO_ONBASE_DEPLOY.sh file (for Linux environment):
#! /bin/ksh
#
#- Property of DJ Orthopedic
#- All rights reserved.
#- File Name: DJO_ONBASE_DEPLOY.sh
#- Purpose    : Creates the required AQs Deploys the BPEL processes to target environment
#-
#- Usage: . DJO_ONBASE_DEPLOY.sh
#
#- =============================================================
#- Maintenance Log
#- =============================================================
#-
# ===============================================================
# Deployment of OnBase BPEL processes. Change the variables WLS_HOME and JAVA_HOME value w.r.t target environment’s SOA home directory
# ===============================================================
export WLS_HOME=/d01/oracle/products/11g/fmw
export ORACLE_SOA_HOME=${WLS_HOME}/Oracle_SOA1
export ANT_HOME=${WLS_HOME}/modules/org.apache.ant_1.7.1/
export JAVA_HOME=/d01/oracle/products/11g/fmw/jdk160_18
export PATH=${JAVA_HOME}/bin:${ANT_HOME}/bin:${PATH}

echo "MDS Deployment"
deployMDS(){
ant -buildfile DeployMDS/build.xml -propertyfile  DeployMDS/build.properties
         }
deploy(){
                              ant -propertyfile build.properties
 }
deployMDS
echo "MDS Deployment Done... "
deploy

Deploy.cmd file (for windows environment):

set WLS_HOME=C:\Oracle\Middleware (you have to mention your WLS_HOME here)
set ORACLE_SOA_HOME=%WLS_HOME%\Oracle_SOA1
set ANT_HOME=%WLS_HOME%\modules\org.apache.ant_1.7.1\
set JAVA_HOME=C:\Java\jdk1.6.0_26 (you have to mention your JAVA_HOME here)

set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%

echo "MDS Deployment"
ant  -buildfile DeployMDS/build.xml -propertyfile build.properties unDeployMDS
echo "MDS Deployment Done... "
build.properties file:

#server information
managed.server.host=localhost   (you have to mention your SERVER.HOST value here)
managed.server.port=8001 (you have to mention your SERVER.PORT value here)

# User and credentials for the servers
server.user=weblogic (you have to mention your SERVER_USER here)
server.password=welcome1 (you have to mention your SERVER_PASSWORD here)

#MDS DEPLOYMENT RELATED PROPERTIES
mds.repository=../MDS/seed/apps/
mds.applications=FaultPolicies (you have to mention your policy file, which you want to deploy in the MDS)
mds.overwrite=true
mds.forceDefault=true

#set this to true if you want to undeploy the MDS folder and then deploy. For simple deployment, keep it false.
mds.undeploy=false

Create lib directory, temp directory, adf-config-file.seed file and build.xml file under DeployMDS folder inside the MDSDeploymentScript folder.

Download and copy the ant-contrib-1.0b3.jar File in the MDSDeploymentScript\DeployMDS\lib directory. Which is available in the below link: http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip/download.

Copy the Common_mds.jar at MDSDeploymentScript\DeployMDS\temp\Common directory.
Copy the OnBase_mds.jar at MDSDeploymentScript\DeployMDS\temp\OnBase directory.



adf-config-file.seed file:

<?xml version="1.0" encoding="windows-1252" ?>
<adf-config xmlns="http://xmlns.oracle.com/adf/config"
            xmlns:sec="http://xmlns.oracle.com/adf/security/config">
  <!-- jdeveloper client side mds settings -->
  <adf-mds-config xmlns="http://xmlns.oracle.com/adf/mds/config">
    <mds-config xmlns="http://xmlns.oracle.com/mds/config">
      <persistence-config>
        <metadata-namespaces>
          <!-- shared namespace for soa artifacts, such as xsd / wsdl -->
          <namespace metadata-store-usage="mstore-usage_1" path="/soa/shared"/>
          <!-- customer namespace for sharing stuff -->
          <namespace metadata-store-usage="mstore-usage_1" path="/apps"/>
        </metadata-namespaces>
        <metadata-store-usages>
          <!-- default store, based on the current oracle.home sys env -->
          <metadata-store-usage id="mstore-usage_1">
            <metadata-store class-name="oracle.mds.persistence.stores.file.FileMetadataStore">
              <property value="MDS_LOC"
                        name="metadata-path"/>
              <property value="seed" name="partition-name"/>
            </metadata-store>
          </metadata-store-usage>
        </metadata-store-usages>
      </persistence-config>
    </mds-config>
  </adf-mds-config>
  <sec:adf-security-child xmlns="http://xmlns.oracle.com/adf/security/config">
    <CredentialStoreContext credentialStoreClass="oracle.adf.share.security.providers.jps.CSFCredentialStore"
                            credentialStoreLocation="../../src/META-INF/jps-config.xml"/>
  </sec:adf-security-child>
</adf-config>

build.xml file:

<?xml version="1.0" encoding="iso-8859-1"?>
<project name="DeployAll" default="deployMDS">
 <property name="mds.serverURL"
           value="http://${managed.server.host}:${managed.server.port}"/>
 <property name="tmp.output.dir" value="${basedir}/temp"/>
 <property environment="env"/>
 <property name="oracle.home" value="${env.ORACLE_SOA_HOME}"/>
 <property name="wl_home" value="${env.WLS_HOME}/wlserver_10.3"/>
 <path id="library.MDS.Contrib">
  <pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
 </path>
 <taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath refid="library.MDS.Contrib"/>
 </taskdef>
 <import file="${oracle.home}/bin/ant-sca-deploy.xml"/>
 <target name="unDeployMDS">
  <echo>undeploy MDS</echo>
  <foreach list="${mds.applications}" param="mds.application"
           target="undeployMDSApplication" inheritall="true"
           inheritrefs="false"/>
 </target>
 <target name="deployMDS">
  <echo>undeploy and/or deploy MDS</echo>
  <if>
   <equals arg1="${mds.undeploy}" arg2="true"/>
   <then>
    <foreach list="${mds.applications}" param="mds.application"
             target="undeployMDSApplication" inheritall="true"
             inheritrefs="false"/>
   </then>
  </if>
  <foreach list="${mds.applications}" param="mds.application"
           target="deployMDSApplication" inheritall="true" inheritrefs="false"/>
 </target>
 <target name="deployMDSApplication">
  <echo>deploy MDS application ${mds.application}</echo>
  <property name="mds.deploy.dir" value="${tmp.output.dir}/${mds.application}"/>
  <delete dir="${mds.deploy.dir}"/>
  <mkdir dir="${mds.deploy.dir}"/>
  <echo>create zip from file MDS store</echo>
  <zip destfile="${mds.deploy.dir}/${mds.application}_mds.jar" compress="false">
   <fileset dir="${mds.repository}" includes="${mds.application}/**"/>
  </zip>
  <echo>create zip with MDS jar</echo>
  <zip destfile="${mds.deploy.dir}/${mds.application}_mds.zip" compress="false">
   <fileset dir="${mds.deploy.dir}" includes="*.jar"/>
  </zip>
  <echo>deploy MDS app</echo>
  <antcall target="deploy" inheritall="false">
   <param name="wl_home" value="${wl_home}"/>
   <param name="oracle.home" value="${oracle.home}"/>
   <param name="serverURL" value="${mds.serverURL}"/>
   <param name="user" value="${server.user}"/>
   <param name="password" value="${server.password}"/>
   <param name="overwrite" value="${mds.overwrite}"/>
   <param name="forceDefault" value="${mds.forceDefault}"/>
   <param name="sarLocation"
          value="${mds.deploy.dir}/${mds.application}_mds.zip"/>
  </antcall>
 </target>
 <target name="undeployMDSApplication">
  <echo>undeploy MDS application ${mds.application}</echo>
  <antcall target="removeSharedData" inheritall="false">
   <param name="wl_home" value="${wl_home}"/>
   <param name="oracle.home" value="${oracle.home}"/>
   <param name="serverURL" value="${mds.serverURL}"/>
   <param name="user" value="${server.user}"/>
   <param name="password" value="${server.password}"/>
   <param name="folderName" value="${mds.application}"/>
  </antcall>
 </target>
</project>

Copy below the fault-bindings.xml and fault-policies.xml file at MDSDeploymentScript\MDS\seed\apps\FaultPolicies folder.

Fault-bindings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="2.0.1"
                     xmlns="http://schemas.oracle.com/bpel/faultpolicy"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

               <!--
            the faultpolicy mapping for the reference called
                CreditCardAuthorizationService, and PartnerSupplierService
        -->
               <reference faultPolicy="OrderBookingFaultPolicy">
                   <name>CreditCardAuthorizationService</name>
            <name>PartnerSupplierMediator</name>
               </reference>

</faultPolicyBindings>

Fault-policies.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy">

               <!-- Policy for the Orderbooking processor to allow recoverable faults to be handled manually -->
               <faultPolicy version="2.0.1" id="OrderBookingFaultPolicy"
                              xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:xs="http://www.w3.org/2001/XMLSchema"
                              xmlns="http://schemas.oracle.com/bpel/faultpolicy"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

                              <!-- This section describes fault conditions. Build more conditions with faultName, test and action -->
                              <Conditions>
                                             <!-- in case of a remote fault (e.g. disabled service) human intervention action is triggered -->
                                             <faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:remoteFault">
                                                            <condition>
                                                                           <action ref="ora-human-intervention"/>
                                                            </condition>
                                             </faultName>
                                             <faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:bindingFault">
                                                            <condition>
                                                                           <action ref="ora-rethrow-fault"/>
                                                            </condition>
                                             </faultName>
                              </Conditions>
                              <Actions>
                                             <!-- This action will attempt 8 retries at increasing intervals of 2, 4, 8, 16, 32, 64, 128, and 256 seconds. -->
                                             <Action id="ora-retry">
                                                            <retry>
                                                                           <retryCount>3</retryCount>
                                                                           <retryInterval>2</retryInterval>
                                                                           <retryFailureAction ref="ora-terminate"/>
                                                                           <exponentialBackoff/>
                                                            </retry>
                                             </Action>
                                             <!-- This is an action will cause a replay scope fault-->
                                             <Action id="ora-replay-scope">
                                                            <replayScope/>
                                             </Action>
                                             <!-- This is an action will bubble up the fault-->
                                             <Action id="ora-rethrow-fault">
                                                            <rethrowFault/>
                                             </Action>
                                             <!-- This is an action will mark the work item to be "pending recovery from console"-->
                                             <Action id="ora-human-intervention">
                                                            <humanIntervention/>
                                             </Action>
                                             <!-- This action will cause the instance to terminate-->
                                             <Action id="ora-terminate">
                                                            <abort/>
                                             </Action>
                              </Actions>
               </faultPolicy>

</faultPolicies>