Showing posts with label Code Snippets. Show all posts
Showing posts with label Code Snippets. Show all posts

Wednesday, September 22, 2010

Using Dynamic Endpoint for a non-AIA based Composite in SOA 11g

The use of dynamic endpoint approach for a non-AIA based Composite is more or less the same, as it would have to been done for an AIA Composite. The stress on AIA in the implementation of dynamic endpoint is because AIA has AIAConfigurations.properties file, where usually this type information is stored. This information can be changed, loaded and reference at runtime, and so making the endpoint dynamic. The non-existence of AIA does not limit one from implementing this.

One just needs to make sure, AIA is replaced by a suitable component. By this statement, I mean one needs to make sure a mechanism is available to change, load and reference the endpoint at runtime. Oracle Fusion Middleware offers a lot of option for one to replace AIA. You can do any one of the below and yet use the dynamic endpoint feature without AIA:
  • Store information in a file and use file adapter to read the file whenever required
  • Store information in a database table and use a DB adapter to fetch the information
  • Use BPEL Preference Properties to store the information (Preference Properties can be modified at runtime from EM Console)
  • Store the information in Domain Value Map (DVM) and use functions to read the information from DVM
In all the cases, the information can be modified on the fly and each have their own set of limitations. I  saw DVM as the simplest, straightforward, hassle-free and readymade approach towards dynamic endpoint.

I created a DVM to store the information: Name of the Composite and Endpoint URI for the Composite. Teh DVM can be created within the Composite or deployed to MDS directly and referred from MDS. As to, how to deploy the DVM to MDS and referring from MDS, read this post.

Implementing the Dynamic Endpoint:

Creating Variables in BPEL:

  1. Create two variables in the BPEL flow namely, TargetEndpointLocation (String) and EndpointReference (of Type EndpointReference from WS-Addressing)
  2. When creating  the variable EndpointReference, import the XSD ws_addressing.xsd and choose the element type EndpointReference to create the variable
  3. ws_addressing.xsd can be downloaded from here
  4. This way, one need not copy-paste any code, or insert any namespace in the BPEL Process and its corresponding WSDL 
  5. After creating the variables, open the .bpel in source  mode and look for the namespace http://schemas.xmlsoap.org/ws/2003/03/addressing. Change the namespace prefix to wsa so that the namespace looks like below:
     xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing"
Implementing the dynamic endpoint:

  1. Use the dvm:lookupValue function to look up the endpoint URI from the DVM. In the code snippet below, I have the DVM in MDS and I am looking up a DVM by name Endpoints to get the endpoint URI
  2. Assign the URI to /wsa:EndpointReference/wsa:Address
  3. Assign the /wsa:EndpointReference/wsa:Address to Partner link in the invoke that follows this logic
  4. Insert the below code snippet just before the invoke node from the source view of the .bpel

Code Snippet:

<scope name="Scope_GetDynamicEndpoint">
    <sequence>
        <assign name="Assign_targetEndpointLocation">
            <copy>
                <from expression="dvm:lookupValue('oramds:/apps/Samples/Endpoints.dvm','ServiceName','SampleFlow','EndPoint','')"/>
                <to variable="TargetEndpointLocation"/>
            </copy>
        </assign>
        <assign name="AssignPartnerlinkEndpointReference">
            <copy>
                <from>
                    <wsa:EndpointReference xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing">
                        <wsa:Address/>
                    </wsa:EndpointReference>
                </from>
                <to variable="EndpointReference" query="/wsa:EndpointReference"/>
            </copy>
            <copy>
                <from variable="TargetEndpointLocation"/>
                <to variable="EndpointReference"
                query="/wsa:EndpointReference/wsa:Address"/>
            </copy>
            <copy>
                <from variable="EndpointReference"/>
                <to partnerLink="SampleFlowTarget"/>
            </copy>
        </assign>
    </sequence>
</scope>

    inputVariable="Invoke_SampleFlowTarget_InputVariable"
    ......



Peace!

Cheers,
- AR

Monday, September 13, 2010

Function to find age in years in Oracle Business Rules

I was part of a discussion recently - can age be found within business rules or can bpel do the math and get it for business rules. Business rules is not less incompetent and it does offer capability to mathematical calculations or so called numerical manipulations.

I had a date captured in a tag of type String and sent to business rules. I had to find the age from the date received in input. I have written a function in business rules that can get this done. Essentially the date is converted from string to date and then a difference in dates, will get you the result as an integer.

Duration.years between(OracleDate.from string(arg_1.IP1),RL.date.get current())










Peace!

Cheers,
-AR

Thursday, July 22, 2010

Remove duplicates from an input XML using XSLT

It is often the case that an input XML may contain duplicate data. It might be necessary to filter the duplicate data using a unique identifier, also from the input and send only the non-repeating, unique data to the output. In these cases, this transformation can be used to filter the data in the input.
This can be better understood by mapping this case to a real time scenario. Let us assume an organization having employees who can work in more than one department. If the input is going to contain the list of employees based on the department, there will be some employees whose data can repeat, as they are part of more than one department. If we need to filter the result based on the employee id to get a set of non-repeating unique employees, this logic can be used.

The implementation of this logic has been done using the function “following::”. The transformation logic is as below:


<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
  <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
  <mapSources>
    <source type="XSD">
      <schema location="http://localhost:7778/Schemas/Sample.xsd"/>
      <rootElement name="SampleXML" namespace="http://xmlns.oracle.com/
SampleXML"/>
    </source>
  </mapSources>
  <mapTargets>
    <target type="XSD">
      <schema location="
http://localhost:7778/Schemas/Sample.xsd"/>
      <rootElement name="
SampleXML" namespace="http://xmlns.oracle.com/SampleXML"/>
    </target>
  </mapTargets>
  <!-- GENERATED BY ORACLE XSL MAPPER 10.1.3.4.0(build 080718.0645) AT [THU SEP 24 15:16:11 EEST 2009]. -->
?>
<xsl:stylesheet version="1.0"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes="xsl xsd bpws hwf">
    <xsl:template match="/">
        <EmployeeListSorted>
            <xsl:for-each select="/EmployeeList/Employee[not(EmpId=following::EmpId)]">
                <xsl:sort select="./EmpId" order="ascending"/>
                <Employee>
                    <xsl:copy-of select="./Name"/>
                    <xsl:copy-of select="./EmpId"/>
                </Employee>
            </xsl:for-each>
        </EmployeeListSorted>
    </xsl:template>   
</xsl:stylesheet>



The preceding-sibling grouping technique did not work as because your nodes are not siblings of each other and because it only works where the grouping key is the string-value of the node, not where it is some other function of the node (here, its name).

Peace !

Cheers,
- AR
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License