Thursday 20 May 2010

Replace endpoint URLs in SOA Composites before compilation

The configuration plan doesnot allow to change endpoint URLs in XSLT artifacts. We tried to hack the ant-sca-deploy and managed to use Ant tokens to replace endpoint URLs in all the files in the composite.
The ant-sca-package copies the composite to a tmp dir and then compiles it. In between this we use

<echo>About to find/replace the endpoint URLs in the Composite Package</echo>
<replace dir="${tmp.dir}" value="${server}:${port}">
<replacetoken>devServer:7001</replacetoken>
</replace>

Thus, the jar file created contains the endpoints of the target server which is now compiled and then deployed avoiding any issues with dependant partnerlinks and refernced schemas.

This is the snapshot of the ant-sca-package.xml file

<target depends="scac-validate" name="package">


<available property="compile.source" type="dir" file="${src.dir}">
<antcall target="compile-source">

<property name="tmp.dir" value="${compositeDir}/dist"></property>
<mkdir dir="${tmp.dir}">

<copy failonerror="false" todir="${tmp.dir}" includeemptydirs="false">
<fileset dir="${compositeDir}">
<exclude name="classes/**">
<exclude name="deploy/**">
<exclude name="dist/**">
<exclude name=".designer/**">
<exclude name="**/*.jpr">
<exclude name="**/*.ear">
<exclude name="**/*.zip">
<exclude name="**/*.war">
<exclude name="**/*.jws">
<exclude name="**/*.bin">
</fileset>
</copy>

<replaceregexp file="${tmp.dir}/composite.xml" replace="'revision=" match="revision=&quot;(.*)&quot;revision='(.*)'">

<copy failonerror="false" todir="${tmp.dir}/SCA-INF/classes">
<fileset dir="${compositeDir}/../.adf">
<include name="META-INF/**">
</fileset>
<fileset dir="${compositeDir}/../src">
<include name="META-INF/*">
</fileset>
</copy>

<echo>tmp.dir: ${tmp.dir}</echo>


<echo>About to find/replace the endpoint URLs in the Composite Package</echo>
<replace dir="${tmp.dir}" value="${server}:${port}">
<replacetoken>devServer:7001</replacetoken>
</replace>


<jar destfile="${deploy.composite.name}" basedir="${tmp.dir}">

<delete includeemptydirs="true" deleteonexit="true">
<fileset dir="${tmp.dir}" includes="*/**">
</delete>
<delete dir="${tmp.dir}">
</target>

<target name="compile-source" if="compile.source">
<echo message="deleting contents of ${sca-inf.classes.dir}">
<delete failonerror="false" includeemptydirs="true">
<fileset dir="${sca-inf.classes.dir}" includes="*/**">
</delete>
<mkdir dir="${sca-inf.classes.dir}">
<javac debug="true" destdir="${sca-inf.classes.dir}" classpathref="scac.tasks.class.path" srcdir="${src.dir}">
</javac>
</target>

No comments:

Post a Comment