Using Ant to inspect Connection Properties in WSDL Files that are generated by Oracle SOA Suite Adapters

0

 

Oracle SOA Suite comes with a collection of adapters that allow you to easily tap into a number of technologies from BPEL Processes or from ESB Services. Want to connect to a database, hook up to a queue or access your E-Business Suite: create an adapter for it with a WSDL interface from within JDeveloper by simply running a wizard.

Logical Connection Names

All adapters, whether these are used to connect to an FTP server or access an MQ-Series queue, use logical connection names or JNDI names that must be specified at design time. At runtime, the adapter framework uses these JNDI names for looking up the physical connection data from configuration files. This mechanism works well. It ensures that the software remains unchanged when dragging it through the various stages of the software development life-cycle process: from QA to SIT, to UAT and finally Production only the environment-specific configuration files have different data. Obviously, developers are required to stick to the naming conventions for the logical connection names.

Risky business

Unfortunately, for ‘convenience’ Oracle decided to place physical connection data in the generated WSDL files at design time. When the system is not able to obtain the connection details from the configuration files using the JNDI name, it will use the so called ManagedConnectionFactory or MCF properties from the WSDL instead. Risky business that may cause undesirable behavior: if there is a misconfiguration the service may connect to an instance that was specified at design time without you knowing that. I prefer a clear error on which a system administrator can act appropriately by fixing the connection details in the proper configuration file. Hence, as a rule, the MCF properties need to be removed from the generated WSDL files afterwards. For inspection of the connection properties in the WSDL files I created a simple Ant script. ....

Requirements

My initial requirement is simple: I want an overview of the connection data for all WSDL files in the project. Typically, these are listed in the WSDL files in the following format:

    &lt;!-- Your runtime connection is declared in<br />        J2EE_HOME/application-deployments/default/DbAdapter/oc4j-ra.xml<br />        These 'mcf' properties here are from your design time connection and <br />        save you from having to edit that file and restart the application server<br />        if eis/DB/HR is missing.<br />        These 'mcf' properties are safe to remove.<br />    --&gt;<br />    &lt;service name=&quot;ReadDptData&quot;&gt;<br />        &lt;port name=&quot;ReadDptData_pt&quot; binding=&quot;tns:ReadDptData_binding&quot;&gt;<br />            &lt;jca:address location=&quot;eis/DB/HR&quot;<br />                UIConnectionName=&quot;HR&quot;<br />                ManagedConnectionFactory=&quot;oracle.tip.adapter.db.DBManagedConnectionFactory&quot;<br />                mcf.DriverClassName=&quot;oracle.jdbc.OracleDriver&quot;<br />                mcf.PlatformClassName=&quot;oracle.toplink.platform.database.oracle.OraclePlatform&quot;<br />                mcf.ConnectionString=&quot;jdbc:oracle:thin:@//localhost:1521/XE&quot;<br />                mcf.UserName=&quot;hr&quot;<br />                mcf.Password=&quot;62C32F70E98297522AD97E15439FAC0E&quot;<br />            /&gt;<br />        &lt;/port&gt;<br />    &lt;/service&gt;<br /><br />

Now, I want to check the contents of the <jca:address> element for each file. In a project I am currently working on that literally means plowing through hundreds of files. Hence, I need a utility that automates that tedious task for me. Since we already use Ant extensively, e.g. for deploying BPEL Processes and ESB Services, the utility is implemented as an Ant build script.

Loop Constructs and XML Tasks in Ant

Out of the Apache box, Ant does not come with looping constructs. Luckily the Ant-Contrib project provides very useful extensions to Ant among which is a foreach task that allows looping over a set of files. Subsequently, for each file I want to display the contents of of the <jca:address> element. Applying a simple XPath expression should do the trick. That is possible using the yet another Ant extension, XMLTask. Putting it all together results in the following script:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;project name=&quot;QA&quot; default=&quot;list-connection-data-in-wsdl-files&quot; basedir=&quot;.&quot;&gt;<br />&lt;!--  QA Utilities for SOA components --&gt;<br />    &lt;property environment=&quot;env&quot;/&gt;<br />    &lt;property name=&quot;server-src&quot; value=&quot;${env.SOA_PROJECT_HOME}/work&quot;/&gt;<br /><br />    &lt;taskdef resource=&quot;net/sf/antcontrib/antcontrib.properties&quot;&gt;<br />      &lt;classpath&gt;<br />        &lt;pathelement location=&quot;${env.SOA_DA_HOME}/lib/ant-contrib-1.0b3.jar&quot;/&gt;<br />      &lt;/classpath&gt;<br />    &lt;/taskdef&gt;<br /><br />    &lt;taskdef name=&quot;xmltask&quot; classname=&quot;com.oopsconsultancy.xmltask.ant.XmlTask&quot;&gt;<br />      &lt;classpath&gt;<br />        &lt;pathelement location=&quot;${env.SOA_DA_HOME}/lib/xmltask-v1.15.1.jar&quot;/&gt;<br />      &lt;/classpath&gt;<br />    &lt;/taskdef&gt;<br /><br />    &lt;target name=&quot;list-connection-data-in-wsdl-files&quot;&gt;<br />      &lt;foreach target=&quot;list-connection-data-in-wsdl-file&quot;<br />               param=&quot;source-file&quot;<br />      &gt;<br />        &lt;path id=&quot;src.path&quot;&gt;<br />          &lt;fileset dir=&quot;${server-src}&quot;&gt;<br />            &lt;include name=&quot;**/*.wsdl&quot;/&gt;<br />          &lt;/fileset&gt;<br />        &lt;/path&gt;<br />      &lt;/foreach&gt;<br />    &lt;/target&gt;    <br /><br />    &lt;target name=&quot;list-connection-data-in-wsdl-file&quot;&gt;<br />      &lt;echo message=&quot;File name: ${source-file}&quot; /&gt;<br />      &lt;xmltask source=&quot;${source-file}&quot;&gt;<br />        &lt;copy path=&quot;descendant::*/:service/:port&quot; buffer=&quot;connect-data-buffer&quot;/&gt;<br />        &lt;print buffer=&quot;connect-data-buffer&quot;/&gt;<br />      &lt;/xmltask&gt;<br />    &lt;/target&gt;<br /><br />&lt;/project&gt;<br /><br />

When using XPath expressions in XMLTask Ant targets, like descendant::*/:service/:port in this case, the colon character is used by XMLTask to deal with local namespaces in the WSDL file. As far as I know, there is no way to pass on namespaces data to XMLTask (I confess that I did not spent a lot of time investigating). XPath expressions /:service/:port/:address and /:service/:port/jca:address do not return the required results.

Room for improvements

The script that is provided here suits my needs. But as always there is room for improvements. For one, when it does not find a <jca:address> element it reports that whereas in that case we could opt for not even mentioning the file. Furthermore, the script could be extended to automatically remove all but the location attribute from the <jca:address> element. For that purpose, XMLTask provides options for manipulation of XML documents.

Share.

About Author

Comments are closed.