I'm using the cxf-java2ws-plugin to generate a WSDL file from JAX-WS annotated classes. For my data objects; I'm specifying the fact that an external schema file already exists (by adding an @XmlSchema annotation with a location attribute to the package-info.java file). When the WSDL file gets generated; the namespace for the imported schema is declared; but the schema file itself is never imported. This results in a malformed schema.
My plugin configuration is as follows:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>2.4.2</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>com.mycorp.hello.HelloWebService</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<outputFile>${basedir}/src/main/webapp/WEB-INF/wsdl/HelloWebService.wsdl</outputFile>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
Here is an example of the package-info.java file:
@javax.xml.bind.annotation.XmlSchema(location="http://localhost:16899/schema/model.xsd", namespace="urn:ws.mycorp.com:hello:model")
package com.mycorp.hello.model;
Here is the pre-existing schema file:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ws.mycorp.com:hello:model" xmlns:tns="urn:ws.mycorp.com:hello:model" elementFormDefault="qualified">
<complexType name="MessageObject">
<sequence>
<element name="message" nillable="true" type="string"></element>
</sequence>
</complexType>
</schema>
Here is the generated schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:ws.mycorp.com:hello:model" xmlns:tns="http://hello.mycorp.com/" elementFormDefault="unqualified" targetNamespace="http://hello.mycorp.com/" version="1.0">
<xs:import namespace="urn:ws.mycorp.com:hello:model"/>
<xs:element name="getHelloMessage" type="tns:getHelloMessage"/>
<xs:element name="getHelloMessageResponse" type="tns:getHelloMessageResponse"/>
<xs:complexType name="getHelloMessage">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getHelloMessageResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="ns1:messageObject"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Note how the "urn:ws.mycorp.com:hello:model" namespace is declared and imported but is lacking the actual schema location (http://localhost:16899/schema/model.xsd). As a result, the generated schema has an error since ns1:messageObject cannot be found.
Obviously, I could manually modify the generated schema; but this becomes a nuisance since I'd have to do it every time the code is modified... and in a real world scenario (I put togeth开发者_开发知识库er this simple test case to illustrate the problem), there might be more than 1 pre-existing schema file.
EDIT:After doing a bit more research on this, I believe the problem is that JAXB requires a catalog file:
http://jaxb.java.net/guide/Fixing_broken_references_in_schema.html
The catalog file would allow JAXB to resolve the existing namespace (urn:ws.mycorp.com:hello:model) to an actual location. Unfortunately, the java2ws cxf tool seems to lack options to customize the JAXB databinding process:
http://cxf.547215.n5.nabble.com/jira-Resolved-CXF-1693-Allow-custom-Jaxb-databinding-in-java2ws-just-like-in-wsdl2java-td4787407.html
And the documentation from jaxb that indicates how to pass the catalog file assumes jaxb is getting invoked directly(either via ant/maven or the command line CLI tool); which isn't the case with java2ws...
精彩评论