I have an Ant task that takes a wsdl file and should auto generate POJO's (client side Java) , so I can start programming my client side JAX-WS web services.
However I'm getting an error "[ERROR] The package name .... used for this schema is not a valid package name"
This error only occurs when my wsdl file has more than 1 schema import in it such as
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
Below is the entire wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:CMSLINK="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" xmlns:REQ="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" xmlns:RESP="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry" name="ProcessCustomerInquiryService">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response" schemaLocation="ProcessCustomerInquiryResponse.xsd"/>
<xsd:import namespace="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request" schemaLocation="ProcessCustomerInquiryRequest.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ProcessCustomerInquiryRequest">
<wsdl:part name="requestData" element="REQ:ProcessCustomerInquiryRequest"/>
</wsdl:message>
<wsdl:message name="ProcessCustomerInquiryResponse">
<wsdl:part name="responseData" element="RESP:ProcessCustomerInquiryResponse"/>
</wsdl:message>
<wsdl:portType name="ESB_ProcessCustomerInquiryService">
<wsdl:operation name="ReqResp">
<wsdl:input name="processRequest" message="CMSLINK:ProcessCustomerInquiryRequest"/>
<wsdl:output name="processResponse" message="CMSLINK:ProcessCustomerInquiryResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProcessCustomerInquiryServiceSoapBinding" type="CMSLINK:ESB_ProcessCustomerInquiryService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ReqResp">
<wsdlsoap:operation soapAction="process"/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProcessCustomerInquiryService">
<wsdl:port name="ProcessCustomerInquiry" binding="CMSLINK:ProcessCustomerInquiryServiceSoapBinding">
<wsdlsoap:address location="http://tsesbd01.tms.toyota.com:51180/v2/MF_CMSLINK_ProcessCustomerInquiryDistributed.msgflow"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The XJC Ant task
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Response=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="http://service.rts.cmslink.tms.com/ProcessCustomerInquiry/Request=com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
If I remove the extra schema import either response.xsd or request.xsd, and also only include 1 "-p" package namespace argument for the ANT task, than the ANT runs without error, however my wsdl file contains multiple schema imports.
EDIT
I changed the value of "-p" arguement to adhere to package conventions, although my previous approach was based on JXC bug forum.
<project name="WSDLCompile" default="wsdl2java" basedir=".">
<target name="wsdl2java" description="Run xjc -wsdl.">
<!-- properties -->
<property name="sourceDir" value="temp/src" />
<echo message="sourceDir:"/>
<echo message="${sourceDir}"/>
<mkdir dir="temp/classes"/>
<property name="outputDir" value="temp/classes" />
<echo message="outputDir:"/>
<echo message="${outputDir}"/>
<!-- xjc properties -->
<property name="wsdl.url" value="src/wsdl/cmslink/ProcessCustomerInquiry.wsdl" />
<echo message="wsdl.url:"/>
<echo message="${wsdl.url}"/>
<property name="wsdl.mapping.package.response" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Response" />
<echo message="wsdl.mapping.package.response:"/>
<property name="wsdl.mapping.package.request" value="com.tms.cmslink.rts.service.ProcessCustomerInquiry.Request" />
<echo message="wsdl.mapping.package.request:"/>
<!--C:/Program Files/Java/jdk1.7.0_09/bin/xjc -->
<!--xjc execution-->
<exec executable="xjc">
<arg value="-wsdl" />
<arg value="${wsdl.url}" />
<arg value="-d" />
<arg value="${outputDir}" />
<arg value="-p"/>
<arg value="${wsdl.mapping.package.request}"/>
<arg value="-p"/>
<arg value="${wsdl.mapping.package.response}"/>
<arg value="-verbose"/>
</exec>
</target>
</project>
I have even tried the above ant task,with
-p <arg value="${wsdl.mapping.package.request }"/>
<arg value="${wsdl.mapping.package.response}"/>
by putting both package names on 1 line separated by space, this is according to JXC doc , explaining you can have "zero or more package namespaces separated by space". I require XJC to be able to handle more than 1 schema import.
The -p
option specifies a single Java package that should be used for all generated classes regardless of namespace. If you want each namespace URI to map to its own package then you can't use -p
, you instead need to use a binding customization file
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
<bindings schemaLocation="ProcessCustomerInquiryResponse.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.response"/>
</schemaBindings>
</bindings>
<bindings schemaLocation="ProcessCustomerInquiryRequest.xsd" node="/xs:schema">
<schemaBindings>
<package name="com.example.inquiry.request"/>
</schemaBindings>
</bindings>
</bindings>
and pass it to xjc
using the -b
option
<arg value="-b"/>
<arg file="bindings.xjb"/>