JavaBlog.fr / Java.lu DEVELOPMENT,Java,Libray,Tools Java : Generation Of Proxies for CXF, AXIS web services via ANT Script (WSDLToJava)

Java : Generation Of Proxies for CXF, AXIS web services via ANT Script (WSDLToJava)

Hi,

Just a post concerning the generation of JAVA webservice client for CXF and AXIS web services via an ANT script.

More information on sites on proxies creation:
http://cxf.apache.org/docs/wsdl-to-java.html
http://axis.apache.org/axis/java/ant/axis-wsdl2java.html

  • First, download the CXF and AXIS SDK librairies:
    C:\SDK\axis2-1.7.7
    C:\SDK\cfx-3.0.3
    C:\SDK\jdk1.7.0_17
     
  • Create a specific folder for the generated proxies sources (for example, WSProxyGenerator\src_generated)
     
  • References all needed libairies (JAR) in your project (for example lib/*.jar)
     
  • Create a properties file for the ANT script build.properties:
    cxf.home=C\:/SDK/cfx-3.0.3
    axis.home=C\:/SDK/axis2-1.7.7
    

     

  • Create a ANT script file build.xml containing the ANT targets create_proxy depending of init_proxy, create_proxy_cxf and create_proxy_axis targets:
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="ProxiesGenerator" default="create_proxy" basedir=".">
    	<property file="build.properties" />
    
    	<target name="create_proxy" depends="init_proxy,create_proxy_cxf,create_proxy_axis" >
    	</target>
    	
    	<target name="init_proxy">
    		<fail unless="cxf.home" message="Apache CXF home (cxf.home) not set" />
    		<path id="cxf.classpath">
    			<fileset dir="${cxf.home}/lib">
    				<include name="*.jar" />
    			</fileset>
    		</path>
    
    		<fail unless="axis.home" message="Apache AXIS home (axis.home) not set" />
    
    		<path id="axis.classpath">
    			<fileset dir="${axis.home}/lib">
    				<include name="*.jar" />
    			</fileset>
    			<fileset dir="${basedir}/lib">
    				<include name="*.jar" />
    			</fileset>
    		</path>
    
    		<delete includeemptydirs="true">
    			<fileset dir="${basedir}/src_generated">
    				<include name="**/*.java" />
    			</fileset>
    		</delete>
    		<mkdir dir="${basedir}/src_generated" />
    	</target>
    
    	<target name="create_proxy_cxf">
    	</target>
    
    	<target name="create_proxy_axis">
    	</target>
    </project>
    

     

 

CXF proxy generation

  • Create a file containing the URLs of CXF web services wsdllist_cxf.txt:
    https://myserver1.java.lu/services/core/MyObjectService?wsdl
    https://myserver1.java.lu/services/core/MyObjectService2?wsdl
    

     

  • Create a file for the binding-name simple-binding.xjb
    <?xml version="1.0" encoding="UTF-8"?>
    <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    	jaxb:version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    	jaxb:extensionBindingPrefixes="xjc">
    	<jaxb:globalBindings>
    		<xjc:simple />
    		<xjc:serializable uid="1397139757393" />
    	</jaxb:globalBindings>
    </jaxb:bindings>
    

     

  • Create in the build.xml file the CXF target:
    	<target name="create_proxy_cxf">
    		<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
    			<arg value="-autoNameResolution" />
    			<arg value="-verbose" />
    			<arg value="-fe" />
    			<arg value="jaxws21" />
    			<arg value="-encoding" />
    			<arg value="Cp1252" />
    			<arg value="-d" />
    			<arg value="${basedir}/src_generated" />
    			<arg value="-b" />
    			<arg value="simple-binding.xjb" />
    			<arg value="-wsdlList" />
    			<arg value="wsdllist_cxf.txt" />
    			<classpath>
    				<path refid="cxf.classpath" />
    			</classpath>
    		</java>
    	</target>
    

     

 

AXIS proxy generation

  • Create in the build.xml file the CXF target:
    	<target name="create_proxy_axis">
    		<java classname="org.apache.axis.wsdl.WSDL2Java" fork="true">
    			<arg value="--verbose" />
    			<arg value="--Debug" />
    			<arg value="--output" />
    			<arg value="${basedir}/src_generated" />
    			<arg value="-u" />
    			<arg value="https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl" />
    			<classpath>
    				<path refid="axis.classpath" />
    			</classpath>
    		</java>
    	</target>
    

     

 

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="ProxiesGenerator" default="create_proxy" basedir=".">
	<property file="build.properties" />

	<target name="create_proxy" depends="init_proxy,create_proxy_cxf,create_proxy_axis" >
	</target>
	
	<target name="init_proxy">
		<fail unless="cxf.home" message="Apache CXF home (cxf.home) not set" />
		<path id="cxf.classpath">
			<fileset dir="${cxf.home}/lib">
				<include name="*.jar" />
			</fileset>
		</path>

		<fail unless="axis.home" message="Apache AXIS home (axis.home) not set" />

		<path id="axis.classpath">
			<fileset dir="${axis.home}/lib">
				<include name="*.jar" />
			</fileset>
			<fileset dir="${basedir}/lib">
				<include name="*.jar" />
			</fileset>
		</path>

		<delete includeemptydirs="true">
			<fileset dir="${basedir}/src_generated">
				<include name="**/*.java" />
			</fileset>
		</delete>
		<mkdir dir="${basedir}/src_generated" />
	</target>

	<target name="create_proxy_cxf">
		<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
			<arg value="-autoNameResolution" />
			<arg value="-verbose" />
			<arg value="-fe" />
			<arg value="jaxws21" />
			<arg value="-encoding" />
			<arg value="Cp1252" />
			<arg value="-d" />
			<arg value="${basedir}/src_generated" />
			<arg value="-b" />
			<arg value="simple-binding.xjb" />
			<arg value="-wsdlList" />
			<arg value="wsdllist_cxf.txt" />
			<classpath>
				<path refid="cxf.classpath" />
			</classpath>
		</java>
	</target>

	<target name="create_proxy_axis">
		<java classname="org.apache.axis.wsdl.WSDL2Java" fork="true">
			<arg value="--verbose" />
			<arg value="--Debug" />
			<arg value="--output" />
			<arg value="${basedir}/src_generated" />
			<arg value="-u" />
			<arg value="https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl" />
			<classpath>
				<path refid="axis.classpath" />
			</classpath>
		</java>
	</target>
</project>

 
Execute the ANT script build.xml, the proxies are generated in the src_generated folder:

Buildfile: C:\Workspaces\WSProxyGenerator\build.xml
init_proxy:
create_proxy_cxf:
      Loading FrontEnd jaxws21 ...
      Loading DataBinding jaxb ...
      wsdl2java -autoNameResolution -verbose -fe jaxws21 -encoding Cp1252 -d C:\Workspaces\WSProxyGenerator/src_generated -b simple-binding.xjb -wsdlList wsdllist_cxf.txt
      wsdl2java - Apache CXF 3.0.3
create_proxy_axis:
      Parsing XML file:  https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl
      Symbol Table
      -----------------------
      org.apache.axis.wsdl.symbolTable.DefinedType
...
      -----------------------
      Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebService.java
      Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceSoapBindingStub.java
      Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceService.java
      Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceServiceLocator.java
create_proxy:
BUILD SUCCESSFUL
Total time: 11 seconds

 

Best regards,

Huseyin

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post