Nothing special. just bits and pieces about my life, my career and my loves.

Monday, April 07, 2008

Weblogic JWSC and Maven

I decided to use Weblogic Java Web Services (JWS) instead of other web services stack like Axis2, Metro for web services implementation at Optus.

The reasons behind it are:
simpler deployment model comparing to Axis2 - AAR really sucks
Metro only supports Netbeans to generate the WS policy files

Weblogic 9.2/10 provides an ant task for you to generate the artifacts from the JWS file. However, unlike Metro, it doesn't support maven by default. In order to get around with it, I have to use the Antrun plug-in to invoke my ant build scripts.

Here is my ant script:

<?xml version="1.0" ?>
<project default="all">
<!-- Project Specific Settings, you need to change this section for different project -->
<property name="packageName" value="com/mycompany/ws/jws" />
<property name="contextPath" value="security" />
<property name="serviceName" value="SecurityService" />

<!-- it's a convention to put wsdl under the src/main/resources/wsdl -->
<property name="srcWsdlDir" value="src/main/resources/wsdls" />

<!-- Setting the CLASSPATH -->
<property environment="env" />
<echo>###############################################################</echo>
<echo>${env.WL_HOME}</echo>
<echo>${env.JAVA_HOME}</echo>
<echo>###############################################################</echo>
<echo>${dependencies}</echo>
<echo>###############################################################</echo>
<path id="project.class.path">
<path path="${dependencies}" />
<path path="${env.WL_HOME}/server/lib/weblogic.jar" />
</path>

<!-- define weblogic specific ant task -->
<taskdef name="wsdlc" classpathref="project.class.path" classname="weblogic.wsee.tools.anttasks.WsdlcTask" />
<taskdef name="jwsc" classpathref="project.class.path" classname="weblogic.wsee.tools.anttasks.JwscTask" />

<!-- create java (jws, interface and DTOs) sources from wsdl -->
<target name="wsdlc">
<wsdlc srcWsdl="src/main/resources/wsdls/${serviceName}.wsdl" destJwsDir="target/jws" destImplDir="target/impl" />

<!-- Execute again to get the source code -->
<wsdlc explode="true" srcWsdl="src/main/resources/wsdls/${serviceName}.wsdl" destJwsDir="target/jws" destImplDir="target/impl" />
<echo>generate-from-wsdl completed</echo>

<!-- copy generated files like DTOs-->
<copy todir="target/generated-sources" includeEmptyDirs="false">
<fileset dir="target/jws">
<!--<exclude core package>-->
<exclude name="**/core/**/*.java" />
<include name="**/*.java" />
</fileset>
</copy>

<!-- check jws file exists or not -->
<available file="src/main/java/${packageName}/Jws${serviceName}.java" property="jwsFile.exists" />
<antcall target="jws_check" />
<echo>finish copy</echo>
</target>

<!-- copy jws file to source if neccessary -->
<target name="jws_check" unless="jwsFile.exists">
<echo>copy jws file now as it doesn't exist</echo>
<copy todir="src/main/java/${packageName}" includeEmptyDirs="false" flatten="true">
<fileset dir="target/impl">
<include name="**/${serviceName}Impl.java" />
</fileset>
</copy>
<move file="src/main/java/${packageName}/${serviceName}Impl.java" tofile="src/main/java/${packageName}/Jws${serviceName}.java" />
</target>

<!-- create weblogic deployment desciptors from jws file -->
<target name="jwsc" if="jwsFile.exists">
<echo>build.xml is called</echo>

<jwsc debug="true" tempdir="target/temp" keepgenerated="yes" srcdir="src/main/java" classpathref="project.class.path" destdir="target">
<module explode="true" contextPath="${contextPath}">
<jws file="${packageName}/Jws${serviceName}.java" compiledWsdl="target/jws/${serviceName}_wsdl.jar">
<WLHttpTransport serviceUri="${serviceName}" portName="${serviceName}Port" />
</jws>

<!-- add the web service to our template web.xml -->
<descriptor file="src/main/resources/wlartifacts/web.xml" />
</module>
</jwsc>

<!-- insert our service name as the URL pattern of the JAMon filter-->
<replace file="target/jws/WEB-INF/web.xml" token="@FILTER_URL_PATTERN@" value="/${serviceName}"/>

<echo>jwsc completed</echo>
</target>

<!-- copy generated binary files to Maven, so that it will be archived in the WAR file -->
<target name="copy_files" if="jwsFile.exists">

<copy todir="src/main/webapp/WEB-INF" includeEmptyDirs="false" failonerror="false">
<fileset dir="target/jws/WEB-INF">
<exclude name="**/*.class" />
<exclude name="classes/*" />
</fileset>
</copy>
<!-- copy generated java sources again-->
<copy todir="target/generated-sources" includeEmptyDirs="false" failonerror="false">
<fileset dir="target/jws">
<exclude name="**/core/**/*.java" />
<include name="**/*.java" />
</fileset>
</copy>

<copy todir="src/main/webapp" includeEmptyDirs="false" failonerror="false">
<fileset dir="target/jws">
<include name="wsdls/**" />
</fileset>
</copy>
</target>

<!-- clean up generated files in WEB-INF -->
<target name="clean">
<echo>cleaning all generated files</echo>
<delete failonerror="false" includeemptydirs="true">
<fileset dir="src/main/webapp/WEB-INF" includes="**/*" />
</delete>
<delete failonerror="false" includeemptydirs="true">
<fileset dir="src/main/webapp">
<include name="wsdls/**" />
</fileset>
</delete>
</target>

<target name="all" depends="wsdlc,jwsc,copy_files" />

</project>

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home